diff options
| author | Stephane Wirtel <stephane@openerp.com> | 2009-10-08 15:30:57 +0200 |
|---|---|---|
| committer | Stephane Wirtel <stephane@openerp.com> | 2009-10-08 15:30:57 +0200 |
| commit | 9a0d6aa9471287f7e43b567eb2de560587fc0e4d (patch) | |
| tree | 986442412e3a6f0f7ac12283482dbb9538c1d0fb /bin | |
| parent | fbee346b9261dc633c438e1335656f5f7cfd43f6 (diff) | |
[MERGE] Backport: http://bazaar.launchpad.net/~openobject-training/+junk/server/revision/1821
[FIX] Workflow button desactivation regarding user roles
bzr revid: stephane@openerp.com-20091008133057-3htx9jwebv9pprgd
Diffstat (limited to 'bin')
| -rw-r--r-- | bin/osv/orm.py | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/bin/osv/orm.py b/bin/osv/orm.py index 8c87b1bccf1..7c2c6718915 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -1062,19 +1062,37 @@ class orm_template(object): buttons = (n for n in node.getElementsByTagName('button') if n.getAttribute('type') != 'object') for button in buttons: - ok = True + can_click = True if user != 1: # admin user has all roles user_roles = usersobj.read(cr, user, [user], ['roles_id'])[0]['roles_id'] - cr.execute("select role_id from wkf_transition where signal=%s", (button.getAttribute('name'),)) + # TODO handle the case of more than one workflow for a model + cr.execute("""SELECT DISTINCT t.role_id + FROM wkf + INNER JOIN wkf_activity a ON a.wkf_id = wkf.id + INNER JOIN wkf_transition t ON (t.act_to = a.id) + WHERE wkf.osv = %s + AND t.signal = %s + """, (self._name, button.getAttribute('name'),)) roles = cr.fetchall() - for role in roles: - if role[0]: - ok = ok and rolesobj.check(cr, user, user_roles, role[0]) + + # draft -> valid = signal_next (role X) + # draft -> cancel = signal_cancel (no role) + # + # valid -> running = signal_next (role Y) + # valid -> cancel = signal_cancel (role Z) + # + # running -> done = signal_next (role Z) + # running -> cancel = signal_cancel (role Z) + - if not ok: - button.setAttribute('readonly', '1') - else: - button.setAttribute('readonly', '0') + # As we don't know the object state, in this scenario, + # the button "signal_cancel" will be always shown as there is no restriction to cancel in draft + # the button "signal_next" will be show if the user has any of the roles (X Y or Z) + # The verification will be made later in workflow process... + if roles: + can_click = any((not role) or rolesobj.check(cr, user, user_roles, role) for (role,) in roles) + + button.setAttribute('readonly', str(int(not can_click))) arch = node.toxml(encoding="utf-8").replace('\t', '') fields = self.fields_get(cr, user, fields_def.keys(), context) |
