summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorSébastien Theys <seb@odoo.com>2019-06-17 09:42:16 +0000
committerSébastien Theys <seb@odoo.com>2019-06-17 10:52:01 +0000
commite05442fe191aff4686d3adc4d7f689deef13e730 (patch)
tree5f2f9df548ec861ad56c8af900027218d0ca0f75 /addons
parent7316111aafbf4740ded06376c635a722add8bfbf (diff)
[IMP] product, *: clean test and demo set up with attribute lines
* = account, mrp, purchase_stock, sale, sale_product_configurator, stock_account, website_sale It is always better to create the product template attribute lines before creating the variants. In a following commit, this will become mandatory. The variants that are created should always match the combination of attributes set on the template. Finally explicitly call `create_variant_ids` when possible instead of reassigning the attribute lines to implicitly call `create_variant_ids`. closes odoo/odoo#34122 Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
Diffstat (limited to 'addons')
-rw-r--r--addons/account/tests/test_product_id_change.py4
-rw-r--r--addons/mrp/tests/common.py2
-rw-r--r--addons/mrp/tests/test_bom.py11
-rw-r--r--addons/product/data/product_demo.xml54
-rw-r--r--addons/product/tests/common.py15
-rw-r--r--addons/product/tests/test_variants.py30
-rw-r--r--addons/purchase_stock/tests/test_onchange_product.py2
-rw-r--r--addons/sale/tests/test_onchange.py2
-rw-r--r--addons/sale_product_configurator/tests/test_sale_product_configurator_ui.py20
-rw-r--r--addons/stock_account/tests/test_anglo_saxon_valuation_reconciliation_common.py8
-rw-r--r--addons/website_sale/data/demo.xml22
11 files changed, 87 insertions, 83 deletions
diff --git a/addons/account/tests/test_product_id_change.py b/addons/account/tests/test_product_id_change.py
index c9ebaaebca3..88fce1d846b 100644
--- a/addons/account/tests/test_product_id_change.py
+++ b/addons/account/tests/test_product_id_change.py
@@ -43,8 +43,8 @@ class TestProductIdChange(AccountingTestCase):
list_price='121',
taxes_id=[(6, 0, [tax_include_sale.id])],
supplier_taxes_id=[(6, 0, [tax_include_purchase.id])]))
- product = self.product_model.create(dict(product_tmpl_id=product_tmpl.id,
- standard_price='242'))
+ product = product_tmpl.product_variant_id
+ product.standard_price = '242'
fp = self.fiscal_position_model.create(dict(name="fiscal position", sequence=1))
fp_tax_sale = self.fiscal_position_tax_model.create(dict(position_id=fp.id,
tax_src_id=tax_include_sale.id,
diff --git a/addons/mrp/tests/common.py b/addons/mrp/tests/common.py
index 55e817e68f6..b9592d4720e 100644
--- a/addons/mrp/tests/common.py
+++ b/addons/mrp/tests/common.py
@@ -57,7 +57,7 @@ class TestMrpCommon(common2.TestStockCommon):
user_group_mrp_byproducts = cls.env.ref('mrp.group_mrp_byproducts')
# Update demo products
- (cls.product_2 | cls.product_3 | cls.product_4 | cls.product_5 | cls.product_6 | cls.product_7 | cls.product_8).write({
+ (cls.product_2 | cls.product_3 | cls.product_4 | cls.product_5 | cls.product_6 | cls.product_7_3 | cls.product_8).write({
'type': 'product',
})
diff --git a/addons/mrp/tests/test_bom.py b/addons/mrp/tests/test_bom.py
index cacdf65189d..12cd389666f 100644
--- a/addons/mrp/tests/test_bom.py
+++ b/addons/mrp/tests/test_bom.py
@@ -4,7 +4,6 @@
from odoo import exceptions
from odoo.tests import Form
from odoo.addons.mrp.tests.common import TestMrpCommon
-from odoo.tests import Form
from odoo.tools import float_compare, float_round
@@ -23,8 +22,8 @@ class TestBoM(TestMrpCommon):
def test_variants(self):
test_bom = self.env['mrp.bom'].create({
- 'product_id': self.product_7.id,
- 'product_tmpl_id': self.product_7.product_tmpl_id.id,
+ 'product_id': self.product_7_3.id,
+ 'product_tmpl_id': self.product_7_template.id,
'product_uom_id': self.uom_unit.id,
'product_qty': 4.0,
'routing_id': self.routing_2.id,
@@ -47,7 +46,7 @@ class TestBoM(TestMrpCommon):
'product_qty': 2,
'attribute_value_ids': [(4, self.prod_attr1_v2.id)],
})
- boms, lines = test_bom.explode(self.product_7, 4)
+ boms, lines = test_bom.explode(self.product_7_3, 4)
self.assertIn(test_bom, [b[0]for b in boms])
self.assertIn(test_bom_l1, [l[0] for l in lines])
self.assertNotIn(test_bom_l2, [l[0] for l in lines])
@@ -88,8 +87,8 @@ class TestBoM(TestMrpCommon):
})
test_bom_2 = self.env['mrp.bom'].create({
- 'product_id': self.product_7.id,
- 'product_tmpl_id': self.product_7.product_tmpl_id.id,
+ 'product_id': self.product_7_3.id,
+ 'product_tmpl_id': self.product_7_template.id,
'product_uom_id': self.uom_unit.id,
'product_qty': 4.0,
'routing_id': self.routing_2.id,
diff --git a/addons/product/data/product_demo.xml b/addons/product/data/product_demo.xml
index 1e7a7d3a37d..a46ab878d1a 100644
--- a/addons/product/data/product_demo.xml
+++ b/addons/product/data/product_demo.xml
@@ -183,6 +183,19 @@
<field name="uom_po_id" ref="uom.product_uom_unit"/>
<field name="description_sale">160x80cm, with large legs.</field>
</record>
+
+ <!-- the product template attribute lines have to be defined before creating the variants -->
+ <record id="product_template_attribute_line_1" model="product.template.attribute.line">
+ <field name="product_tmpl_id" ref="product_product_4_product_template"/>
+ <field name="attribute_id" ref="product_attribute_1"/>
+ <field name="value_ids" eval="[(6, 0, [ref('product.product_attribute_value_1'), ref('product.product_attribute_value_2')])]"/>
+ </record>
+ <record id="product_template_attribute_line_2" model="product.template.attribute.line">
+ <field name="product_tmpl_id" ref="product_product_4_product_template"/>
+ <field name="attribute_id" ref="product_attribute_2"/>
+ <field name="value_ids" eval="[(6, 0, [ref('product.product_attribute_value_3'), ref('product.product_attribute_value_4')])]"/>
+ </record>
+
<record id="product_product_4" model="product.product">
<field name="default_code">FURN_0096</field>
<field name="standard_price">500.0</field>
@@ -216,21 +229,6 @@
<field name="image" type="base64" file="product/static/img/table01.png"/>
</record>
- <record id="product_template_attribute_line_1" model="product.template.attribute.line">
- <field name="product_tmpl_id" ref="product_product_4_product_template"/>
- <field name="attribute_id" ref="product_attribute_1"/>
- <field name="value_ids" eval="[(6,0,[ref('product.product_attribute_value_1'), ref('product.product_attribute_value_2')])]"/>
- </record>
- <record id="product_template_attribute_line_2" model="product.template.attribute.line">
- <field name="product_tmpl_id" ref="product_product_4_product_template"/>
- <field name="attribute_id" ref="product_attribute_2"/>
- <field name="value_ids" eval="[(6,0,[ref('product.product_attribute_value_3'), ref('product.product_attribute_value_4')])]"/>
- </record>
-
- <record id="product_product_4_product_template" model="product.template">
- <field name="attribute_line_ids" eval="[(6,0,[ref('product.product_template_attribute_line_1'), ref('product.product_template_attribute_line_2')])]"/>
- </record>
-
<record id="product_product_5" model="product.product">
<field name="name">Corner Desk Right Sit</field>
<field name="categ_id" ref="product_category_5"/>
@@ -311,35 +309,35 @@
<field name="image" type="base64" file="product/static/img/product_product_10-image.png"/>
</record>
- <record id="product_product_11" model="product.product">
+ <record id="product_product_11_product_template" model="product.template">
<field name="name">Conference Chair</field>
<field name="categ_id" ref="product_category_5"/>
<field name="standard_price">14</field>
<field name="list_price">16.50</field>
<field name="type">consu</field>
- <field name="weight">0.01</field>
<field name="uom_id" ref="uom.product_uom_unit"/>
<field name="uom_po_id" ref="uom.product_uom_unit"/>
- <field name="default_code">E-COM12</field>
- <field name="attribute_value_ids" eval="[(6,0,[ref('product.product_attribute_value_1')])]"/>
<field name="image" type="base64" file="product/static/img/product_product_11-image.png"/>
</record>
- <record id="product_product_11b" model="product.product">
- <field name="name">Conference Chair</field>
- <field name="default_code">E-COM13</field>
- <field name="weight">0.01</field>
- <field name="product_tmpl_id" ref="product_product_11_product_template"/>
- <field name="attribute_value_ids" eval="[(6,0,[ref('product.product_attribute_value_2')])]"/>
- </record>
+ <!-- the product template attribute lines have to be defined before creating the variants -->
<record id="product_template_attribute_line_4" model="product.template.attribute.line">
<field name="product_tmpl_id" ref="product_product_11_product_template"/>
<field name="attribute_id" ref="product_attribute_1"/>
<field name="value_ids" eval="[(6,0,[ref('product.product_attribute_value_1'), ref('product.product_attribute_value_2')])]"/>
</record>
- <record id="product_product_11_product_template" model="product.template">
- <field name="attribute_line_ids" eval="[(6,0,[ref('product.product_template_attribute_line_4')])]"/>
+ <record id="product_product_11" model="product.product">
+ <field name="default_code">E-COM12</field>
+ <field name="weight">0.01</field>
+ <field name="product_tmpl_id" ref="product_product_11_product_template"/>
+ <field name="attribute_value_ids" eval="[(6, 0, [ref('product.product_attribute_value_1')])]"/>
+ </record>
+ <record id="product_product_11b" model="product.product">
+ <field name="default_code">E-COM13</field>
+ <field name="weight">0.01</field>
+ <field name="product_tmpl_id" ref="product_product_11_product_template"/>
+ <field name="attribute_value_ids" eval="[(6, 0, [ref('product.product_attribute_value_2')])]"/>
</record>
<!--
diff --git a/addons/product/tests/common.py b/addons/product/tests/common.py
index 8bfec6ff2d8..cc91604e129 100644
--- a/addons/product/tests/common.py
+++ b/addons/product/tests/common.py
@@ -66,6 +66,7 @@ class TestProductCommon(common.SavepointCase):
cls.prod_att_1 = cls.env['product.attribute'].create({'name': 'Color'})
cls.prod_attr1_v1 = cls.env['product.attribute.value'].create({'name': 'red', 'attribute_id': cls.prod_att_1.id})
cls.prod_attr1_v2 = cls.env['product.attribute.value'].create({'name': 'blue', 'attribute_id': cls.prod_att_1.id})
+ cls.prod_attr1_v3 = cls.env['product.attribute.value'].create({'name': 'green', 'attribute_id': cls.prod_att_1.id})
cls.product_7_template = cls.env['product.template'].create({
'name': 'Sofa',
@@ -76,17 +77,9 @@ class TestProductCommon(common.SavepointCase):
'value_ids': [(6, 0, [cls.prod_attr1_v1.id, cls.prod_attr1_v2.id])]
})]
})
- cls.product_7 = Product.create({
- 'product_tmpl_id': cls.product_7_template.id,
- })
- cls.product_7_1 = Product.create({
- 'product_tmpl_id': cls.product_7_template.id,
- 'attribute_value_ids': [(6, 0, [cls.prod_attr1_v1.id])],
- })
- cls.product_7_2 = Product.create({
- 'product_tmpl_id': cls.product_7_template.id,
- 'attribute_value_ids': [(6, 0, [cls.prod_attr1_v2.id])],
- })
+ cls.product_7_1 = cls.product_7_template.product_variant_ids.filtered(lambda p: p.attribute_value_ids == cls.prod_attr1_v1)
+ cls.product_7_2 = cls.product_7_template.product_variant_ids.filtered(lambda p: p.attribute_value_ids == cls.prod_attr1_v2)
+ cls.product_7_3 = cls.product_7_template.product_variant_ids.filtered(lambda p: p.attribute_value_ids == cls.prod_attr1_v3)
cls.product_8 = Product.create({
'name': 'House',
diff --git a/addons/product/tests/test_variants.py b/addons/product/tests/test_variants.py
index ed7f1f777c5..7f9d232fd46 100644
--- a/addons/product/tests/test_variants.py
+++ b/addons/product/tests/test_variants.py
@@ -362,16 +362,18 @@ class TestVariantsNoCreate(common.TestProductCommon):
'attribute_line_ids': [
(0, 0, { # one variant for this one
'attribute_id': self.prod_att_1.id,
- 'value_ids': [(4, self.prod_attr1_v1.id)],
+ 'value_ids': [(6, 0, self.prod_attr1_v1.ids)],
}),
],
})
self.assertEqual(len(template.product_variant_ids), 1)
-
- for variant_id in template.product_variant_ids:
- variant_id.attribute_value_ids += self.size_S
- template.attribute_line_ids += template.attribute_line_ids.browse()
+ template.attribute_line_ids = [(0, 0, {
+ 'attribute_id': self.size.id,
+ 'value_ids': [(6, 0, self.size_S.ids)],
+ })]
self.assertEqual(len(template.product_variant_ids), 1)
+ # no_variant attribute should not appear on the variant
+ self.assertNotIn(self.size_S, template.product_variant_ids.attribute_value_ids)
class TestVariantsManyAttributes(common.TestAttributesCommon):
@@ -481,12 +483,18 @@ class TestVariantsImages(common.TestProductCommon):
'name': 'template',
})
- for color in self.colors:
- attr = self.env['product.attribute.value'].create({
- 'name': color,
- 'attribute_id': product_attribute.id,
- })
+ color_values = self.env['product.attribute.value'].create([{
+ 'name': color,
+ 'attribute_id': product_attribute.id,
+ } for color in self.colors])
+
+ self.env['product.template.attribute.line'].create({
+ 'attribute_id': product_attribute.id,
+ 'product_tmpl_id': self.template.id,
+ 'value_ids': [(6, 0, color_values.ids)],
+ })
+ for color, color_value in zip(self.colors, color_values):
f = io.BytesIO()
Image.new('RGB', (800, 500), self.colors[color]).save(f, 'PNG')
f.seek(0)
@@ -494,7 +502,7 @@ class TestVariantsImages(common.TestProductCommon):
self.env['product.product'].create({
'image_raw_original': self.images[color],
- 'attribute_value_ids': [(6, 0, [attr.id])],
+ 'attribute_value_ids': [(6, 0, [color_value.id])],
'product_tmpl_id': self.template.id,
})
# the first one has no image, no color
diff --git a/addons/purchase_stock/tests/test_onchange_product.py b/addons/purchase_stock/tests/test_onchange_product.py
index 39c2621d2c3..fe7a239a607 100644
--- a/addons/purchase_stock/tests/test_onchange_product.py
+++ b/addons/purchase_stock/tests/test_onchange_product.py
@@ -48,7 +48,7 @@ class TestOnchangeProductId(TransactionCase):
list_price=121,
seller_ids=[(6, 0, [supplierinfo.id])],
supplier_taxes_id=[(6, 0, [tax_include_id.id])]))
- product_id = self.product_model.create(dict(product_tmpl_id=product_tmpl_id.id))
+ product_id = product_tmpl_id.product_variant_id
fp_id = self.fiscal_position_model.create(dict(name="fiscal position", sequence=1))
diff --git a/addons/sale/tests/test_onchange.py b/addons/sale/tests/test_onchange.py
index dbb5c6b83d1..cb3c06eaddb 100644
--- a/addons/sale/tests/test_onchange.py
+++ b/addons/sale/tests/test_onchange.py
@@ -42,7 +42,7 @@ class TestOnchangeProductId(TransactionCase):
list_price=121,
taxes_id=[(6, 0, [tax_include_id.id])]))
- product_id = self.product_model.create(dict(product_tmpl_id=product_tmpl_id.id))
+ product_id = product_tmpl_id.product_variant_id
fp_id = self.fiscal_position_model.create(dict(name="fiscal position", sequence=1))
diff --git a/addons/sale_product_configurator/tests/test_sale_product_configurator_ui.py b/addons/sale_product_configurator/tests/test_sale_product_configurator_ui.py
index e6b19f9982e..21565e631f7 100644
--- a/addons/sale_product_configurator/tests/test_sale_product_configurator_ui.py
+++ b/addons/sale_product_configurator/tests/test_sale_product_configurator_ui.py
@@ -61,17 +61,17 @@ class TestUi(odoo.tests.HttpCase):
'attribute_id': product_attribute.id
} for i in range(1, 11) for product_attribute in product_attributes])
- product_template_attribute_lines = self.env['product.template.attribute.line'].create([{
+ product_template = self.env.ref("product.product_product_4_product_template")
+
+ self.env['product.template.attribute.line'].create([{
'attribute_id': product_attribute.id,
- 'product_tmpl_id': self.env.ref("product.product_product_4").id,
+ 'product_tmpl_id': product_template.id,
'value_ids': [(6, 0, product_attribute_values.filtered(
lambda product_attribute_value: product_attribute_value.attribute_id == product_attribute
).ids)]
} for product_attribute in product_attributes])
- self.env.ref("product.product_product_4").update({
- 'attribute_line_ids': [(4, product_template_attribute_line.id) for product_template_attribute_line in product_template_attribute_lines]
- })
+ product_template.create_variant_ids()
self.start_tour("/web", 'sale_product_configurator_advanced_tour', login="admin")
@@ -106,15 +106,15 @@ class TestUi(odoo.tests.HttpCase):
'attribute_id': product_attributes[0].id
}])
- product_template_attribute_lines = self.env['product.template.attribute.line'].create([{
+ product_template = self.env.ref("product.product_product_4_product_template")
+
+ self.env['product.template.attribute.line'].create([{
'attribute_id': product_attributes[0].id,
- 'product_tmpl_id': self.env.ref("product.product_product_4").id,
+ 'product_tmpl_id': product_template.id,
'value_ids': [(6, 0, [product_attribute_values[0].id])]
}])
- self.env.ref("product.product_product_4").update({
- 'attribute_line_ids': [(4, product_template_attribute_lines[0].id)]
- })
+ product_template.create_variant_ids()
self.start_tour("/web", 'sale_product_configurator_single_custom_attribute_tour', login="admin")
diff --git a/addons/stock_account/tests/test_anglo_saxon_valuation_reconciliation_common.py b/addons/stock_account/tests/test_anglo_saxon_valuation_reconciliation_common.py
index 0db00180504..4da2c2365d6 100644
--- a/addons/stock_account/tests/test_anglo_saxon_valuation_reconciliation_common.py
+++ b/addons/stock_account/tests/test_anglo_saxon_valuation_reconciliation_common.py
@@ -102,15 +102,15 @@ class ValuationReconciliationTestCase(AccountingTestCase):
'uom_po_id': uom.id,
})
- self.test_product_order = self.env['product.product'].create({
+ self.test_product_order = test_product_order_inv_template.product_variant_id
+ self.test_product_order.write({
'name': 'The chocolate moose - order',
- 'product_tmpl_id': test_product_order_inv_template.id,
'standard_price': 42.0,
})
- self.test_product_delivery = self.env['product.product'].create({
+ self.test_product_delivery = test_product_delivery_inv_template.product_variant_id
+ self.test_product_delivery.write({
'name': 'The chocolate moose - delivery',
- 'product_tmpl_id': test_product_delivery_inv_template.id,
'standard_price': 42.0,
})
diff --git a/addons/website_sale/data/demo.xml b/addons/website_sale/data/demo.xml
index 216c6d38c33..d8eeb7ec088 100644
--- a/addons/website_sale/data/demo.xml
+++ b/addons/website_sale/data/demo.xml
@@ -632,10 +632,8 @@
<!-- action_confirm for confirmation date -->
<function model="sale.order" name="action_confirm" eval="[[ref('website_sale_order_14')]]"/>
- <!-- Moved from deleted module "website_sale_option" -->
- <record id="product_product_1" model="product.product">
+ <record id="product_product_1_product_template" model="product.template">
<field name="name">Warranty</field>
- <field name="default_code">SERV_125889</field>
<field name="list_price">20.0</field>
<field name="website_sequence">9980</field>
<field name="website_published" eval="True"/>
@@ -643,18 +641,26 @@
<field name="uom_id" ref="uom.product_uom_unit"/>
<field name="uom_po_id" ref="uom.product_uom_unit"/>
<field name="description_sale">Warranty, issued to the purchaser of an article by its manufacturer, promising to repair or replace it if necessary within a specified period of time.</field>
- <field name="attribute_value_ids" eval="[(6,0,[ref('product.product_attribute_value_5')])]"/>
<field name="categ_id" ref="product.product_category_3"/>
<field name="invoice_policy">delivery</field>
+ <field name="public_categ_ids" eval="[(6, 0, [ref('website_sale.services')])]"/>
</record>
+
<record id="product_template_attribute_line_1" model="product.template.attribute.line">
- <field name="product_tmpl_id" ref="product_product_1_product_template"/>
+ <field name="product_tmpl_id" ref="website_sale.product_product_1_product_template"/>
<field name="attribute_id" ref="product.product_attribute_3"/>
<field name="value_ids" eval="[(6,0,[ref('product.product_attribute_value_5'), ref('product.product_attribute_value_6')])]"/>
</record>
- <record id="product_product_1_product_template" model="product.template">
- <field name="attribute_line_ids" eval="[(6,0,[ref('product_template_attribute_line_1')])]"/>
- <field name="public_categ_ids" eval="[(6,0,[ref('website_sale.services')])]"/>
+
+ <record id="product_product_1" model="product.product">
+ <field name="default_code">SERV_125889</field>
+ <field name="product_tmpl_id" ref="website_sale.product_product_1_product_template"/>
+ <field name="attribute_value_ids" eval="[(6, 0, [ref('product.product_attribute_value_5')])]"/>
+ </record>
+ <record id="product_product_1b" model="product.product">
+ <field name="default_code">SERV_125890</field>
+ <field name="product_tmpl_id" ref="website_sale.product_product_1_product_template"/>
+ <field name="attribute_value_ids" eval="[(6, 0, [ref('product.product_attribute_value_6')])]"/>
</record>
<!-- Handle automatically created product.template.attribute.value -->