[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) <tic@odoo.com>
This commit is contained in:
Hubert Van de Walle (huvw)
2023-08-21 12:39:47 +02:00
parent d64e69e49c
commit 1076dbdd58
2 changed files with 17 additions and 2 deletions
@@ -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:
@@ -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"""