From 1076dbdd5853fbd11882be6b6d672e8e04a04d9c Mon Sep 17 00:00:00 2001 From: "Hubert Van de Walle (huvw)" Date: Thu, 17 Aug 2023 15:03:38 +0000 Subject: [PATCH] [FIX] purchase_requisition: add missing date_planned computation Steps to reproduce ================== - Create a blanket order - Choose a vendor - Add a product P - Set a price - Save and Confirm - Click on the RFQs/Orders smart button - Create a new RFQ - Delete the line - Add a new line with the same product P - Save -> A validation error appears because the date_planned is not set Cause of the issue ================== `_compute_price_unit_and_date_planned_and_name` is overriden and passes an empty recordset to the super method. Solution ======== We can compute the `date_planned` using the selected seller opw-3416573 closes odoo/odoo#132428 X-original-commit: d7db1d799fe042ef248968c6dee53eaf6e0ed3db Signed-off-by: Tiffany Chang (tic) --- addons/purchase_requisition/models/purchase.py | 6 +++++- .../tests/test_purchase_requisition.py | 13 ++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/addons/purchase_requisition/models/purchase.py b/addons/purchase_requisition/models/purchase.py index 43010097be2..d08541e27f7 100644 --- a/addons/purchase_requisition/models/purchase.py +++ b/addons/purchase_requisition/models/purchase.py @@ -4,7 +4,7 @@ from collections import defaultdict from odoo import api, fields, models, _, Command -from odoo.tools import get_lang +from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT, get_lang class PurchaseOrderGroup(models.Model): @@ -286,6 +286,10 @@ class PurchaseOrderLine(models.Model): date=pol.order_id.date_order and pol.order_id.date_order.date(), uom_id=line.product_uom_id, params=params) + + if not pol.date_planned: + pol.date_planned = pol._get_date_planned(seller).strftime(DEFAULT_SERVER_DATETIME_FORMAT) + product_ctx = {'seller_id': seller.id, 'lang': get_lang(pol.env, partner.lang).code} name = pol._get_product_purchase_description(pol.product_id.with_context(product_ctx)) if line.product_description_variants: diff --git a/addons/purchase_requisition/tests/test_purchase_requisition.py b/addons/purchase_requisition/tests/test_purchase_requisition.py index 60864a696b4..5f24c626929 100644 --- a/addons/purchase_requisition/tests/test_purchase_requisition.py +++ b/addons/purchase_requisition/tests/test_purchase_requisition.py @@ -91,10 +91,21 @@ class TestPurchaseRequisition(TestPurchaseRequisitionCommon): # lazy reproduction of clicking on "New Quotation" act_window button po_form = Form(self.env['purchase.order'].with_context({"default_requisition_id": bo.id, "default_user_id": False})) po = po_form.save() - po.button_confirm() + self.assertEqual(po.order_line.price_unit, bo.line_ids.price_unit, 'The blanket order unit price should have been copied to purchase order') self.assertEqual(po.partner_id, bo.vendor_id, 'The blanket order vendor should have been copied to purchase order') + po_form = Form(po) + po_form.order_line.remove(0) + with po_form.order_line.new() as line: + line.product_id = self.product_09 + line.product_qty = 5.0 + + po = po_form.save() + po.button_confirm() + self.assertEqual(po.order_line.price_unit, bo.line_ids.price_unit, 'The blanket order unit price should still be copied to purchase order') + self.assertEqual(po.state, "purchase") + def test_06_purchase_requisition(self): """ Create a blanket order for a product and a vendor already linked via a supplier info"""