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 Mar 16, 2024
1 parent cf5108e commit 744c375
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 94 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
17 changes: 0 additions & 17 deletions sale_order_secondary_unit/migrations/15.0.2.0.0/post-migration.py

This file was deleted.

35 changes: 13 additions & 22 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 @@ -17,36 +18,26 @@ class SaleOrderLine(models.Model):
compute="_compute_secondary_uom_unit_price",
)

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")
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
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_unit")
def _compute_secondary_uom_unit_price(self):
Expand Down
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
25 changes: 12 additions & 13 deletions sale_order_secondary_unit/tests/test_sale_order_secondary_unit.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.tests import Form, TransactionCase, tagged

Expand Down Expand Up @@ -61,25 +62,19 @@ def setUpClass(cls):
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 +83,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 @@ -104,13 +103,13 @@ def test_independent_type(self):
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
self.order.order_line.secondary_uom_id = False
self.assertEqual(self.order.order_line.secondary_uom_qty, 0)
self.assertEqual(self.order.order_line.secondary_uom_unit_price, 0)
self.order.order_line.update(

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

self.assertEqual(self.order.order_line.secondary_uom_qty, 4)
self.assertEqual(self.order.order_line.secondary_uom_unit_price, 500)

Expand Down
14 changes: 10 additions & 4 deletions sale_order_secondary_unit/views/product_views.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2018-2020 Tecnativa - Sergio Teruel
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<!--
Copyright 2018-2020 Tecnativa - Sergio Teruel
Copyright 2024 CorporateHub
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
-->
<odoo>
<record id="product_template_form_view" model="ir.ui.view">
<field name="name">Product template Secondary Unit</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view" />
<field name="groups_id" eval="[(4, ref('uom.group_uom'))]" />
<field name="arch" type="xml">
<field name="uom_id" position="after">
<field name="sale_secondary_uom_id" options="{'no_create': True}" />
<field
name="sale_secondary_uom_id"
groups="uom.group_uom"
options="{'no_create': True}"
/>
</field>
</field>
</record>
Expand Down
Loading

0 comments on commit 744c375

Please sign in to comment.