From 7eb95e5765d76bdf087f18fb9ea18cfb7c36a01c Mon Sep 17 00:00:00 2001 From: "Divyesh Makwana (Open ERP)" Date: Wed, 18 Apr 2012 14:52:46 +0530 Subject: [PATCH] [IMP] project : Synchronization between states and stages. bzr revid: mdi@tinyerp.com-20120418092246-dswbz05h6jbzn21k --- addons/project/project.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/addons/project/project.py b/addons/project/project.py index c9cd49e54b9..5fe723e9b5b 100644 --- a/addons/project/project.py +++ b/addons/project/project.py @@ -660,6 +660,32 @@ class task(osv.osv): for work in self.pool.get('project.task.work').browse(cr, uid, ids, context=context): if work.task_id: result[work.task_id.id] = True return result.keys() + + def _get_state(self, cr, uid, ids, name, arg, context=None): + res = {} + for task in self.browse(cr, uid, ids, context=context): + if task.type_id: + res[task.id] = task.type_id.state + return res + + def _get_stage(self, cr, uid, ids, context=None): + task_obj = self.pool.get('project.task') + result = {} + for stage in self.browse(cr, uid, ids, context=context): + if stage.state: + task_ids = task_obj.search(cr, uid, [('state', '=', stage.state)], context=context) + for task in task_obj.browse(cr, uid, task_ids, context=context): + result[task.id] = True + return result.keys() + + def _save_state(self, cr, uid, task_id, field_name, field_value, arg, context=None): + stage_obj = self.pool.get('project.task.type') + stage_ids = stage_obj.search(cr, uid, [('state', '=', field_value)], context=context) + if stage_ids: + self.write(cr, uid, task_id, {'type_id': stage_ids[0]}, context=context) + else: + cr.execute("""update project_task set state=%s where id=%s""", (field_value, task_id, )) + return True _columns = { 'active': fields.function(_is_template, store=True, string='Not a Template Task', type='boolean', help="This field is computed automatically and have the same behavior than the boolean 'active' field: if the task is linked to a template or unactivated project, it will be hidden unless specifically asked."), @@ -668,7 +694,11 @@ class task(osv.osv): 'priority': fields.selection([('4','Very Low'), ('3','Low'), ('2','Medium'), ('1','Important'), ('0','Very important')], 'Priority', select=True), 'sequence': fields.integer('Sequence', select=True, help="Gives the sequence order when displaying a list of tasks."), 'type_id': fields.many2one('project.task.type', 'Stage'), - 'state': fields.related('type_id','state', type='selection', selection=_TASK_STATE, string="State", readonly=True, store=True), + 'state': fields.function(_get_state, fnct_inv=_save_state, type='selection', selection=_TASK_STATE, string="State", readonly=True, + store = { + 'project.task': (lambda self, cr, uid, ids, c={}: ids, ['type_id'], 10), + 'project.task.type': (_get_stage, ['state'], 10) + }), 'kanban_state': fields.selection([('normal', 'Normal'),('blocked', 'Blocked'),('done', 'Ready To Pull')], 'Kanban State', help="A task's kanban state indicates special situations affecting it:\n" " * Normal is the default situation\n"