group_id = self.pool.get("procurement.group").create(cr, uid, vals, context=context)
order.write({'procurement_group_id': group_id}, context=context)
- fixed = True
for line in order.order_line:
#Try to fix exception procurement (possible when after a shipping exception the user choose to recreate)
if line.procurement_ids:
- #first check them to see if they are in exception or not
+ #first check them to see if they are in exception or not (one of the related moves is cancelled)
procurement_obj.check(cr, uid, [x.id for x in line.procurement_ids if x.state not in ['cancel', 'done']])
line.refresh()
- #run procurement that are in exception
- if not procurement_obj.run(cr, uid, [x.id for x in line.procurement_ids if x.state == 'exception'], context=context):
- fixed = False
+ #run again procurement that are in exception in order to trigger another move
+ proc_ids += [x.id for x in line.procurement_ids if x.state == 'exception']
elif sale_line_obj.need_procurement(cr, uid, [line.id], context=context):
if (line.state == 'done') or not line.product_id:
continue
proc_id = procurement_obj.create(cr, uid, vals, context=context)
proc_ids.append(proc_id)
#Confirm procurement order such that rules will be applied on it
- #note that the workflow ensure proc_ids isn't an empty list
- if proc_ids:
- procurement_obj.run(cr, uid, proc_ids, context=context)
- # FP NOTE: do we need this? isn't it the workflow that should set this
- val = {}
- if order.state == 'shipping_except' and fixed:
- val['state'] = 'progress'
- val['shipped'] = False
+ #note that the workflow normally ensure proc_ids isn't an empty list
+ procurement_obj.run(cr, uid, proc_ids, context=context)
+
+ #if shipping was in exception and the user choose to recreate the delivery order, write the new status of SO
+ if order.state == 'shipping_except':
+ val = {'state': 'progress', 'shipped': False}
if (order.order_policy == 'manual'):
for line in order.order_line:
if (not line.invoiced) and (line.state not in ('cancel', 'draft')):
val['state'] = 'manual'
break
- order.write(val)
+ order.write(val)
return True
# if mode == 'finished':
for move in procurement.move_ids:
already_done_qty += move.product_uom_qty if move.state == 'done' else 0
already_done_qty_uos += move.product_uos_qty if move.state == 'done' else 0
- qty_left = max(procurement.product_qty-already_done_qty, 0)
- qty_uos_left = max(procurement.product_uos_qty-already_done_qty_uos, 0)
+ qty_left = max(procurement.product_qty - already_done_qty, 0)
+ qty_uos_left = max(procurement.product_uos_qty - already_done_qty_uos, 0)
vals = {
'name': procurement.name,
'company_id': procurement.company_id.id,
return super(procurement_order, self)._run(cr, uid, procurement, context)
def _check(self, cr, uid, procurement, context=None):
+ ''' Implement the procurement checking for rules of type 'move'. The procurement will be satisfied only if all related
+ moves are done/cancel and if the requested quantity is moved.
+ '''
if procurement.rule_id and procurement.rule_id.action == 'move':
+ uom_obj = self.pool.get('product.uom')
done_test_list = []
done_cancel_test_list = []
qty_done = 0
for move in procurement.move_ids:
done_test_list.append(move.state == 'done')
done_cancel_test_list.append(move.state in ('done', 'cancel'))
- qty_done += move.product_uom_qty if move.state == 'done' else 0
+ qty_done += move.product_qty if move.state == 'done' else 0
+ qty_done = uom_obj._compute_qty(cr, uid, procurement.product_id.uom_id.id, qty_done, procurement.product_uom.id)
at_least_one_done = any(done_test_list)
all_done_or_cancel = all(done_cancel_test_list)
if not all_done_or_cancel:
return False
- elif at_least_one_done and all_done_or_cancel and procurement.product_qty == qty_done:
+ elif all_done_or_cancel and procurement.product_qty == qty_done:
return True
elif at_least_one_done:
#some move cancelled and some validated
- self.message_post(cr, uid, [procurement.id], body=_('Some stock moves have been cancelled for this procurement.'), context=context)
+ self.message_post(cr, uid, [procurement.id], body=_('Some stock moves have been cancelled for this procurement. Run the procurement again to trigger a move for the remaining quantity or change the procurement quantity to finish it directly'), context=context)
else:
#all move are cancelled
self.message_post(cr, uid, [procurement.id], body=_('All stock moves have been cancelled for this procurement.'), context=context)