[IMP]: if child task is open then parent task shold not doneor close

If task is created from procurement and we done that task then sale order must be done.

bzr revid: aja@tinyerp.com-20130618113818-2t3uvswykwysxsnp
This commit is contained in:
ajay javiya (OpenERP) 2013-06-18 17:08:18 +05:30
parent 43b072cf22
commit 374ba0e238
6 changed files with 38 additions and 5 deletions

View File

@ -46,6 +46,7 @@ class project_task_type(osv.osv):
'project_ids': fields.many2many('project.project', 'project_task_type_rel', 'type_id', 'project_id', 'Projects'),
'fold': fields.boolean('Folded by Default',
help="This stage is not visible, for example in status bar or kanban view, when there are no records in that stage to display."),
'action': fields.text('Python Action'),
}
def _get_default_project_id(self, cr, uid, ctx={}):
proj = ctx.get('default_project_id', False)
@ -782,6 +783,7 @@ class task(base_stage, osv.osv):
'id': fields.integer('ID', readonly=True),
'color': fields.integer('Color Index'),
'user_email': fields.related('user_id', 'email', type='char', string='User Email', readonly=True),
'is_close': fields.boolean('Task is Close ?'),
}
_defaults = {
'stage_id': _get_default_stage_id,
@ -922,6 +924,12 @@ class task(base_stage, osv.osv):
return stage_ids[0]
return False
def action_task_close(self, cr, uid, ids, context=None):
return self.write(cr, uid, ids, {'is_close': True})
def action_task_open(self, cr, uid, ids, context=None):
return self.write(cr, uid, ids, {'is_close': False})
def _check_child_task(self, cr, uid, ids, context=None):
if context == None:
context = {}
@ -929,7 +937,7 @@ class task(base_stage, osv.osv):
for task in tasks:
if task.child_ids:
for child in task.child_ids:
if child.state in ['draft', 'open', 'pending']:
if not child.is_close:
raise osv.except_osv(_("Warning!"), _("Child task still open.\nPlease cancel or complete child task first."))
return True
@ -1026,6 +1034,15 @@ class task(base_stage, osv.osv):
self._store_history(cr, uid, [task_id], context=context)
return task_id
def _trigger_stage_action(self, cr, uid, ids, action, context):
for line in action['action'].split('\n'):
line = line.strip()
if line and hasattr(self,line):
getattr(self,line)(cr,uid,ids,context)
else:
raise osv.except_osv(_("Warning!"), _("Invalid Python Action."))
return True
# Overridden to reset the kanban_state to normal whenever
# the stage (stage_id) of the task changes.
def write(self, cr, uid, ids, vals, context=None):
@ -1038,6 +1055,9 @@ class task(base_stage, osv.osv):
vals['message_follower_ids'] += [(6, 0,[follower.id]) for follower in project_id.message_follower_ids]
if vals and not 'kanban_state' in vals and 'stage_id' in vals:
new_stage = vals.get('stage_id')
action=self.pool.get('project.task.type').read(cr, uid, new_stage, ['action'],context=context)
if action['action']:
self._trigger_stage_action(cr, uid, ids, action, context)
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

View File

@ -30,43 +30,51 @@
<record id="project_tt_analysis" model="project.task.type">
<field name="sequence">1</field>
<field name="name">Analysis</field>
<field name="action">action_task_open</field>
<field name="case_default" eval="False"/>
</record>
<record id="project_tt_specification" model="project.task.type">
<field name="sequence">2</field>
<field name="name">Specification</field>
<field name="action">action_task_open</field>
<field name="case_default" eval="True"/>
</record>
<record id="project_tt_design" model="project.task.type">
<field name="sequence">2</field>
<field name="name">Design</field>
<field name="action">action_task_open</field>
<field name="case_default" eval="True"/>
</record>
<record id="project_tt_development" model="project.task.type">
<field name="sequence">3</field>
<field name="name">Development</field>
<field name="action">action_task_open</field>
<field name="case_default" eval="True"/>
</record>
<record id="project_tt_testing" model="project.task.type">
<field name="sequence">4</field>
<field name="name">Testing</field>
<field name="action">action_task_open</field>
<field name="case_default" eval="True"/>
</record>
<record id="project_tt_merge" model="project.task.type">
<field name="sequence">5</field>
<field name="name">Merge</field>
<field name="action">action_task_open</field>
<field name="case_default" eval="False"/>
<field name="fold" eval="True"/>
</record>
<record id="project_tt_deployment" model="project.task.type">
<field name="sequence">100</field>
<field name="name">Done</field>
<field name="action">action_task_close</field>
<field name="case_default" eval="True"/>
<field name="fold" eval="True"/>
</record>
<record id="project_tt_cancel" model="project.task.type">
<field name="sequence">200</field>
<field name="name">Cancelled</field>
<field name="action">action_task_close</field>
<field name="case_default" eval="True"/>
<field name="fold" eval="True"/>
</record>

View File

@ -376,6 +376,7 @@
<group>
<group>
<field name="project_id" on_change="onchange_project(project_id)" context="{'default_use_tasks':1}"/>
<field name="is_close" invisible="1"/>
<field name="user_id"
on_change="onchange_user_assigned()"
options='{"no_open": True}'
@ -679,6 +680,7 @@
<group>
<field name="name"/>
<field name="case_default"/>
<field name="action"/>
</group>
<group>
<field name="sequence"/>

View File

@ -377,7 +377,6 @@ class project_issue(base_stage, osv.osv):
context=context)
def write(self, cr, uid, ids, vals, context=None):
#Update last action date every time the user changes the stage
if 'stage_id' in vals:
stage=self.pool.get('project.task.type').read(cr, uid, vals['stage_id'],['sequence'],context=context)
@ -390,7 +389,6 @@ class project_issue(base_stage, osv.osv):
sequence = [stage.sequence for stage in issue.project_id.type_ids[-2:]]
if stage['sequence'] in sequence:
vals['date_closed'] = time.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT)
return super(project_issue, self).write(cr, uid, ids, vals, context)
def onchange_task_id(self, cr, uid, ids, task_id, context=None):

View File

@ -30,7 +30,12 @@ class project_task(osv.osv):
'sale_line_id': fields.related('procurement_id', 'sale_line_id', type='many2one', relation='sale.order.line', store=True, string='Sales Order Line'),
}
def _validate_subflows(self, cr, uid, ids):
def action_task_close(self, cr, uid, ids, context=None):
res = super(project_task, self).action_task_close(cr, uid, ids,context)
self._validate_subflows(cr, uid, ids,context)
return res
def _validate_subflows(self, cr, uid, ids,context):
wf_service = netsvc.LocalService("workflow")
for task in self.browse(cr, uid, ids):
if task.procurement_id:

View File

@ -39,7 +39,7 @@ class procurement_order(osv.osv):
@return: True or False.
"""
for p in self.browse(cr, uid, ids, context=context):
if (p.product_id.type=='service') and (p.procure_method=='make_to_order') and p.task_id :
if (p.product_id.type=='service') and (p.procure_method=='make_to_order') and p.task_id and (not p.task_id.is_close):
return False
return True