Revert "[IMP] product,purchase: Make the vendor price configurable on the variants too."

This reverts commit d5c24abee5 which is
broken since e945b86d5a but hasn't been
noticed due to non-validation of views (fixed by fe02b79a65).
This commit is contained in:
Christophe Simonis
2016-12-12 14:34:35 +01:00
parent 8a808d1703
commit 5f945a5fc5
6 changed files with 31 additions and 130 deletions
+23 -32
View File
@@ -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
+1 -1
View File
@@ -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',
+1 -1
View File
@@ -195,7 +195,7 @@
<field name="type" invisible="1"/>
</group>
</group>
<group name="pricing_and_weight">
<group>
<group name="pricing" string="Pricing">
<field name="product_variant_count" invisible="1"/>
<field name="lst_price" widget='monetary' options="{'currency_field': 'currency_id'}" attrs="{'readonly': [('product_variant_count', '&gt;', 1)]}"/>
+5 -12
View File
@@ -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
+1 -57
View File
@@ -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.')
-27
View File
@@ -572,33 +572,6 @@
</field>
</record>
<record id="product_product_supplier_form_inherit" model="ir.ui.view">
<field name="name">product.product.supplier.form.inherit</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_normal_form_view"/>
<field name="arch" type="xml">
<field name="seller_ids" position="attributes">
<attribute name="readonly">True</attribute>
</field>
<field name="seller_ids" position="after">
<separator string="Variant Vendors"/>
<field name="product_seller_ids"/>
</field>
</field>
</record>
<record id="product_variant_supplier_easy_edit_view" model="ir.ui.view">
<field name="name">product.product.supplier.view.form.easy</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_variant_easy_edit_view"/>
<field name="arch" type="xml">
<group name="pricing_and_weight" position="after">
<separator string="Vendors"/>
<field name="product_seller_ids"/>
</group>
</field>
</record>
<record id="view_category_property_form" model="ir.ui.view">
<field name="name">product.category.property.form.inherit.stock</field>
<field name="model">product.category</field>