Skip to content

Commit

Permalink
[MIG] sale_order_secondary_unit: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-pelykh committed Jun 24, 2024
1 parent 84693c3 commit 221c07c
Show file tree
Hide file tree
Showing 14 changed files with 151 additions and 132 deletions.
14 changes: 9 additions & 5 deletions sale_order_secondary_unit/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Sale Order 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%2Fsale--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/sale-workflow/tree/15.0/sale_order_secondary_unit
:target: https://github.com/OCA/sale-workflow/tree/16.0/sale_order_secondary_unit
:alt: OCA/sale-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/sale-workflow-15-0/sale-workflow-15-0-sale_order_secondary_unit
:target: https://translation.odoo-community.org/projects/sale-workflow-16-0/sale-workflow-16-0-sale_order_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/sale-workflow&target_branch=15.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -61,7 +61,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-workflow/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/sale-workflow/issues/new?body=module:%20sale_order_secondary_unit%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/sale-workflow/issues/new?body=module:%20sale_order_secondary_unit%0Aversion:%2016.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 @@ -86,6 +86,10 @@ Contributors
* Ernesto Tejeda
* Pedro M. Baeza

* `CorporateHub <https://corporatehub.eu/>`__

* Alexey Pelykh <[email protected]>

Maintainers
~~~~~~~~~~~

Expand All @@ -99,6 +103,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/sale-workflow <https://github.com/OCA/sale-workflow/tree/15.0/sale_order_secondary_unit>`_ project on GitHub.
This module is part of the `OCA/sale-workflow <https://github.com/OCA/sale-workflow/tree/16.0/sale_order_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 sale_order_secondary_unit/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "Sale Order Secondary Unit",
"summary": "Sale product in a secondary unit",
"version": "15.0.2.1.0",
"version": "16.0.1.0.0",
"development_status": "Production/Stable",
"category": "Sale",
"website": "https://github.com/OCA/sale-workflow",
Expand Down
2 changes: 1 addition & 1 deletion sale_order_secondary_unit/i18n/de.po
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ msgid "-&gt;"
msgstr ""

#. module: sale_order_secondary_unit
#: model:ir.model.fields,field_description:sale_order_secondary_unit.field_sale_order_line__secondary_uom_unit_price
#: model:ir.model.fields,field_description:sale_order_secondary_unit.field_sale_order_line__secondary_uom_price_unit
msgid "2nd unit price"
msgstr ""

Expand Down
2 changes: 1 addition & 1 deletion sale_order_secondary_unit/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ msgid "-&gt;"
msgstr "-&gt;"

#. module: sale_order_secondary_unit
#: model:ir.model.fields,field_description:sale_order_secondary_unit.field_sale_order_line__secondary_uom_unit_price
#: model:ir.model.fields,field_description:sale_order_secondary_unit.field_sale_order_line__secondary_uom_price_unit
msgid "2nd unit price"
msgstr "Precio de la 2ª unidad"

Expand Down
2 changes: 1 addition & 1 deletion sale_order_secondary_unit/i18n/fi.po
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ msgid "-&gt;"
msgstr ""

#. module: sale_order_secondary_unit
#: model:ir.model.fields,field_description:sale_order_secondary_unit.field_sale_order_line__secondary_uom_unit_price
#: model:ir.model.fields,field_description:sale_order_secondary_unit.field_sale_order_line__secondary_uom_price_unit
msgid "2nd unit price"
msgstr "2. Yksikköhinta"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ msgid "-&gt;"
msgstr ""

#. module: sale_order_secondary_unit
#: model:ir.model.fields,field_description:sale_order_secondary_unit.field_sale_order_line__secondary_uom_unit_price
#: model:ir.model.fields,field_description:sale_order_secondary_unit.field_sale_order_line__secondary_uom_price_unit
msgid "2nd unit price"
msgstr ""

Expand Down
2 changes: 1 addition & 1 deletion sale_order_secondary_unit/i18n/zh_CN.po
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ msgid "-&gt;"
msgstr ""

#. module: sale_order_secondary_unit
#: model:ir.model.fields,field_description:sale_order_secondary_unit.field_sale_order_line__secondary_uom_unit_price
#: model:ir.model.fields,field_description:sale_order_secondary_unit.field_sale_order_line__secondary_uom_price_unit
msgid "2nd unit price"
msgstr ""

Expand Down
17 changes: 0 additions & 17 deletions sale_order_secondary_unit/migrations/15.0.2.0.0/post-migration.py

This file was deleted.

57 changes: 25 additions & 32 deletions sale_order_secondary_unit/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2018-2020 Tecnativa - Carlos Dauden
# Copyright 2024 CorporateHub
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models

Expand All @@ -11,52 +12,44 @@ class SaleOrderLine(models.Model):
"uom_field": "product_uom",
}

secondary_uom_unit_price = fields.Float(
string="2nd unit price",
secondary_uom_price_unit = fields.Float(
string="Secondary Unit Price",
digits="Product Price",
compute="_compute_secondary_uom_unit_price",
compute="_compute_secondary_uom_price_unit",
store=True,
precompute=True,
)

product_uom_qty = fields.Float(
store=True, readonly=False, compute="_compute_product_uom_qty", copy=True
)

@api.depends("secondary_uom_qty", "secondary_uom_id", "product_uom_qty")
@api.depends("secondary_uom_qty", "secondary_uom_id")
def _compute_product_uom_qty(self):
res = super()._compute_product_uom_qty()
self._compute_helper_target_field_qty()
return res

@api.onchange("product_uom")
def onchange_product_uom_for_secondary(self):
def _onchange_product_uom(self):
self._onchange_helper_product_uom_for_secondary()

@api.onchange("product_id")
def product_id_change(self):
"""
If default sales secondary unit set on product, put on secondary
quantity 1 for being the default quantity. We override this method,
that is the one that sets by default 1 on the other quantity with that
purpose.
"""
res = super().product_id_change()
line_uom_qty = self.product_uom_qty
self.secondary_uom_id = self.product_id.sale_secondary_uom_id
if self.product_id.sale_secondary_uom_id:
if line_uom_qty == 1.0:
self.secondary_uom_qty = 1.0
self.onchange_product_uom_for_secondary()
else:
self.product_uom_qty = line_uom_qty
return res

@api.depends("secondary_uom_qty", "product_uom_qty", "price_unit")
def _compute_secondary_uom_unit_price(self):
def _onchange_product_id(self):
inherited_secondary_uom_id = (
self.product_id.sale_secondary_uom_id
or self.product_id.product_tmpl_id.sale_secondary_uom_id
)
if inherited_secondary_uom_id:
line_uom_qty = self.product_uom_qty
self.secondary_uom_id = inherited_secondary_uom_id
self.product_uom_qty = line_uom_qty

@api.depends("secondary_uom_qty", "product_uom_qty", "price_subtotal")
def _compute_secondary_uom_price_unit(self):
for line in self:
if line.secondary_uom_id:
try:
line.secondary_uom_unit_price = (
line.secondary_uom_price_unit = (
line.price_subtotal / line.secondary_uom_qty
)
except ZeroDivisionError:
line.secondary_uom_unit_price = 0
line.secondary_uom_price_unit = 0

Check warning on line 53 in sale_order_secondary_unit/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_order_secondary_unit/models/sale_order.py#L52-L53

Added lines #L52 - L53 were not covered by tests
else:
line.secondary_uom_unit_price = 0
line.secondary_uom_price_unit = 0
4 changes: 4 additions & 0 deletions sale_order_secondary_unit/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
* Sergio Teruel
* Ernesto Tejeda
* Pedro M. Baeza

* `CorporateHub <https://corporatehub.eu/>`__

* Alexey Pelykh <[email protected]>
10 changes: 7 additions & 3 deletions sale_order_secondary_unit/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ <h1 class="title">Sale Order Secondary Unit</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:d870b4aa2365687416065e0cd5aef2754fc39659c2bef870bbf907d7d5b0cd6c
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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/sale-workflow/tree/15.0/sale_order_secondary_unit"><img alt="OCA/sale-workflow" src="https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/sale-workflow-15-0/sale-workflow-15-0-sale_order_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/sale-workflow&amp;target_branch=15.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/sale-workflow/tree/16.0/sale_order_secondary_unit"><img alt="OCA/sale-workflow" src="https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/sale-workflow-16-0/sale-workflow-16-0-sale_order_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/sale-workflow&amp;target_branch=16.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 sale orders to allow sale products in
secondary unit of distinct category.</p>
<p><strong>Table of contents</strong></p>
Expand Down Expand Up @@ -409,7 +409,7 @@ <h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/sale-workflow/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/sale-workflow/issues/new?body=module:%20sale_order_secondary_unit%0Aversion:%2015.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/sale-workflow/issues/new?body=module:%20sale_order_secondary_unit%0Aversion:%2016.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 All @@ -433,6 +433,10 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<li>Pedro M. Baeza</li>
</ul>
</li>
<li><a class="reference external" href="https://corporatehub.eu/">CorporateHub</a><ul>
<li>Alexey Pelykh &lt;<a class="reference external" href="mailto:alexey.pelykh&#64;corphub.eu">alexey.pelykh&#64;corphub.eu</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand All @@ -442,7 +446,7 @@ <h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/sale-workflow/tree/15.0/sale_order_secondary_unit">OCA/sale-workflow</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/sale-workflow/tree/16.0/sale_order_secondary_unit">OCA/sale-workflow</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
70 changes: 34 additions & 36 deletions sale_order_secondary_unit/tests/test_sale_order_secondary_unit.py
Original file line number Diff line number Diff line change
@@ -1,52 +1,47 @@
# Copyright 2018-2020 Tecnativa - Carlos Dauden
# Copyright 2024 CorporateHub
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.fields import Command
from odoo.tests import Form, TransactionCase, tagged

from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT


@tagged("post_install", "-at_install")
class TestSaleOrderSecondaryUnit(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
# Remove this variable in v16 and put instead:
# from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT
DISABLED_MAIL_CONTEXT = {
"tracking_disable": True,
"mail_create_nolog": True,
"mail_create_nosubscribe": True,
"mail_notrack": True,
"no_reset_password": True,
}
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))
cls.product_uom_kg = cls.env.ref("uom.product_uom_kgm")
cls.product_uom_gram = cls.env.ref("uom.product_uom_gram")
cls.product_uom_unit = cls.env.ref("uom.product_uom_unit")
cls.price_list = cls.env["product.pricelist"].create(
{"name": "price list for test"}
)
cls.product = cls.env["product.product"].create(
{
"name": "test",
"list_price": 1000.00,
"uom_id": cls.product_uom_kg.id,
"uom_po_id": cls.product_uom_kg.id,
}
)
# Set secondary uom on product template
cls.product.product_tmpl_id.write(
{
"secondary_uom_ids": [
(
0,
0,
Command.create(
{
"name": "unit-500",
"uom_id": cls.product_uom_unit.id,
"factor": 0.5,
},
}
)
],
}
)
cls.price_list = cls.env["product.pricelist"].create(
{
"name": "price list for test",
}
)
cls.secondary_unit = cls.env["product.secondary.unit"].search(
[("product_tmpl_id", "=", cls.product.product_tmpl_id.id)]
)
Expand All @@ -58,28 +53,21 @@ def setUpClass(cls):
with order_form.order_line.new() as line_form:
line_form.product_id = cls.product
line_form.product_uom_qty = 1
line_form.price_unit = 1000.00
cls.order = order_form.save()

def test_onchange_secondary_uom(self):
def test_compute_product_uom_qty(self):
self.order.order_line.write(
{"secondary_uom_id": self.secondary_unit.id, "secondary_uom_qty": 5}
)
self.order.order_line._compute_product_uom_qty()
self.assertEqual(self.order.order_line.product_uom_qty, 2.5)

def test_onchange_secondary_unit_product_uom_qty(self):
self.order.order_line.update(
def test_compute_secondary_uom_qty(self):
self.order.order_line.write(
{"secondary_uom_id": self.secondary_unit.id, "product_uom_qty": 3.5}
)
self.assertEqual(self.order.order_line.secondary_uom_qty, 7.0)

def test_default_secondary_unit(self):
self.order.order_line.product_id_change()
self.assertEqual(self.order.order_line.secondary_uom_id, self.secondary_unit)

def test_onchange_order_product_uom(self):
self.order.order_line.update(
self.order.order_line.write(
{
"secondary_uom_id": self.secondary_unit.id,
"product_uom": self.product_uom_gram.id,
Expand All @@ -88,6 +76,10 @@ def test_onchange_order_product_uom(self):
)
self.assertEqual(self.order.order_line.secondary_uom_qty, 7.0)

def test_default_secondary_unit(self):
self.order.order_line._onchange_product_id()
self.assertEqual(self.order.order_line.secondary_uom_id, self.secondary_unit)

def test_independent_type(self):
# dependent type is already tested as dependency_type by default
self.order.order_line.secondary_uom_id = self.secondary_unit.id
Expand All @@ -103,18 +95,24 @@ def test_independent_type(self):
self.assertEqual(self.order.order_line.secondary_uom_qty, 2)
self.assertEqual(self.order.order_line.product_uom_qty, 17)

def test_secondary_uom_unit_price(self):
# Remove secondary uom in sale line to do a complete test of secondary price
def test_secondary_uom_price_unit(self):
self.order.order_line.secondary_uom_id = False
self.assertEqual(self.order.order_line.secondary_uom_unit_price, 0)
self.order.order_line.update(
self.assertEqual(self.order.order_line.product_uom_qty, 1)
self.assertEqual(self.order.order_line.price_unit, 1000)
self.assertEqual(self.order.order_line.price_subtotal, 1000)
self.assertEqual(self.order.order_line.secondary_uom_qty, 0)
self.assertEqual(self.order.order_line.secondary_uom_price_unit, 0)

self.order.order_line.write(
{"secondary_uom_id": self.secondary_unit.id, "product_uom_qty": 2}
)

self.assertEqual(self.order.order_line.product_uom_qty, 2)
self.assertEqual(self.order.order_line.price_unit, 1000)
self.assertEqual(self.order.order_line.price_subtotal, 2000)
self.assertEqual(self.order.order_line.secondary_uom_qty, 4)
self.assertEqual(self.order.order_line.secondary_uom_unit_price, 500)
self.assertEqual(self.order.order_line.secondary_uom_price_unit, 500)

self.order.order_line.write({"product_uom_qty": 8})
self.assertEqual(self.order.order_line.secondary_uom_qty, 16)
self.assertEqual(self.order.order_line.secondary_uom_unit_price, 500)
self.assertEqual(self.order.order_line.price_subtotal, 8000)
self.assertEqual(self.order.order_line.secondary_uom_qty, 16)
self.assertEqual(self.order.order_line.secondary_uom_price_unit, 500)
Loading

0 comments on commit 221c07c

Please sign in to comment.