[FIX] purchase: Update price unit on new line even if confirmed RFQ
Steps to reproduce: - Install purchase - Go to Settings and activate `Variant Grid Entry` - Create a new Requests for Quotation - Add a customer and add a product that has a variant min 2 variant - Wizard should ask for the variant - Select 1 variant by increasing quantity in the grid and confirm - Confirm order - Add again a product variant with the wizard Issue: Price unit is not set on the new line. Cause: In `_onchange_quantity` (triggered by the purchase_product_matrix module), we do not update price unit if order line is in state `purchase` or `done`. Solution: Replace condition to not perform `_onchange_quantity` if order line has an invoice line. opw-2956755 closes odoo/odoo#99522 X-original-commit: 8f92146b2d4996be724213345567291f045aad85 Signed-off-by: Adrien Widart <awt@odoo.com> Signed-off-by: Nasreddin Boulif (bon) <bon@odoo.com>
This commit is contained in:
@@ -1202,7 +1202,7 @@ class PurchaseOrderLine(models.Model):
|
||||
@api.depends('product_qty', 'product_uom')
|
||||
def _compute_price_unit_and_date_planned_and_name(self):
|
||||
for line in self:
|
||||
if not line.product_id:
|
||||
if not line.product_id or line.invoice_lines:
|
||||
continue
|
||||
params = {'order_id': line.order_id}
|
||||
seller = line.product_id._select_seller(
|
||||
|
||||
@@ -457,3 +457,57 @@ class TestPurchaseToInvoice(AccountTestInvoicingCommon):
|
||||
self.assertEqual(line.qty_invoiced, 10)
|
||||
line.qty_received = 15
|
||||
self.assertEqual(line.qty_invoiced, 10)
|
||||
|
||||
def test_on_change_quantity_price_unit(self):
|
||||
""" When a user changes the quantity of a product in a purchase order it
|
||||
should only update the unit price if PO line has no invoice line. """
|
||||
|
||||
supplierinfo_vals = {
|
||||
'partner_id': self.partner_a.id,
|
||||
'price': 10.0,
|
||||
'min_qty': 1,
|
||||
"product_id": self.product_order.id,
|
||||
"product_tmpl_id": self.product_order.product_tmpl_id.id,
|
||||
}
|
||||
|
||||
supplierinfo = self.env["product.supplierinfo"].create(supplierinfo_vals)
|
||||
po_form = Form(self.env['purchase.order'])
|
||||
po_form.partner_id = self.partner_a
|
||||
with po_form.order_line.new() as po_line_form:
|
||||
po_line_form.product_id = self.product_order
|
||||
po_line_form.product_qty = 1
|
||||
po = po_form.save()
|
||||
po_line = po.order_line[0]
|
||||
|
||||
self.assertEqual(10.0, po_line.price_unit, "Unit price should be set to 10.0 for 1 quantity")
|
||||
|
||||
# Ensure price unit is updated when changing quantity on a un-confirmed PO
|
||||
supplierinfo.write({'min_qty': 2, 'price': 20.0})
|
||||
po_line.write({'product_qty': 2})
|
||||
self.assertEqual(20.0, po_line.price_unit, "Unit price should be set to 20.0 for 2 quantity")
|
||||
|
||||
po.button_confirm()
|
||||
|
||||
# Ensure price unit is updated when changing quantity on a confirmed PO
|
||||
supplierinfo.write({'min_qty': 3, 'price': 30.0})
|
||||
po_line.write({'product_qty': 3})
|
||||
self.assertEqual(30.0, po_line.price_unit, "Unit price should be set to 30.0 for 3 quantity")
|
||||
|
||||
po.action_create_invoice()
|
||||
|
||||
# Ensure price unit is NOT updated when changing quantity on PO confirmed and line linked to an invoice line
|
||||
supplierinfo.write({'min_qty': 4, 'price': 40.0})
|
||||
po_line.write({'product_qty': 4})
|
||||
self.assertEqual(30.0, po_line.price_unit, "Unit price should be set to 30.0 for 3 quantity")
|
||||
|
||||
with po_form.order_line.new() as po_line_form:
|
||||
po_line_form.product_id = self.product_order
|
||||
po_line_form.product_qty = 1
|
||||
po = po_form.save()
|
||||
po_line = po.order_line[1]
|
||||
|
||||
self.assertEqual(235.0, po_line.price_unit, "Unit price should be reset to 235.0 since the supplier supplies minimum of 4 quantities")
|
||||
|
||||
# Ensure price unit is updated when changing quantity on PO confirmed and line NOT linked to an invoice line
|
||||
po_line.write({'product_qty': 4})
|
||||
self.assertEqual(40.0, po_line.price_unit, "Unit price should be set to 40.0 for 4 quantity")
|
||||
|
||||
Reference in New Issue
Block a user