diff options
| author | Nicolas Martinelli <nim@odoo.com> | 2016-12-19 15:14:29 +0100 |
|---|---|---|
| committer | Nicolas Martinelli <nim@odoo.com> | 2016-12-20 18:29:16 +0100 |
| commit | a9a9f624e47251fa8bd966bc2118836350ddff01 (patch) | |
| tree | 9b294355e5d255b31a1478a8a070005856cfa9f0 | |
| parent | 2317801ddb6ed4c28336eb09382a64f3d6774b89 (diff) | |
[FIX] purchase: update of PO line
DO NOT FORWARDPORT!!!
An issue occurs when a PO line is updated following a reordering rule or
a MTO rule.
As an example, a product is configured as follow:
- UoM: Units
- Purchase UoM: Box of 25 Units
To reproduce:
- Sell one unit of product, then run the scheduler
=> it creates a procurement for one unit, but since the product is
purchased by box of 25, it creates a PO with a box of 25.
- Sell one unit of product, then run the scheduler
=> it creates a procurement for one unit, find the existing PO line,
round in the purchase UoM (so it gives one box of 25), then add it to
the PO line.
The solution is to recomputed the necessary quantity at the very end of
the process. For a given PO line, list all procurements and adjust the
quantity.
This is a partial fix, since it doesn't take into account the potential
new price of the seller. However, that would require a major rewrite of
this part of the code, since it was originally written for v8 which
handles the PO line quantity recomputation sequentially instead of
batch.
opw-688916
| -rw-r--r-- | addons/purchase/purchase.py | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 98e17b136f3..d3fdb96d35a 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -1634,26 +1634,18 @@ class procurement_order(osv.osv): for proc in procurements: if po_prod_dict.get(proc.product_id.id): po_line = po_prod_dict[proc.product_id.id] - # FIXME: compute quantity using `_calc_new_qty_price` method. - # new_qty, new_price = self._calc_new_qty_price(cr, uid, proc, po_line=po_line, context=context) - uom_id = po_line.product_uom # Convert to UoM of existing line - qty = uom_obj._compute_qty_obj(cr, uid, proc.product_uom, proc.product_qty, uom_id) - if lines_to_update.get(po_line): - lines_to_update[po_line] += [(proc.id, qty)] + lines_to_update[po_line] += [proc] else: - lines_to_update[po_line] = [(proc.id, qty)] + lines_to_update[po_line] = [proc] else: procs_to_create.append(proc) - procs = [] # Update the quantities of the lines that need to for line in lines_to_update.keys(): - tot_qty = 0 - for proc, qty in lines_to_update[line]: - tot_qty += qty - self.message_post(cr, uid, proc, body=_("Quantity added in existing Purchase Order Line"), context=context) - line_values += [(1, line.id, {'product_qty': line.product_qty + tot_qty, 'procurement_ids': [(4, x[0]) for x in lines_to_update[line]]})] + for proc in lines_to_update[line]: + self.message_post(cr, uid, proc.id, body=_("Quantity added in existing Purchase Order Line"), context=context) + line_values += [(1, line.id, {'procurement_ids': [(4, x[0].id) for x in lines_to_update[line]]})] # Create lines for which no line exists yet if procs_to_create: @@ -1665,6 +1657,21 @@ class procurement_order(osv.osv): self.message_post(cr, uid, [proc.id], body=_("Purchase line created and linked to an existing Purchase Order"), context=context) po_obj.write(cr, uid, [add_purchase], {'order_line': line_values},context=context) + # FIXME: partial fix of forward-port fe92dea. Ideally, we should use the method + # '_calc_new_qty_price'. However, this method was written for v8, where the PO line + # update was sequential, not in batch as it is now. + # DO NOT FORWARD PORT + for line, new_procs in lines_to_update.iteritems(): + qty = 0.0 + for proc in line.procurement_ids: + if proc in new_procs or proc.state == 'running': + qty += uom_obj._compute_qty(cr, uid, + proc.product_uom.id, proc.product_qty, proc.product_id.uom_id.id, round=False) + + new_qty = uom_obj._compute_qty(cr, uid, line.product_id.uom_id.id, qty, line.product_uom.id) + if new_qty > line.product_qty: + line.write({'product_qty': new_qty}) + for procurement in procurements: self.update_origin_po(cr, uid, po, procurement, context=context) |
