[REF] product_origin_char: simplify to template-based origin
- Move origin_text field from product.supplierinfo to product.template - Add related field in product.product for variant access - Remove dependency on product_main_seller - Update views to show field near category (editable) - Rewrite tests for new architecture - Update all documentation (README, readme/ fragments) - Bump version to 18.0.2.0.0
This commit is contained in:
parent
e2ced75ecd
commit
5efe57dc19
15 changed files with 180 additions and 402 deletions
|
|
@ -5,190 +5,71 @@ from odoo.tests.common import TransactionCase
|
|||
|
||||
|
||||
class TestProductOriginChar(TransactionCase):
|
||||
"""Test cases for product_origin_char module.
|
||||
|
||||
This module adds a simple origin_text field to product.template
|
||||
with a related field in product.product for variant access.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
|
||||
|
||||
# Create test suppliers
|
||||
cls.supplier_1 = cls.env["res.partner"].create(
|
||||
{
|
||||
"name": "Supplier 1",
|
||||
"is_company": True,
|
||||
}
|
||||
)
|
||||
cls.supplier_2 = cls.env["res.partner"].create(
|
||||
{
|
||||
"name": "Supplier 2",
|
||||
"is_company": True,
|
||||
}
|
||||
)
|
||||
|
||||
# Create test product
|
||||
cls.product = cls.env["product.product"].create(
|
||||
# Create test product template
|
||||
cls.product_tmpl = cls.env["product.template"].create(
|
||||
{
|
||||
"name": "Test Product",
|
||||
"type": "consu",
|
||||
}
|
||||
)
|
||||
cls.product = cls.product_tmpl.product_variant_ids[0]
|
||||
|
||||
def test_01_origin_text_in_supplierinfo(self):
|
||||
"""Test that origin_text can be set in supplierinfo"""
|
||||
supplierinfo = self.env["product.supplierinfo"].create(
|
||||
{
|
||||
"partner_id": self.supplier_1.id,
|
||||
"product_tmpl_id": self.product.product_tmpl_id.id,
|
||||
"origin_text": "Valencia, Spain",
|
||||
}
|
||||
)
|
||||
self.assertEqual(supplierinfo.origin_text, "Valencia, Spain")
|
||||
def test_01_origin_text_in_template(self):
|
||||
"""Test that origin_text can be set in product.template"""
|
||||
self.product_tmpl.origin_text = "Valencia, Spain"
|
||||
self.assertEqual(self.product_tmpl.origin_text, "Valencia, Spain")
|
||||
|
||||
def test_02_origin_from_main_seller(self):
|
||||
"""Test that product shows origin from main seller"""
|
||||
# Create supplierinfo for supplier 1 (will be main seller)
|
||||
self.env["product.supplierinfo"].create(
|
||||
{
|
||||
"partner_id": self.supplier_1.id,
|
||||
"product_tmpl_id": self.product.product_tmpl_id.id,
|
||||
"sequence": 1,
|
||||
"origin_text": "Valencia, Spain",
|
||||
}
|
||||
)
|
||||
|
||||
# Verify main seller is supplier 1
|
||||
self.product.product_tmpl_id.invalidate_recordset()
|
||||
self.assertEqual(self.product.product_tmpl_id.main_seller_id, self.supplier_1)
|
||||
|
||||
# Verify origin_text on product matches supplier 1's origin
|
||||
self.product.invalidate_recordset()
|
||||
self.assertEqual(self.product.origin_text, "Valencia, Spain")
|
||||
self.assertEqual(self.product.product_tmpl_id.origin_text, "Valencia, Spain")
|
||||
|
||||
def test_03_origin_updates_with_main_seller_change(self):
|
||||
"""Test that origin updates when main seller changes"""
|
||||
# Create supplierinfo for both suppliers
|
||||
supplier1_info = self.env["product.supplierinfo"].create(
|
||||
{
|
||||
"partner_id": self.supplier_1.id,
|
||||
"product_tmpl_id": self.product.product_tmpl_id.id,
|
||||
"sequence": 1,
|
||||
"origin_text": "Valencia, Spain",
|
||||
}
|
||||
)
|
||||
supplier2_info = self.env["product.supplierinfo"].create(
|
||||
{
|
||||
"partner_id": self.supplier_2.id,
|
||||
"product_tmpl_id": self.product.product_tmpl_id.id,
|
||||
"sequence": 2,
|
||||
"origin_text": "Aragón, Spain",
|
||||
}
|
||||
)
|
||||
|
||||
# Initially, main seller is supplier 1
|
||||
self.product.product_tmpl_id.invalidate_recordset()
|
||||
self.assertEqual(self.product.product_tmpl_id.main_seller_id, self.supplier_1)
|
||||
self.product.invalidate_recordset()
|
||||
self.assertEqual(self.product.origin_text, "Valencia, Spain")
|
||||
|
||||
# Change main seller by swapping sequences
|
||||
supplier1_info.sequence = 2
|
||||
supplier2_info.sequence = 1
|
||||
|
||||
# Verify main seller is now supplier 2
|
||||
self.product.product_tmpl_id.invalidate_recordset()
|
||||
self.assertEqual(self.product.product_tmpl_id.main_seller_id, self.supplier_2)
|
||||
|
||||
# Verify origin_text updated to supplier 2's origin
|
||||
self.product.invalidate_recordset()
|
||||
def test_02_origin_text_in_product_related(self):
|
||||
"""Test that product.product has related access to origin_text"""
|
||||
self.product_tmpl.origin_text = "Aragón, Spain"
|
||||
# Variant should show template's origin via related field
|
||||
self.assertEqual(self.product.origin_text, "Aragón, Spain")
|
||||
|
||||
def test_04_empty_origin_without_supplier(self):
|
||||
"""Test that product without suppliers has no origin"""
|
||||
# Create product without suppliers
|
||||
product_no_supplier = self.env["product.product"].create(
|
||||
def test_03_origin_text_write_from_variant(self):
|
||||
"""Test that origin_text can be written from variant (readonly=False)"""
|
||||
self.product.origin_text = "Basque Country"
|
||||
# Should update the template
|
||||
self.assertEqual(self.product_tmpl.origin_text, "Basque Country")
|
||||
|
||||
def test_04_empty_origin(self):
|
||||
"""Test that origin_text defaults to False/empty"""
|
||||
new_product = self.env["product.product"].create(
|
||||
{
|
||||
"name": "Product Without Supplier",
|
||||
"name": "Product Without Origin",
|
||||
"type": "consu",
|
||||
}
|
||||
)
|
||||
self.assertFalse(new_product.origin_text)
|
||||
self.assertFalse(new_product.product_tmpl_id.origin_text)
|
||||
|
||||
# Verify no main seller and no origin
|
||||
self.assertFalse(product_no_supplier.product_tmpl_id.main_seller_id)
|
||||
self.assertFalse(product_no_supplier.origin_text)
|
||||
|
||||
def test_05_empty_origin_with_supplier_no_text(self):
|
||||
"""Test that supplier without origin_text shows False"""
|
||||
# Create supplierinfo without origin_text
|
||||
self.env["product.supplierinfo"].create(
|
||||
{
|
||||
"partner_id": self.supplier_1.id,
|
||||
"product_tmpl_id": self.product.product_tmpl_id.id,
|
||||
"sequence": 1,
|
||||
# No origin_text set
|
||||
}
|
||||
)
|
||||
|
||||
# Verify main seller exists but origin is False
|
||||
self.product.product_tmpl_id.invalidate_recordset()
|
||||
self.assertEqual(self.product.product_tmpl_id.main_seller_id, self.supplier_1)
|
||||
self.product.invalidate_recordset()
|
||||
self.assertFalse(self.product.origin_text)
|
||||
|
||||
def test_06_translation_support(self):
|
||||
"""Test that origin_text field is translatable"""
|
||||
# Create supplierinfo with origin in default language
|
||||
supplierinfo = self.env["product.supplierinfo"].create(
|
||||
{
|
||||
"partner_id": self.supplier_1.id,
|
||||
"product_tmpl_id": self.product.product_tmpl_id.id,
|
||||
"origin_text": "Valencia, Spain",
|
||||
}
|
||||
)
|
||||
|
||||
# Verify field has translate=True attribute
|
||||
field = self.env["product.supplierinfo"]._fields["origin_text"]
|
||||
self.assertTrue(field.translate)
|
||||
|
||||
# Test that we can set translation (requires lang to be installed)
|
||||
# This is a basic check - full translation testing would require
|
||||
# installing multiple languages
|
||||
self.assertEqual(supplierinfo.origin_text, "Valencia, Spain")
|
||||
|
||||
def test_07_multiple_products_same_supplier(self):
|
||||
"""Test that different products can have different origins from same supplier"""
|
||||
product2 = self.env["product.product"].create(
|
||||
def test_05_multiple_products_independent_origins(self):
|
||||
"""Test that different products have independent origins"""
|
||||
product2_tmpl = self.env["product.template"].create(
|
||||
{
|
||||
"name": "Test Product 2",
|
||||
"type": "consu",
|
||||
}
|
||||
)
|
||||
|
||||
# Create supplierinfo for product 1
|
||||
self.env["product.supplierinfo"].create(
|
||||
{
|
||||
"partner_id": self.supplier_1.id,
|
||||
"product_tmpl_id": self.product.product_tmpl_id.id,
|
||||
"origin_text": "Valencia, Spain",
|
||||
}
|
||||
)
|
||||
self.product_tmpl.origin_text = "Valencia, Spain"
|
||||
product2_tmpl.origin_text = "Aragón, Spain"
|
||||
|
||||
# Create supplierinfo for product 2 with same supplier but different origin
|
||||
self.env["product.supplierinfo"].create(
|
||||
{
|
||||
"partner_id": self.supplier_1.id,
|
||||
"product_tmpl_id": product2.product_tmpl_id.id,
|
||||
"origin_text": "Aragón, Spain",
|
||||
}
|
||||
)
|
||||
self.assertEqual(self.product_tmpl.origin_text, "Valencia, Spain")
|
||||
self.assertEqual(product2_tmpl.origin_text, "Aragón, Spain")
|
||||
|
||||
# Verify each product has its own origin
|
||||
self.product.invalidate_recordset()
|
||||
product2.invalidate_recordset()
|
||||
self.assertEqual(self.product.origin_text, "Valencia, Spain")
|
||||
self.assertEqual(product2.origin_text, "Aragón, Spain")
|
||||
|
||||
def test_08_product_variant_level(self):
|
||||
"""Test that origin_text works at product variant level"""
|
||||
def test_06_product_variants_share_origin(self):
|
||||
"""Test that all variants of a template share the same origin"""
|
||||
# Create product template with variants
|
||||
product_attr = self.env["product.attribute"].create({"name": "Color"})
|
||||
attr_value_red = self.env["product.attribute.value"].create(
|
||||
|
|
@ -217,17 +98,49 @@ class TestProductOriginChar(TransactionCase):
|
|||
}
|
||||
)
|
||||
|
||||
# Create supplierinfo at template level
|
||||
self.env["product.supplierinfo"].create(
|
||||
# Set origin on template
|
||||
product_tmpl.origin_text = "Test Origin"
|
||||
|
||||
# Verify all variants show the same origin
|
||||
for variant in product_tmpl.product_variant_ids:
|
||||
self.assertEqual(variant.origin_text, "Test Origin")
|
||||
|
||||
def test_07_origin_update_propagates_to_variants(self):
|
||||
"""Test that updating template origin updates all variants"""
|
||||
# Create product with variants
|
||||
product_attr = self.env["product.attribute"].create({"name": "Size"})
|
||||
attr_value_s = self.env["product.attribute.value"].create(
|
||||
{"name": "S", "attribute_id": product_attr.id}
|
||||
)
|
||||
attr_value_m = self.env["product.attribute.value"].create(
|
||||
{"name": "M", "attribute_id": product_attr.id}
|
||||
)
|
||||
|
||||
product_tmpl = self.env["product.template"].create(
|
||||
{
|
||||
"partner_id": self.supplier_1.id,
|
||||
"product_tmpl_id": product_tmpl.id,
|
||||
"origin_text": "Test Origin",
|
||||
"name": "Sized Product",
|
||||
"type": "consu",
|
||||
"origin_text": "Original Origin",
|
||||
"attribute_line_ids": [
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"attribute_id": product_attr.id,
|
||||
"value_ids": [(6, 0, [attr_value_s.id, attr_value_m.id])],
|
||||
},
|
||||
)
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
# Verify all variants show the same origin (from template level)
|
||||
product_tmpl.invalidate_recordset()
|
||||
# Verify initial origin
|
||||
for variant in product_tmpl.product_variant_ids:
|
||||
variant.invalidate_recordset()
|
||||
self.assertEqual(variant.origin_text, "Test Origin")
|
||||
self.assertEqual(variant.origin_text, "Original Origin")
|
||||
|
||||
# Update origin on template
|
||||
product_tmpl.origin_text = "Updated Origin"
|
||||
|
||||
# Verify all variants show updated origin
|
||||
for variant in product_tmpl.product_variant_ids:
|
||||
self.assertEqual(variant.origin_text, "Updated Origin")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue