Skip to content

Commit

Permalink
[MIG] product_secondary_unit: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pfranck committed Nov 13, 2024
1 parent 56e5e97 commit fff893c
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 17 deletions.
20 changes: 10 additions & 10 deletions product_secondary_unit/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Product Secondary Unit
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproduct--attribute-lightgray.png?logo=github
:target: https://github.com/OCA/product-attribute/tree/17.0/product_secondary_unit
:target: https://github.com/OCA/product-attribute/tree/18.0/product_secondary_unit
:alt: OCA/product-attribute
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/product-attribute-17-0/product-attribute-17-0-product_secondary_unit
:target: https://translation.odoo-community.org/projects/product-attribute-18-0/product-attribute-18-0-product_secondary_unit
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/product-attribute&target_branch=17.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/product-attribute&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -51,7 +51,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/product-attribute/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/product-attribute/issues/new?body=module:%20product_secondary_unit%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/product-attribute/issues/new?body=module:%20product_secondary_unit%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand All @@ -66,11 +66,11 @@ Authors
Contributors
------------

- Carlos Dauden <carlos.dauden@tecnativa.com>
- Sergio Teruel <sergio.teruel@tecnativa.com>
- Kitti Upariphutthiphong <kittiu@ecosoft.co.th>
- Pimolnat Suntian <pimolnats@ecosoft.co.th>
- Alan Ramos <alan.ramos@jarsa.com.mx>
- Carlos Dauden <carlos.dauden@tecnativa.com>
- Sergio Teruel <sergio.teruel@tecnativa.com>
- Kitti Upariphutthiphong <kittiu@ecosoft.co.th>
- Pimolnat Suntian <pimolnats@ecosoft.co.th>
- Alan Ramos <alan.ramos@jarsa.com.mx>

Maintainers
-----------
Expand All @@ -93,6 +93,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-sergio-teruel|

This module is part of the `OCA/product-attribute <https://github.com/OCA/product-attribute/tree/17.0/product_secondary_unit>`_ project on GitHub.
This module is part of the `OCA/product-attribute <https://github.com/OCA/product-attribute/tree/18.0/product_secondary_unit>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion product_secondary_unit/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "Product Secondary Unit",
"summary": "Set a secondary unit per product",
"version": "17.0.1.0.0",
"version": "18.0.1.0.0",
"development_status": "Production/Stable",
"category": "Product",
"website": "https://github.com/OCA/product-attribute",
Expand Down
6 changes: 3 additions & 3 deletions product_secondary_unit/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ <h1 class="title">Product Secondary Unit</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:3038be23ebd37dd87f7595ccf86308fa611b0a81df5134e31c81d12bb79f3f84
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/product-attribute/tree/17.0/product_secondary_unit"><img alt="OCA/product-attribute" src="https://img.shields.io/badge/github-OCA%2Fproduct--attribute-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/product-attribute-17-0/product-attribute-17-0-product_secondary_unit"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/product-attribute&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/product-attribute/tree/18.0/product_secondary_unit"><img alt="OCA/product-attribute" src="https://img.shields.io/badge/github-OCA%2Fproduct--attribute-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/product-attribute-18-0/product-attribute-18-0-product_secondary_unit"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/product-attribute&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module extends the functionality of product module to allow define
other units with their conversion factor.</p>
<p><strong>Table of contents</strong></p>
Expand Down Expand Up @@ -399,7 +399,7 @@ <h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/product-attribute/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/product-attribute/issues/new?body=module:%20product_secondary_unit%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/product-attribute/issues/new?body=module:%20product_secondary_unit%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand Down Expand Up @@ -431,7 +431,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/sergio-teruel"><img alt="sergio-teruel" src="https://github.com/sergio-teruel.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/product-attribute/tree/17.0/product_secondary_unit">OCA/product-attribute</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/product-attribute/tree/18.0/product_secondary_unit">OCA/product-attribute</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
88 changes: 88 additions & 0 deletions product_secondary_unit/tests/test_product_second_unit.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright 2018 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.fields import Command
from odoo.tests import TransactionCase, tagged


Expand Down Expand Up @@ -39,9 +40,69 @@ def setUpClass(cls):
],
}
)
cls.woods = cls.env["product.template"].create(
{
"name": "Piece of woods",
"list_price": 2000,
"uom_id": cls.product_uom_kg.id,
"uom_po_id": cls.product_uom_kg.id,
"secondary_uom_ids": [
(
0,
0,
{
"code": "A",
"name": "unit-700",
"uom_id": cls.product_uom_unit.id,
"factor": 0.7,
},
),
(
0,
0,
{
"code": "B",
"name": "unit-900",
"uom_id": cls.product_uom_unit.id,
"factor": 0.9,
},
),
],
}
)
cls.secondary_unit = cls.env["product.secondary.unit"].search(
[("product_tmpl_id", "=", cls.product.id)], limit=1
)
cls.densitiy = cls.env["product.attribute"].create(
[
{
"name": "Density",
"sequence": 1,
"value_ids": [
Command.create(
{
"name": "Low",
"sequence": 1,
}
),
Command.create(
{
"name": "Heavy",
"sequence": 2,
}
),
],
}
]
)
cls.low, cls.heavy = cls.densitiy.value_ids
cls.density_attribute_lines = cls.env["product.template.attribute.line"].create(
{
"product_tmpl_id": cls.woods.id,
"attribute_id": cls.densitiy.id,
"value_ids": [Command.set([cls.low.id, cls.heavy.id])],
}
)

def test_product_secondary_unit_name(self):
self.assertEqual(self.secondary_unit.name_get()[0][1], "unit-700-0.7")
Expand All @@ -58,3 +119,30 @@ def test_product_secondary_unit_search(self):
self.assertEqual(len(name_get), 1)
name_get = self.env["product.secondary.unit"].name_search(name="X", args=args)
self.assertEqual(len(name_get), 0)

def test_multi_variant_product_secondary_unit(self):
first_variant = self.woods.product_variant_ids[0]
second_variant = self.woods.product_variant_ids[2]
self.assertEqual(len(self.woods.secondary_uom_ids), 2)
self.assertEqual(first_variant.secondary_uom_ids, self.woods.secondary_uom_ids)

first_variant.write(
{
"secondary_uom_ids": [
(
0,
0,
{
"code": "C",
"name": "unit-1000",
"product_id": first_variant.id,
"uom_id": self.product_uom_unit.id,
"factor": 0.1,
},
),
]
}
)
self.assertEqual(len(self.woods.secondary_uom_ids), 3)
self.assertEqual(len(first_variant.secondary_uom_ids), 2)
self.assertEqual(len(second_variant.secondary_uom_ids), 3)
27 changes: 27 additions & 0 deletions product_secondary_unit/tests/test_secondary_unit_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,23 @@ def setUpClass(cls):
"factor": 10,
},
),
(
0,
0,
{
"code": "C20",
"name": "box 20",
"dependency_type": "independent",
"uom_id": cls.product_uom_unit.id,
"factor": 20,
},
),
],
}
)
cls.secondary_unit_box_5 = cls.product_template.secondary_uom_ids[0]
cls.secondary_unit_box_10 = cls.product_template.secondary_uom_ids[1]
cls.secondary_unit_box_20 = cls.product_template.secondary_uom_ids[2]
# Fake model which inherit from
cls.secondary_unit_fake = cls.env["secondary.unit.fake"].create(
{
Expand Down Expand Up @@ -87,6 +99,21 @@ def test_product_secondary_unit_mixin(self):
fake_model._onchange_helper_product_uom_for_secondary()
self.assertEqual(fake_model.secondary_uom_qty, 12)

def test_product_secondary_unit_independent_mixin(self):
fake_model = self.secondary_unit_fake
fake_model.write(
{
"product_uom_qty": 20,
"secondary_uom_qty": 1,
"secondary_uom_id": self.secondary_unit_box_20.id,
}
)
self.assertEqual(fake_model.product_uom_qty, 20)
fake_model.invalidate_recordset()
fake_model.product_uom_id = self.product_uom_dozen
fake_model._onchange_helper_product_uom_for_secondary()
self.assertEqual(fake_model.secondary_uom_qty, 1)

def test_product_secondary_unit_mixin_no_uom(self):
# If secondary_uom_id is not informed product_qty on target model is
# not computed.
Expand Down
6 changes: 3 additions & 3 deletions product_secondary_unit/views/product_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
groups="uom.group_uom"
>
<field name="secondary_uom_ids" colspan="4" nolabel="1">
<tree editable="bottom" decoration-muted="(not active)">
<list editable="bottom" decoration-muted="(not active)">
<field name="active" widget="boolean_toggle" />
<field name="product_tmpl_id" column_invisible="1" />
<field
Expand All @@ -32,7 +32,7 @@
<field name="uom_id" />
<field name="factor" />
<field name="dependency_type" />
</tree>
</list>
</field>
</group>
</xpath>
Expand All @@ -45,7 +45,7 @@
<field name="inherit_id" ref="product.product_normal_form_view" />
<field name="arch" type="xml">
<xpath
expr="//field[@name='secondary_uom_ids']/tree/field[@name='product_id']"
expr="//field[@name='secondary_uom_ids']/list/field[@name='product_id']"
position="attributes"
>
<attribute name="domain">[('id', '=', parent.id)]</attribute>
Expand Down
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
odoo_test_helper

0 comments on commit fff893c

Please sign in to comment.