diff --git a/addons/product/models/product.py b/addons/product/models/product.py index 75d475877a3..e13747f6ca1 100644 --- a/addons/product/models/product.py +++ b/addons/product/models/product.py @@ -162,7 +162,6 @@ class ProductProduct(models.Model): pricelist_item_ids = fields.Many2many( 'product.pricelist.item', 'Pricelist Items', compute='_get_pricelist_items') - product_seller_ids = fields.One2many('product.supplierinfo', 'product_id', 'Variant Vendors') _sql_constraints = [ ('barcode_uniq', 'unique(barcode)', _("A barcode can only be assigned to one product !")), @@ -479,11 +478,29 @@ class ProductProduct(models.Model): @api.multi def _select_seller(self, partner_id=False, quantity=0.0, date=None, uom_id=False): self.ensure_one() - SupInfo = self.env['product.supplierinfo'] - seller = SupInfo.find_seller(self.product_seller_ids, self, partner_id, quantity, date, uom_id) - if not seller: - seller = SupInfo.find_seller(self.seller_ids, self, partner_id, quantity, date, uom_id) - return seller + if date is None: + date = fields.Date.today() + res = self.env['product.supplierinfo'] + for seller in self.seller_ids: + # Set quantity in UoM of seller + quantity_uom_seller = quantity + if quantity_uom_seller and uom_id and uom_id != seller.product_uom: + quantity_uom_seller = uom_id._compute_quantity(quantity_uom_seller, seller.product_uom) + + if seller.date_start and seller.date_start > date: + continue + if seller.date_end and seller.date_end < date: + continue + if partner_id and seller.name not in [partner_id, partner_id.parent_id]: + continue + if quantity_uom_seller < seller.min_qty: + continue + if seller.product_id and seller.product_id != self: + continue + + res |= seller + break + return res @api.multi def price_compute(self, price_type, uom=False, currency=False, company=False): @@ -604,29 +621,3 @@ class SuppliferInfo(models.Model): delay = fields.Integer( 'Delivery Lead Time', default=1, required=True, help="Lead time in days between the confirmation of the purchase order and the receipt of the products in your warehouse. Used by the scheduler for automatic computation of the purchase order planning.") - - @api.model - def find_seller(self, sellers, product, partner_id=False, quantity=0.0, date=None, uom_id=False): - if date is None: - date = fields.Date.today() - res = self - for seller in sellers: - # Set quantity in UoM of seller - quantity_uom_seller = quantity - seller_uom = seller.product_uom or seller.product_id.product_tmpl_id.uom_id - if quantity_uom_seller and uom_id and uom_id != seller_uom: - quantity_uom_seller = uom_id._compute_quantity(quantity_uom_seller, seller_uom) - if seller.date_start and seller.date_start > date: - continue - if seller.date_end and seller.date_end < date: - continue - if partner_id and seller.name not in [partner_id, partner_id.parent_id]: - continue - if quantity_uom_seller < seller.min_qty: - continue - if seller.product_id and seller.product_id != product: - continue - - res |= seller - break - return res diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py index fed9b4a70db..4508ec7f9a9 100644 --- a/addons/product/models/product_template.py +++ b/addons/product/models/product_template.py @@ -70,7 +70,7 @@ class ProductTemplate(models.Model): 'Cost', compute='_compute_standard_price', inverse='_set_standard_price', search='_search_standard_price', digits=dp.get_precision('Product Price'), groups="base.group_user", - help="The cost price is used for valuate stocks or to assess the price of manufacturing a product. The purchase orders are fetching the vendor prices.") + help="Cost of the product, in the default unit of measure of the product.") volume = fields.Float( 'Volume', compute='_compute_volume', inverse='_set_volume', diff --git a/addons/product/views/product_views.xml b/addons/product/views/product_views.xml index dd8f6005333..65f4e5700f8 100644 --- a/addons/product/views/product_views.xml +++ b/addons/product/views/product_views.xml @@ -195,7 +195,7 @@ - + diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index 3a2ece5fa4b..ba48a3a6efd 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -755,8 +755,8 @@ class PurchaseOrderLine(models.Model): price_unit = self.env['account.tax']._fix_tax_included_price(seller.price, self.product_id.supplier_taxes_id, self.taxes_id) if seller else 0.0 if price_unit and seller and self.order_id.currency_id and seller.currency_id != self.order_id.currency_id: price_unit = seller.currency_id.compute(price_unit, self.order_id.currency_id) - seller_uom = seller.product_uom or seller.product_id.product_tmpl_id.uom_id - if self.product_uom and seller_uom != self.product_uom: + + if seller and self.product_uom and seller.product_uom != self.product_uom: price_unit = seller.product_uom._compute_price(price_unit, self.product_uom) self.price_unit = price_unit @@ -777,17 +777,12 @@ class PurchaseOrderLine(models.Model): if not self.product_id: return - seller_min_qty = self.product_id.product_seller_ids\ + seller_min_qty = self.product_id.seller_ids\ .filtered(lambda r: r.name == self.order_id.partner_id)\ .sorted(key=lambda r: r.min_qty) - if not seller_min_qty: - seller_min_qty = self.product_id.seller_ids\ - .filtered(lambda r: r.name == self.order_id.partner_id)\ - .sorted(key=lambda r: r.min_qty) if seller_min_qty: self.product_qty = seller_min_qty[0].min_qty or 1.0 - self.product_uom = seller_min_qty[0].product_uom\ - or seller_min_qty[0].product_id.product_tmpl_id.uom_id + self.product_uom = seller_min_qty[0].product_uom else: self.product_qty = 1.0 @@ -944,9 +939,7 @@ class ProcurementOrder(models.Model): cache = {} res = [] for procurement in self: - suppliers = procurement.product_id.product_seller_ids.filtered(lambda r: not r.product_id or r.product_id == procurement.product_id) - if not suppliers: - suppliers = procurement.product_id.seller_ids.filtered(lambda r: not r.product_id or r.product_id == procurement.product_id) + suppliers = procurement.product_id.seller_ids.filtered(lambda r: not r.product_id or r.product_id == procurement.product_id) if not suppliers: procurement.message_post(body=_('No vendor associated to product %s. Please set one to fix this procurement.') % (procurement.product_id.name)) continue diff --git a/addons/purchase/tests/test_purchase_order.py b/addons/purchase/tests/test_purchase_order.py index 393e30aacd0..5f1c1f3f645 100644 --- a/addons/purchase/tests/test_purchase_order.py +++ b/addons/purchase/tests/test_purchase_order.py @@ -3,7 +3,6 @@ from datetime import datetime -from odoo import fields from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT from odoo.addons.account.tests.account_test_classes import AccountingTestCase @@ -18,12 +17,11 @@ class TestPurchaseOrder(AccountingTestCase): self.AccountInvoice = self.env['account.invoice'] self.AccountInvoiceLine = self.env['account.invoice.line'] + def test_00_purchase_order_flow(self): self.partner_id = self.env.ref('base.res_partner_1') - self.partner_id_1 = self.env.ref('base.res_partner_3') self.product_id_1 = self.env.ref('product.product_product_8') self.product_id_2 = self.env.ref('product.product_product_11') - def test_00_purchase_order_flow(self): # Ensure product_id_2 doesn't have res_partner_1 as supplier if self.partner_id in self.product_id_2.seller_ids.mapped('name'): id_to_remove = self.product_id_2.seller_ids.filtered(lambda r: r.name == self.partner_id).ids[0] if self.product_id_2.seller_ids.filtered(lambda r: r.name == self.partner_id) else False @@ -85,57 +83,3 @@ class TestPurchaseOrder(AccountingTestCase): }) self.invoice.purchase_order_change() self.assertEqual(self.po.order_line.mapped('qty_invoiced'), [5.0, 5.0], 'Purchase: all products should be invoiced"') - - def test_01_vendor_price(self): - #Case1: We find a vendor for the product variant and take the variant vendor price. - #Add the vendors in product variants. - self.product_id_1.write({'product_seller_ids': [(0, 0, {'name': self.partner_id.id, 'min_qty': 5.0, 'price': 500.0})]}) - - #Lets create a purchase order to test the vendor price. - self.po1 = self.PurchaseOrder.create({'partner_id': self.partner_id.id}) - - #Call the 'onchange_product_id' to get the price from vendor. - po_line_1 = self.PurchaseOrderLine.new({ - 'name': self.product_id_1.name, - 'product_id': self.product_id_1.id, - 'order_id': self.po1.id, - 'product_uom': self.product_id_1.uom_po_id.id, - 'date_planned': fields.Datetime.now(), - }) - po_line_1.onchange_product_id() - line_dict_1 = po_line_1._convert_to_write({key: po_line_1[key] for key in po_line_1._cache}) - self.order_line1 = self.PurchaseOrderLine.create(line_dict_1) - - self.assertEqual(self.order_line1.product_qty, 5.0, 'Purchase: the minimal quantity of the product for the supplier should be 5.0.') - self.assertEqual(self.order_line1.price_unit, 500.0, 'Purchase: the price of the product for the supplier should be 500.0.') - - #Case2: When we don't find a vendor for the product variant, we take the price from product template. - #Add the vendors in product variants and product template. - self.product_id_1.write({ - 'product_seller_ids': [(0, 0, { - 'name': self.partner_id.id, - 'min_qty': 10, - 'price': 100})], - 'seller_ids': [(0, 0, { - 'name': self.partner_id_1.id, - 'min_qty': 4, - 'price': 150})] - }) - - #Lets create a purchase order to test the vendor price. - self.po2 = self.PurchaseOrder.create({'partner_id': self.partner_id_1.id}) - - #Call the 'onchange_product_id' to get the price from vendor. - po_line_2 = self.PurchaseOrderLine.new({ - 'name': self.product_id_1.name, - 'product_id': self.product_id_1.id, - 'order_id': self.po2.id, - 'product_uom': self.product_id_1.uom_po_id.id, - 'date_planned': fields.Datetime.now(), - }) - po_line_2.onchange_product_id() - line_dict_2 = po_line_2._convert_to_write(po_line_2._cache) - self.order_line2 = self.PurchaseOrderLine.create(line_dict_2) - - self.assertEqual(self.order_line2.product_qty, 4.0, 'Purchase: the minimal quantity of the product for the supplier should be 4.0.') - self.assertEqual(self.order_line2.price_unit, 150.0, 'Purchase: the price of the product for the supplier should be 150.0.') diff --git a/addons/purchase/views/purchase_views.xml b/addons/purchase/views/purchase_views.xml index 2afc49b045e..a3e2e1050b3 100644 --- a/addons/purchase/views/purchase_views.xml +++ b/addons/purchase/views/purchase_views.xml @@ -572,33 +572,6 @@ - - product.product.supplier.form.inherit - product.product - - - - True - - - - - - - - - - product.product.supplier.view.form.easy - product.product - - - - - - - - - product.category.property.form.inherit.stock product.category