[FIX] purchase_requisition: create a PO alternative with note & section

Steps to reproduce the bug:
- Create a PO:
    - Add a product
    - Add a note or section
- Go To Alternatives:
    - Click on “Create Alternative”
         - Add another vendor
         - Try to validate

Problem:
An error is triggered: “The operation cannot be completed: Description
(name) is mandatory”

The “display_type” and “name” fields must be copied in the vals to
create a `purchase.order.line`

opw-3164863

closes odoo/odoo#115070

X-original-commit: 66f806399d173f53b61db80b81d06a93421c75a3
Signed-off-by: Tiffany Chang <tic@odoo.com>
Signed-off-by: Djamel Touati (otd) <otd@odoo.com>
This commit is contained in:
Touati Djamel (otd)
2023-03-13 15:28:01 +01:00
parent c5d7042815
commit 934d9a5caa
3 changed files with 23 additions and 6 deletions
@@ -207,7 +207,7 @@ class PurchaseOrder(models.Model):
'view_mode': 'list',
'res_model': 'purchase.order.line',
'views': [(view_id, "list")],
'domain': [('order_id', 'in', (self | self.alternative_po_ids).ids)],
'domain': [('order_id', 'in', (self | self.alternative_po_ids).ids), ('display_type', '=', False)],
'context': ctx,
}
@@ -153,6 +153,13 @@ class TestPurchaseRequisition(TestPurchaseRequisitionCommon):
line.product_id = self.product_09
line.product_qty = 5.0
line.price_unit = unit_price
line.product_uom = self.env.ref('uom.product_uom_dozen')
with po_form.order_line.new() as line:
line.display_type = "line_section"
line.name = "Products"
with po_form.order_line.new() as line:
line.display_type = 'line_note'
line.name = 'note1'
po_form.save()
# first flow: check that creating an alt PO correctly auto-links both POs to each other
@@ -166,13 +173,17 @@ class TestPurchaseRequisition(TestPurchaseRequisitionCommon):
# check alt po was created with correct values
alt_po_1 = orig_po.alternative_po_ids.filtered(lambda po: po.id != orig_po.id)
self.assertEqual(orig_po.order_line.product_id, alt_po_1.order_line.product_id, "Alternative PO should have copied the product to purchase from original PO")
self.assertEqual(orig_po.order_line.product_qty, alt_po_1.order_line.product_qty, "Alternative PO should have copied the qty to purchase from original PO")
self.assertEqual(len(alt_po_1.order_line), 3)
self.assertEqual(orig_po.order_line[0].product_id, alt_po_1.order_line[0].product_id, "Alternative PO should have copied the product to purchase from original PO")
self.assertEqual(orig_po.order_line[0].product_qty, alt_po_1.order_line[0].product_qty, "Alternative PO should have copied the qty to purchase from original PO")
self.assertEqual(orig_po.order_line[0].product_uom, alt_po_1.order_line[0].product_uom, "Alternative PO should have copied the product unit of measure from original PO")
self.assertEqual((orig_po.order_line[1].display_type, orig_po.order_line[1].name), (alt_po_1.order_line[1].display_type, alt_po_1.order_line[1].name))
self.assertEqual((orig_po.order_line[2].display_type, orig_po.order_line[2].name), (alt_po_1.order_line[2].display_type, alt_po_1.order_line[2].name))
self.assertEqual(len(alt_po_1.alternative_po_ids), 2, "Newly created PO should be auto-linked to itself and original PO")
# check compare POLs correctly calcs best date/price PO lines: orig_po.date_planned = best & alt_po.price = best
alt_po_1.order_line.date_planned += timedelta(days=1)
alt_po_1.order_line.price_unit = unit_price - 10
alt_po_1.order_line[0].date_planned += timedelta(days=1)
alt_po_1.order_line[0].price_unit = unit_price - 10
action = orig_po.action_compare_alternative_lines()
best_price_ids, best_date_ids, best_price_unit_ids = orig_po.get_tender_best_lines()
best_price_pol = self.env['purchase.order.line'].browse(best_price_ids)
@@ -83,4 +83,10 @@ class PurchaseRequisitionCreateAlternative(models.TransientModel):
@api.model
def _get_alternative_line_value(self, order_line):
return {'product_id': order_line.product_id.id, 'product_qty': order_line.product_qty}
return {
'product_id': order_line.product_id.id,
'product_qty': order_line.product_qty,
'product_uom': order_line.product_uom.id,
'display_type': order_line.display_type,
'name': order_line.name,
}