diff --git a/addons/project/project.py b/addons/project/project.py
index c9cd49e54b9..7751a4613a5 100644
--- a/addons/project/project.py
+++ b/addons/project/project.py
@@ -44,9 +44,7 @@ class project_task_type(osv.osv):
'sequence': fields.integer('Sequence'),
'project_default': fields.boolean('Common to All Projects', help="If you check this field, this stage will be proposed by default on each new project. It will not assign this stage to existing projects."),
'project_ids': fields.many2many('project.project', 'project_task_type_rel', 'type_id', 'project_id', 'Projects'),
- 'state': fields.selection(_TASK_STATE, 'State', required=True,
- help='If the task is created the state is \'Draft\'.\n If the task is started, the state becomes \'In Progress\'.\n If review is needed the task is in \'Pending\' state.\
- \n If the task is over, the states is set to \'Done\'.'),
+ 'state': fields.selection(_TASK_STATE, 'State', required=True, help='This state is related to stage.'),
}
_defaults = {
'state': 'draft',
@@ -660,6 +658,31 @@ 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_ids = self.pool.get('project.task.type').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 +691,14 @@ 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)
+ }, help='If the task is created the state is \'Draft\'.\
+ \n If the task is started, the state becomes \'In Progress\'.\
+ \n If review is needed the task is in \'Pending\' state.\
+ \n If the task is over, the states is set to \'Done\'.'),
'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"
@@ -1087,6 +1117,10 @@ class task(osv.osv):
new_stage = vals.get('type_id')
vals_reset_kstate = dict(vals, kanban_state='normal')
for t in self.browse(cr, uid, ids, context=context):
+ #TO FIX:Kanban view doesn't raise warning
+# stages = [stage.id for stage in t.project_id.type_ids]
+# if new_stage not in stages:
+# raise osv.except_osv(_('Warning !'), _('Stage is not defined in the project.'))
write_vals = vals_reset_kstate if t.type_id != new_stage else vals
super(task,self).write(cr, uid, [t.id], write_vals, context=context)
result = True
diff --git a/addons/project/project_data.xml b/addons/project/project_data.xml
index b7b59911fa4..48bc3439382 100644
--- a/addons/project/project_data.xml
+++ b/addons/project/project_data.xml
@@ -24,21 +24,25 @@
1Design
+ draft2Development
+ open3Testing
+ pending4Deployment
+ done
diff --git a/addons/project/project_view.xml b/addons/project/project_view.xml
index 535c08c75b4..568e47d204f 100644
--- a/addons/project/project_view.xml
+++ b/addons/project/project_view.xml
@@ -224,15 +224,15 @@