[FIX] purchase_requisition: create alternative PO without requisition_id
Steps to reproduce the bug:
- Create a blanket order:
- add any storable product
- Confirm
- Click on new quotation
- Create an alternative purchase order from the new PO
Problem:
A user error is triggered, because the “date_planned” is not set in the
`purchase.order.line`:
"The operation cannot be completed: Missing required fields on
accountable purchase order line."
The `default_requisition_id` is set in the context, so the alternative
purchase order is created with the `requisition_id` field set, and in
the compute override `_compute_price_unit_and_date_planned_and_name`:
https://github.com/odoo/odoo/blob/863c5090f09bfffc2867717ed8b3c99b05a5eb9c/addons/purchase_requisition/models/purchase.py#L119-L120
we don't set the `date_planned` and don't call the super compute with
this record, therefore the `date_planned` is not set:
https://github.com/odoo/odoo/blob/863c5090f09bfffc2867717ed8b3c99b05a5eb9c/addons/purchase_requisition/models/purchase.py#L132
https://github.com/odoo/odoo/blob/863c5090f09bfffc2867717ed8b3c99b05a5eb9c/addons/purchase/models/purchase.py#L1209-L1210
opw-3217377
closes odoo/odoo#115596
X-original-commit: 831ebe11c45e59c16a43051889512dc14fa75eb1
Signed-off-by: Tiffany Chang <tic@odoo.com>
Signed-off-by: Djamel Touati (otd) <otd@odoo.com>
This commit is contained in:
@@ -284,3 +284,41 @@ class TestPurchaseRequisition(TestPurchaseRequisitionCommon):
|
||||
self.assertEqual(
|
||||
po_1.order_line.price_unit, 16,
|
||||
"Line's unit price from the original PO shouldn't be changed")
|
||||
|
||||
def test_11_alternative_po_from_po_with_requisition_id(self):
|
||||
"""Create a purchase order from a blanket order, then check that the alternative purchase order
|
||||
can be created and that the requisition_id is not set on it.
|
||||
"""
|
||||
# create an empty blanket order
|
||||
requisition_type = self.env['purchase.requisition.type'].create({
|
||||
'name': 'Blanket test',
|
||||
'quantity_copy': 'none'
|
||||
})
|
||||
line1 = (0, 0, {
|
||||
'product_id': self.product_13.id,
|
||||
'product_uom_id': self.product_13.uom_po_id.id,
|
||||
'price_unit': 41,
|
||||
'product_qty': 10,
|
||||
})
|
||||
requisition_blanket = self.env['purchase.requisition'].create({
|
||||
'line_ids': [line1],
|
||||
'type_id': requisition_type.id,
|
||||
'vendor_id': self.res_partner_1.id,
|
||||
})
|
||||
requisition_blanket.action_in_progress()
|
||||
# lazy reproduction of clicking on "New Quotation" act_window button
|
||||
po_form = Form(self.env['purchase.order'].with_context({"default_requisition_id": requisition_blanket.id, "default_user_id": False}))
|
||||
po_1 = po_form.save()
|
||||
po_1.button_confirm()
|
||||
self.assertTrue(po_1.requisition_id, "The requisition_id should be set in the purchase order")
|
||||
|
||||
# Creates an alternative PO.
|
||||
action = po_1.action_create_alternative()
|
||||
alt_po_wizard_form = Form(self.env['purchase.requisition.create.alternative'].with_context(**action['context']))
|
||||
alt_po_wizard_form.partner_id = self.res_partner_1
|
||||
alt_po_wizard_form.copy_products = True
|
||||
alt_po_wizard = alt_po_wizard_form.save()
|
||||
alt_po_wizard.action_create_alternative()
|
||||
|
||||
po_2 = po_1.alternative_po_ids - po_1
|
||||
self.assertFalse(po_2.requisition_id, "The requisition_id should not be set in the alternative purchase order")
|
||||
|
||||
@@ -59,7 +59,7 @@ class PurchaseRequisitionCreateAlternative(models.TransientModel):
|
||||
'order has a blocking warning on it and cannot be selected to create an alternative.')
|
||||
)
|
||||
vals = self._get_alternative_values()
|
||||
alt_po = self.env['purchase.order'].with_context(origin_po_id=self.origin_po_id.id).create(vals)
|
||||
alt_po = self.env['purchase.order'].with_context(origin_po_id=self.origin_po_id.id, default_requisition_id=False).create(vals)
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'view_mode': 'form',
|
||||
|
||||
Reference in New Issue
Block a user