Skip to content

Commit

Permalink
[MIG] product_variant_specific_description: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
BhaveshHeliconia committed Feb 6, 2025
1 parent 7870274 commit 1c6a7f5
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 13 deletions.
3 changes: 3 additions & 0 deletions product_variant_specific_description/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ Contributors
------------

- Lois Rilo <[email protected]>
- `Heliconia Solutions Pvt. Ltd. <https://www.heliconia.io>`__

- Bhavesh Heliconia

Maintainers
-----------
Expand Down
2 changes: 1 addition & 1 deletion product_variant_specific_description/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
"name": "Product Variant Specific Description",
"version": "16.0.1.0.1",
"version": "18.0.1.0.0",
"category": "Product",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/product-variant",
Expand Down
4 changes: 2 additions & 2 deletions product_variant_specific_description/init_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
logger = logging.getLogger(__name__)


def post_init_hook(cr, registry):
def post_init_hook(env):
logger.info("Setting product variant description with product template description")
cr.execute(
env.cr.execute(
"""
UPDATE product_product pp
SET description = pt.description
Expand Down
3 changes: 3 additions & 0 deletions product_variant_specific_description/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
- Lois Rilo \<<[email protected]>\>
- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io)
- Bhavesh Heliconia

Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,10 @@ <h2><a class="toc-backref" href="#toc-entry-3">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<ul class="simple">
<li>Lois Rilo &lt;<a class="reference external" href="mailto:lois.rilo&#64;forgeflow.com">lois.rilo&#64;forgeflow.com</a>&gt;</li>
<li><a class="reference external" href="https://www.heliconia.io">Heliconia Solutions Pvt. Ltd.</a><ul>
<li>Bhavesh Heliconia</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
1 change: 1 addition & 0 deletions product_variant_specific_description/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import test_product_variant_description
from . import test_product_template
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from odoo.tests import TransactionCase


class TestProductTemplate(TransactionCase):
def test_is_system_multi_lang(self):
"""
Test case to check if the is_system_multi_lang field is
set correctly based on the system's language count.
"""
product_template = self.env["product.template"].create(
{
"name": "Test Product",
}
)

lang_count = self.env["res.lang"].search_count([])

# Ensure only one language exists, unlink others
if lang_count > 1:
langs = self.env["res.lang"].search([("code", "!=", "en_US")])
langs.unlink()

Check warning on line 21 in product_variant_specific_description/tests/test_product_template.py

View check run for this annotation

Codecov / codecov/patch

product_variant_specific_description/tests/test_product_template.py#L20-L21

Added lines #L20 - L21 were not covered by tests

product_template._compute_is_system_multi_lang()

# Check if the computed value is correct based on language count
if lang_count == 1:
self.assertFalse(
product_template.is_system_multi_lang,
"The is_system_multi_lang field should be False "
"when only one language exists.",
)
else:
self.assertTrue(

Check warning on line 33 in product_variant_specific_description/tests/test_product_template.py

View check run for this annotation

Codecov / codecov/patch

product_variant_specific_description/tests/test_product_template.py#L33

Added line #L33 was not covered by tests
product_template.is_system_multi_lang,
"The is_system_multi_lang field should be True "
"when multiple languages exist.",
)

def test_prepare_variant_values(self):
"""
Test case to check if the description is included when preparing variant values.
"""
product_template = self.env["product.template"].create(
{
"name": "Test Product",
"description": "Product template description",
}
)

# Using correct model
combination = self.env["product.attribute.value"].browse([])

variant_values = product_template._prepare_variant_values(combination)

self.assertEqual(
variant_values.get("description"),
product_template.description,
"The description should be included in the prepared variant values.",
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,14 @@
<field name="inherit_id" ref="product.product_template_only_form_view" />
<field name="arch" type="xml">
<xpath expr="//field[@name='description']/.." position="attributes">
<attribute
name="attrs"
>{'invisible': [('product_variant_count', '>', 1)]}</attribute>
<attribute name="invisible">product_variant_count > 1</attribute>
</xpath>
<xpath expr="//field[@name='description']" position="attributes">
<attribute
name="attrs"
>{'readonly': [('is_system_multi_lang', '=', True)]}</attribute>
<attribute name="readonly">is_system_multi_lang</attribute>
</xpath>
<xpath expr="//field[@name='description']" position="before">
<field name="is_system_multi_lang" invisible="1" />
<p
colspan="2"
attrs="{'invisible': [('is_system_multi_lang', '=', False)]}"
>
<p colspan="2" invisible="is_system_multi_lang">
<i
class="fa fa-info-circle"
/> This field is maintained in the product variant form.
Expand Down

0 comments on commit 1c6a7f5

Please sign in to comment.