[FIX] purchase_requisition: supplier info
When a blanket order is opened, a supplier info is created and should be used in priority over a regular supplier info with the same values. That's what rev [0] tried to do but there was some mistakes: the `purchase_requisition_id` field added in the order is ignored since it isn't stored and the test didn't failed because the created blanket has a lower price unit than the regular supplier info, meaning it is used in priority. Setting the same price unit (50) result in the new purchase order line merged in the first one. Do not re-implement the same order. Adapt the test now that we know the order didn't work (see rev[1]). The user has to manually set a higher priority to the supplier info generated by the purchase requisition. [0]e85838d358[1]2ac4f2ee0fcloses odoo/odoo#36840 Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
This commit is contained in:
@@ -6,7 +6,6 @@ from odoo import fields, models
|
||||
|
||||
class SupplierInfo(models.Model):
|
||||
_inherit = 'product.supplierinfo'
|
||||
_order = 'sequence, min_qty desc, price'
|
||||
|
||||
purchase_requisition_id = fields.Many2one('purchase.requisition', related='purchase_requisition_line_id.requisition_id', string='Agreement', readonly=False)
|
||||
purchase_requisition_line_id = fields.Many2one('purchase.requisition.line')
|
||||
|
||||
@@ -222,7 +222,6 @@ class PurchaseRequisitionLine(models.Model):
|
||||
'product_tmpl_id': self.product_id.product_tmpl_id.id,
|
||||
'price': self.price_unit,
|
||||
'currency_id': self.requisition_id.currency_id.id,
|
||||
'purchase_requisition_id': purchase_requisition.id,
|
||||
'purchase_requisition_line_id': self.id,
|
||||
})
|
||||
|
||||
|
||||
@@ -46,15 +46,14 @@ class TestPurchaseRequisitionStock(TestPurchaseRequisitionCommon):
|
||||
self.assertEqual(len(self.po_requisition.order_line), 1, 'Purchase order should have one line')
|
||||
|
||||
def test_02_purchase_requisition_stock(self):
|
||||
""" Set a static supplier info and make a delivery order for a "to buy" product, check that the purchase order created is consistent. Create a blanket order for this product, create a new delivery order for this product and check that the create purchase order set its values according to the blanket order.
|
||||
"""
|
||||
|
||||
"""Plays with the sequence of regular supplier infos and one created by blanket orders."""
|
||||
# Product creation
|
||||
unit = self.ref("uom.product_uom_unit")
|
||||
warehouse1 = self.env.ref('stock.warehouse0')
|
||||
route_buy = self.ref('purchase_stock.route_warehouse0_buy')
|
||||
route_mto = warehouse1.mto_pull_id.route_id.id
|
||||
vendor1 = self.env['res.partner'].create({'name': 'AAA', 'email': 'from.test@example.com'})
|
||||
vendor2 = self.env['res.partner'].create({'name': 'BBB', 'email': 'from.test2@example.com'})
|
||||
supplier_info1 = self.env['product.supplierinfo'].create({
|
||||
'name': vendor1.id,
|
||||
'price': 50,
|
||||
@@ -88,7 +87,7 @@ class TestPurchaseRequisitionStock(TestPurchaseRequisitionCommon):
|
||||
self.assertEqual(purchase1.order_line.price_unit, 50, 'The price on the purchase order is not the supplierinfo one')
|
||||
|
||||
# Blanket order creation
|
||||
line1 = (0, 0, {'product_id': product_test.id, 'product_qty': 18, 'product_uom_id': product_test.uom_po_id.id, 'price_unit': 42})
|
||||
line1 = (0, 0, {'product_id': product_test.id, 'product_qty': 18, 'product_uom_id': product_test.uom_po_id.id, 'price_unit': 50})
|
||||
requisition_type = self.env['purchase.requisition.type'].create({
|
||||
'name': 'Blanket test',
|
||||
'quantity_copy': 'none',
|
||||
@@ -96,7 +95,7 @@ class TestPurchaseRequisitionStock(TestPurchaseRequisitionCommon):
|
||||
requisition_blanket = self.env['purchase.requisition'].create({
|
||||
'line_ids': [line1],
|
||||
'type_id': requisition_type.id,
|
||||
'vendor_id': vendor1.id,
|
||||
'vendor_id': vendor2.id,
|
||||
'currency_id': self.env.ref("base.USD").id,
|
||||
})
|
||||
requisition_blanket.action_in_progress()
|
||||
@@ -114,9 +113,32 @@ class TestPurchaseRequisitionStock(TestPurchaseRequisitionCommon):
|
||||
})
|
||||
move2._action_confirm()
|
||||
|
||||
# As the supplier.info linked to the blanket order has the same price, the first one is stille used.
|
||||
self.assertEqual(purchase1.order_line.product_qty, 20)
|
||||
|
||||
# Update the sequence of the blanket order's supplier info.
|
||||
supplier_info1.sequence = 2
|
||||
requisition_blanket.line_ids.supplier_info_ids.sequence = 1
|
||||
# In [13]: [(x.sequence, x.min_qty, x.price, x.name.name) for x in supplier_info1 + requisition_blanket.line_ids.supplier_info_ids]
|
||||
# Out[13]: [(2, 0.0, 50.0, 'AAA'), (1, 0.0, 50.0, 'BBB')]
|
||||
|
||||
# Second stock move
|
||||
move3 = self.env['stock.move'].create({
|
||||
'name': '10 in',
|
||||
'procure_method': 'make_to_order',
|
||||
'location_id': stock_location.id,
|
||||
'location_dest_id': customer_location.id,
|
||||
'product_id': product_test.id,
|
||||
'product_uom': unit,
|
||||
'product_uom_qty': 10.0,
|
||||
'price_unit': 10
|
||||
})
|
||||
move3._action_confirm()
|
||||
|
||||
# Verifications
|
||||
purchase2 = self.env['purchase.order'].search([('partner_id', '=', vendor1.id), ('requisition_id', '=', requisition_blanket.id)])
|
||||
self.assertEqual(purchase2.order_line.price_unit, 42, 'The price on the purchase order is not the blanquet order one')
|
||||
purchase2 = self.env['purchase.order'].search([('partner_id', '=', vendor2.id), ('requisition_id', '=', requisition_blanket.id)])
|
||||
self.assertEqual(len(purchase2), 1)
|
||||
self.assertEqual(purchase2.order_line.price_unit, 50, 'The price on the purchase order is not the blanquet order one')
|
||||
|
||||
def test_03_purchase_requisition_stock(self):
|
||||
""" Two blanket orders on different 'make to order' products must generate
|
||||
|
||||
Reference in New Issue
Block a user