[FIX] project_mrp: when task closed, procurement should be close. for that make transition between procurement.act_make_done and procurement.act_done with trigger on project.task model and condition to check closed task. on task closed, cancelled, fire this workflow trigger. no need to send manually signal subflow.done. so remove signal in transition of procurement.act_produce_service to procurement.act_make_done.

bzr revid: hmo@tinyerp.com-20111214063209-ezh4abwvabti81xx
This commit is contained in:
Harry (OpenERP) 2011-12-14 12:02:09 +05:30
parent 09f1515ea9
commit 5910e38001
5 changed files with 26 additions and 8 deletions

View File

@ -176,6 +176,9 @@ class procurement_order(osv.osv):
"""
res = False
for procurement in self.browse(cr, uid, ids, context=context):
product = procurement.product_id
if product.type == 'service':
res = True
if procurement.move_id and procurement.move_id.state == 'done':
res = True
return res
@ -273,7 +276,7 @@ class procurement_order(osv.osv):
if supplier.id == user.company_id.partner_id.id:
res = True
res = False
if procurement.product_id.type=='service':
if product.type=='service':
res = res and self.check_produce_service(cr, uid, procurement, context)
else:
res = res and self.check_produce_product(cr, uid, procurement, context)

View File

@ -31,10 +31,10 @@ class project_task(osv.osv):
}
def _validate_subflows(self, cr, uid, ids):
wf_service = netsvc.LocalService("workflow")
for task in self.browse(cr, uid, ids):
if task.procurement_id:
wf_service = netsvc.LocalService("workflow")
wf_service.trg_validate(uid, 'procurement.order', task.procurement_id.id, 'subflow.done', cr)
wf_service.trg_write(uid, 'procurement.order', task.procurement_id.id, cr)
def do_close(self, cr, uid, ids, *args, **kwargs):
res = super(project_task, self).do_close(cr, uid, ids, *args, **kwargs)

View File

@ -1,10 +1,12 @@
<?xml version="1.0"?>
<openerp>
<data>
<record model="workflow.transition" id="procurement.trans_produce_service_make_done">
<field name="act_from" ref="procurement.act_produce_service"/>
<field name="act_to" ref="procurement.act_make_done"/>
<field name="signal">subflow.done</field>
<record id="trans_make_done_done2" model="workflow.transition">
<field name="act_from" ref="procurement.act_make_done"/>
<field name="act_to" ref="procurement.act_done"/>
<field name="condition">check_task_done()</field>
<field name="trigger_model">project.task</field>
<field name="trigger_expr_id">task_id and [task_id.id] or []</field>
</record>
</data>
</openerp>

View File

@ -28,6 +28,19 @@ class procurement_order(osv.osv):
'task_id': fields.many2one('project.task', 'Task'),
'sale_line_id': fields.many2one('sale.order.line', 'Sale order line')
}
def check_task_done(self, cr, uid, ids, context=None):
""" Checks if task is done or not.
@return: True or False.
"""
res = False
for procurement in self.browse(cr, uid, ids, context=context):
product = procurement.product_id
if product.type<>'service':
res = True
if procurement.task_id and procurement.task_id.state in ('done', 'cancelled'):
res = True
return res
def check_produce_service(self, cr, uid, procurement, context=None):
return True

View File

@ -44,4 +44,4 @@
procurement_ids = self.search(cr, uid, [('sale_line_id', '=', ref('line_services'))])
assert procurement_ids, "Procurement is not generated for Service Order Line."
procurement = self.browse(cr, uid, procurement_ids[0], context=context)
assert procurement.state , "Procurement should be closed."
assert procurement.state == 'done' , "Procurement should be closed."