Skip to content
Snippets Groups Projects
Commit 591e424f authored by Victor Feyens's avatar Victor Feyens
Browse files

[FIX] purchase_product_matrix: multiple fixes


Same fixes for the purchase scope

1) Do not overwrite lines description if the line was not modified

2) Correctly recompute prices/sellers on quantity change.

When no new line was added to the PO through the matrix, the
prices/sellers were not recomputed, even if the qty was modified for
some products.

closes odoo/odoo#78902

Signed-off-by: default avatarVictor Feyens (vfe) <vfe@odoo.com>
parent 4f819438
No related branches found
No related tags found
No related merge requests found
...@@ -38,6 +38,7 @@ class PurchaseOrder(models.Model): ...@@ -38,6 +38,7 @@ class PurchaseOrder(models.Model):
if self.grid and self.grid_update: if self.grid and self.grid_update:
grid = json.loads(self.grid) grid = json.loads(self.grid)
product_template = self.env['product.template'].browse(grid['product_template_id']) product_template = self.env['product.template'].browse(grid['product_template_id'])
product_ids = set()
dirty_cells = grid['changes'] dirty_cells = grid['changes']
Attrib = self.env['product.template.attribute.value'] Attrib = self.env['product.template.attribute.value']
default_po_line_vals = {} default_po_line_vals = {}
...@@ -56,7 +57,13 @@ class PurchaseOrder(models.Model): ...@@ -56,7 +57,13 @@ class PurchaseOrder(models.Model):
old_qty = sum(order_lines.mapped('product_qty')) old_qty = sum(order_lines.mapped('product_qty'))
qty = cell['qty'] qty = cell['qty']
diff = qty - old_qty diff = qty - old_qty
if diff and order_lines:
if not diff:
continue
product_ids.add(product.id)
if order_lines:
if qty == 0: if qty == 0:
if self.state in ['draft', 'sent']: if self.state in ['draft', 'sent']:
# Remove lines if qty was set to 0 in matrix # Remove lines if qty was set to 0 in matrix
...@@ -87,7 +94,7 @@ class PurchaseOrder(models.Model): ...@@ -87,7 +94,7 @@ class PurchaseOrder(models.Model):
# if len(order_lines) > 1: # if len(order_lines) > 1:
# # Remove 1+ lines # # Remove 1+ lines
# self.order_line -= order_lines[1:] # self.order_line -= order_lines[1:]
elif diff: else:
if not default_po_line_vals: if not default_po_line_vals:
OrderLine = self.env['purchase.order.line'] OrderLine = self.env['purchase.order.line']
default_po_line_vals = OrderLine.default_get(OrderLine._fields.keys()) default_po_line_vals = OrderLine.default_get(OrderLine._fields.keys())
...@@ -100,10 +107,14 @@ class PurchaseOrder(models.Model): ...@@ -100,10 +107,14 @@ class PurchaseOrder(models.Model):
product_qty=qty, product_qty=qty,
product_no_variant_attribute_value_ids=no_variant_attribute_values.ids) product_no_variant_attribute_value_ids=no_variant_attribute_values.ids)
)) ))
if new_lines: if product_ids:
res = False res = False
self.update(dict(order_line=new_lines)) if new_lines:
for line in self.order_line.filtered(lambda line: line.product_template_id == product_template): # Add new PO lines
self.update(dict(order_line=new_lines))
# Recompute prices for new/modified lines:
for line in self.order_line.filtered(lambda line: line.product_id.id in product_ids):
res = line._product_id_change() or res res = line._product_id_change() or res
line._onchange_quantity() line._onchange_quantity()
return res return res
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment