[IMP] project : Synchronization between states and stages.

bzr revid: mdi@tinyerp.com-20120418092246-dswbz05h6jbzn21k
This commit is contained in:
Divyesh Makwana (Open ERP)
2012-04-18 14:52:46 +05:30
parent dcf9b25bff
commit 7eb95e5765
+31 -1
View File
@@ -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"