[FIX] sale_mrp, sale_stock: procurement qty of kits
- Create a BOM kit for product F with: 2 Unit(s) of A 1 Unit(s) of B - Create a SO for 1 Unit(s) of F, confirm => a picking with 2 Unit(s) of A and 1 Unit(s) of B is created - Modify the Ordered Qty to 2 Unit(s) The picking is not updated. This is because `_get_qty_procurement` wrongly computed the product quantity based on the moves' quantities. This is not correct since the moves are for products A and B, not product F. At this point, it is not possible to make sure of the real procurement quantity. therefore, we use a very simple approach: we compare the sold quantity before and after modification, and return the difference. opw-1881227 closes odoo/odoo#27064
This commit is contained in:
@@ -47,6 +47,17 @@ class SaleOrderLine(models.Model):
|
||||
components[product] = {'qty': qty, 'uom': to_uom.id}
|
||||
return components
|
||||
|
||||
def _get_qty_procurement(self):
|
||||
self.ensure_one()
|
||||
# Specific case when we change the qty on a SO for a kit product.
|
||||
# We don't try to be too smart and keep a simple approach: we compare the quantity before
|
||||
# and after update, and return the difference. We don't take into account what was already
|
||||
# sent, or any other exceptional case.
|
||||
bom = self.env['mrp.bom']._bom_find(product=self.product_id)
|
||||
if bom and bom.type == 'phantom' and 'previous_product_uom_qty' in self.env.context:
|
||||
return self.env.context['previous_product_uom_qty'].get(self.id, 0.0)
|
||||
return super(SaleOrderLine, self)._get_qty_procurement()
|
||||
|
||||
|
||||
class AccountInvoiceLine(models.Model):
|
||||
# TDE FIXME: what is this code ??
|
||||
|
||||
@@ -99,14 +99,15 @@ class SaleOrderLine(models.Model):
|
||||
|
||||
@api.multi
|
||||
def write(self, values):
|
||||
lines = False
|
||||
lines = self.env['sale.order.line']
|
||||
if 'product_uom_qty' in values:
|
||||
precision = self.env['decimal.precision'].precision_get('Product Unit of Measure')
|
||||
lines = self.filtered(
|
||||
lambda r: r.state == 'sale' and float_compare(r.product_uom_qty, values['product_uom_qty'], precision_digits=precision) == -1)
|
||||
previous_product_uom_qty = {line.id: line.product_uom_qty for line in lines}
|
||||
res = super(SaleOrderLine, self).write(values)
|
||||
if lines:
|
||||
lines._action_launch_procurement_rule()
|
||||
lines.with_context(previous_product_uom_qty=previous_product_uom_qty)._action_launch_procurement_rule()
|
||||
return res
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user