Merge lp:~vaab/openobject-addons/project-has-wider-choices-for-set-priority-set-remaining-time into lp:openobject-addons

Proposed by Valentin Lab
Status: Needs review
Proposed branch: lp:~vaab/openobject-addons/project-has-wider-choices-for-set-priority-set-remaining-time
Merge into: lp:openobject-addons
Diff against target: 44 lines (+23/-2)
1 file modified
project/project.py (+23/-2)
To merge this branch: bzr merge lp:~vaab/openobject-addons/project-has-wider-choices-for-set-priority-set-remaining-time
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+96567@code.launchpad.net

Description of the change

Adds generic methods ``.set_remaining_time_NN`` and ``.set_priority_NN`` in ``project.task`` model in the spirit of the existing ``.set_remaining_time_1``, ``.set_remaining_time_2``, ...

This allows kanban view a much wider range of action if needed. This code is used and tested in a modified kanban view I'm using.

Note that this avoids also hard written presets and messy copy-pasted code in all the "set_remaining_time_1/2/5/10".

To post a comment you must log in.

Unmerged revisions

6663. By Valentin Lab

[NEW] wider choices for set_priority, and set_remaining_time available for view code (ie: kanban).

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'project/project.py'
2--- project/project.py 2012-02-28 14:08:16 +0000
3+++ project/project.py 2012-03-08 13:10:26 +0000
4@@ -681,10 +681,10 @@
5
6 _order = "priority, sequence, date_start, name, id"
7
8- def set_priority(self, cr, uid, ids, priority):
9+ def set_priority(self, cr, uid, ids, priority, context=None):
10 """Set task priority
11 """
12- return self.write(cr, uid, ids, {'priority' : priority})
13+ return self.write(cr, uid, ids, {'priority' : str(priority)})
14
15 def set_high_priority(self, cr, uid, ids, *args):
16 """Set task priority to high
17@@ -696,6 +696,27 @@
18 """
19 return self.set_priority(cr, uid, ids, '2')
20
21+ ## Generic set_priority_* and set_remaining_time_*
22+ def __getattr__(self, name):
23+ for prefix in ["set_priority", "set_remaining_time"]:
24+ if not name.startswith(prefix + "_"):
25+ continue
26+ arg = name[len(prefix) + 1:]
27+ try:
28+ arg = int(arg)
29+ except ValueError:
30+ continue ## defaults to standard get attr
31+ method = getattr(self, prefix)
32+
33+ ## ``method`` and ``arg`` are stored in closure
34+ def _custom_set(cr, uid, ids, context=None):
35+ return method(cr, uid, ids, arg, context)
36+
37+ return _custom_set
38+
39+ ## default getattr
40+ return super(osv.osv, self).__getattr__(name)
41+
42 def _check_recursion(self, cr, uid, ids, context=None):
43 for id in ids:
44 visited_branch = set()

Subscribers

People subscribed via source and target branches

to all changes: