Skip to content

Commit

Permalink
[MIG] stock_secondary_unit: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lk-eska committed Apr 8, 2024
1 parent 5606970 commit b3f956c
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 40 deletions.
6 changes: 6 additions & 0 deletions setup/stock_secondary_unit/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
12 changes: 6 additions & 6 deletions stock_secondary_unit/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Stock Secondary Unit
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:592c2a28d87ad4487df90a96904d06388620f0305840bff125f0dbd5c0dcb91a
!! source digest: sha256:223ef04b21ff22ef2ebf18865952a5de5099e9a5c643632debfcf530c7e2fea7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
Expand All @@ -17,13 +17,13 @@ Stock 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%2Fstock--logistics--warehouse-lightgray.png?logo=github
:target: https://github.com/OCA/stock-logistics-warehouse/tree/15.0/stock_secondary_unit
:target: https://github.com/OCA/stock-logistics-warehouse/tree/16.0/stock_secondary_unit
:alt: OCA/stock-logistics-warehouse
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-15-0/stock-logistics-warehouse-15-0-stock_secondary_unit
:target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-16-0/stock-logistics-warehouse-16-0-stock_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/stock-logistics-warehouse&target_branch=15.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-warehouse&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -54,7 +54,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-warehouse/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/stock-logistics-warehouse/issues/new?body=module:%20stock_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/stock-logistics-warehouse/issues/new?body=module:%20stock_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 Down Expand Up @@ -91,6 +91,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/stock-logistics-warehouse <https://github.com/OCA/stock-logistics-warehouse/tree/15.0/stock_secondary_unit>`_ project on GitHub.
This module is part of the `OCA/stock-logistics-warehouse <https://github.com/OCA/stock-logistics-warehouse/tree/16.0/stock_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 stock_secondary_unit/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "Stock Secondary Unit",
"summary": "Get product quantities in a secondary unit",
"version": "15.0.2.1.0",
"version": "16.0.1.0.0",
"development_status": "Production/Stable",
"category": "stock",
"website": "https://github.com/OCA/stock-logistics-warehouse",
Expand Down
10 changes: 8 additions & 2 deletions stock_secondary_unit/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ class StockMove(models.Model):
}

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

@api.depends("secondary_uom_qty", "secondary_uom_id")
Expand Down Expand Up @@ -42,7 +46,9 @@ class StockMoveLine(models.Model):
_name = "stock.move.line"
_secondary_unit_fields = {"qty_field": "qty_done", "uom_field": "product_uom_id"}

qty_done = fields.Float(store=True, readonly=False, compute="_compute_qty_done")
qty_done = fields.Float(
store=True, readonly=False, compute="_compute_qty_done", precompute=True
)

@api.model
def create(self, vals):
Expand Down
9 changes: 5 additions & 4 deletions stock_secondary_unit/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -366,9 +367,9 @@ <h1 class="title">Stock Secondary Unit</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:592c2a28d87ad4487df90a96904d06388620f0305840bff125f0dbd5c0dcb91a
!! source digest: sha256:223ef04b21ff22ef2ebf18865952a5de5099e9a5c643632debfcf530c7e2fea7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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/stock-logistics-warehouse/tree/15.0/stock_secondary_unit"><img alt="OCA/stock-logistics-warehouse" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/stock-logistics-warehouse-15-0/stock-logistics-warehouse-15-0-stock_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/stock-logistics-warehouse&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/stock-logistics-warehouse/tree/16.0/stock_secondary_unit"><img alt="OCA/stock-logistics-warehouse" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/stock-logistics-warehouse-16-0/stock-logistics-warehouse-16-0-stock_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/stock-logistics-warehouse&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 stock module to allow define
other units with their conversion factor.</p>
<p><strong>Table of contents</strong></p>
Expand Down Expand Up @@ -401,7 +402,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/stock-logistics-warehouse/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/stock-logistics-warehouse/issues/new?body=module:%20stock_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/stock-logistics-warehouse/issues/new?body=module:%20stock_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 Down Expand Up @@ -433,7 +434,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">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/stock-logistics-warehouse/tree/15.0/stock_secondary_unit">OCA/stock-logistics-warehouse</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/tree/16.0/stock_secondary_unit">OCA/stock-logistics-warehouse</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
21 changes: 7 additions & 14 deletions stock_secondary_unit/tests/test_stock_secondary_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,14 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.tests import Form, TransactionCase, tagged

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


@tagged("-at_install", "post_install")
class TestProductSecondaryUnit(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))
# Active multiple units of measure security group for user
cls.env.user.groups_id = [(4, cls.env.ref("uom.group_uom").id)]
Expand Down Expand Up @@ -148,10 +141,10 @@ def test_03_stock_picking_secondary_unit(self):
delivery_order = StockPicking.create(do_vals)
delivery_order.action_confirm()
# Move is merged into 1 line for both stock.move and stock.move.line
self.assertEqual(len(delivery_order.move_lines), 1)
self.assertEqual(len(delivery_order.move_ids), 1)
self.assertEqual(len(delivery_order.move_line_ids), 1)
# Qty merged to 20, and secondary unit qty is 40line
uom_qty = sum(delivery_order.move_lines.mapped("product_uom_qty"))
uom_qty = sum(delivery_order.move_ids.mapped("product_uom_qty"))
secondary_uom_qty = sum(
delivery_order.move_line_ids.mapped("secondary_uom_qty")
)
Expand Down Expand Up @@ -218,7 +211,7 @@ def test_secondary_unit_merge_move_diff_uom(self):
move.secondary_uom_id = product.product_tmpl_id.secondary_uom_ids[1]
picking = picking_form.save()
picking.action_confirm()
self.assertEqual(len(picking.move_lines), 2)
self.assertEqual(len(picking.move_ids), 2)

def test_secondary_unit_merge_move_same_uom(self):
product = self.product_template.product_variant_ids[0]
Expand All @@ -238,5 +231,5 @@ def test_secondary_unit_merge_move_same_uom(self):
move.secondary_uom_id = product.product_tmpl_id.secondary_uom_ids[0]
picking = picking_form.save()
picking.action_confirm()
self.assertEqual(len(picking.move_lines), 1)
self.assertEqual(picking.move_lines.secondary_uom_qty, 2)
self.assertEqual(len(picking.move_ids), 1)
self.assertEqual(picking.move_ids.secondary_uom_qty, 2)
21 changes: 13 additions & 8 deletions stock_secondary_unit/views/product_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
<field name="name">Product template Secondary Unit</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="stock.view_template_property_form" />
<field name="groups_id" eval="[(4, ref('stock.group_stock_user'))]" />
<field name="arch" type="xml">
<xpath expr="//group[@name='inventory']" position="inside">
<group string="Secondary unit">
<group string="Secondary unit" groups="stock.group_stock_user">
<field
name="stock_secondary_uom_id"
options="{'no_create': True}"
Expand All @@ -24,7 +23,6 @@
name="inherit_id"
ref="stock.product_template_form_view_procurement_button"
/>
<field name="groups_id" eval="[(4, ref('stock.group_stock_user'))]" />
<field name="arch" type="xml">
<xpath expr="//button[@name='action_open_quants']" position="after">
<button
Expand All @@ -33,6 +31,7 @@
attrs="{'invisible':[('type', '!=', 'product')]}"
class="oe_stat_button"
icon="fa-building-o"
groups="stock.group_stock_user"
>
<div class="o_form_field o_stat_info">
<span class="o_stat_value">
Expand All @@ -53,7 +52,6 @@
<record id="product_form_view_procurement_button" model="ir.ui.view">
<field name="model">product.product</field>
<field name="inherit_id" ref="stock.product_form_view_procurement_button" />
<field name="groups_id" eval="[(4, ref('stock.group_stock_user'))]" />
<field name="arch" type="xml">
<xpath expr="//button[@name='action_open_quants']" position="after">
<button
Expand All @@ -62,6 +60,7 @@
attrs="{'invisible':[('type', '!=', 'product')]}"
class="oe_stat_button"
icon="fa-building-o"
groups="stock.group_stock_user"
>
<div class="o_form_field o_stat_info">
<span class="o_stat_value">
Expand All @@ -82,27 +81,33 @@
<record id="product_template_tree_view" model="ir.ui.view">
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_tree_view" />
<field name="groups_id" eval="[(4, ref('stock.group_stock_user'))]" />
<field name="arch" type="xml">
<xpath expr="//field[@name='uom_id']" position="after">
<field name="secondary_unit_qty_available" />
<field
name="secondary_unit_qty_available"
groups="stock.group_stock_user"
/>
<field
name="stock_secondary_uom_id"
options="{'no_open': True, 'no_create': True}"
groups="stock.group_stock_user"
/>
</xpath>
</field>
</record>
<record id="product_product_tree_view" model="ir.ui.view">
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_product_tree_view" />
<field name="groups_id" eval="[(4, ref('stock.group_stock_user'))]" />
<field name="arch" type="xml">
<xpath expr="//field[@name='uom_id']" position="after">
<field name="secondary_unit_qty_available" />
<field
name="secondary_unit_qty_available"
groups="stock.group_stock_user"
/>
<field
name="stock_secondary_uom_id"
options="{'no_open': True, 'no_create': True}"
groups="stock.group_stock_user"
/>
</xpath>
</field>
Expand Down
10 changes: 6 additions & 4 deletions stock_secondary_unit/views/stock_move_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<field name="name">Stock Move Secondary Unit</field>
<field name="model">stock.move.line</field>
<field name="inherit_id" ref="stock.view_stock_move_line_operation_tree" />
<field name="groups_id" eval="[(4, ref('uom.group_uom'))]" />
<field name="arch" type="xml">
<field name="product_uom_qty" position="before">
<field name="reserved_uom_qty" position="before">
<field
name="secondary_uom_qty"
attrs="{'readonly': [('state', 'in', ('done', 'cancel')), ('is_locked', '=', True)]}"
force_save="1"
groups="uom.group_uom"
/>
<field
name="secondary_uom_id"
Expand All @@ -21,6 +21,7 @@
('product_id', '=', False)]"
attrs="{'readonly': [('state', '!=', 'draft'), ('id', '!=', False)]}"
options="{'no_create': True}"
groups="uom.group_uom"
/>
</field>
</field>
Expand All @@ -32,13 +33,13 @@
name="inherit_id"
ref="stock.view_stock_move_line_detailed_operation_tree"
/>
<field name="groups_id" eval="[(4, ref('uom.group_uom'))]" />
<field name="arch" type="xml">
<field name="product_uom_qty" position="before">
<field name="reserved_uom_qty" position="before">
<field
name="secondary_uom_qty"
attrs="{'readonly': [('state', 'in', ('done', 'cancel')), ('is_locked', '=', True)]}"
force_save="1"
groups="uom.group_uom"
/>
<field
name="secondary_uom_id"
Expand All @@ -47,6 +48,7 @@
('product_id', '=', False)]"
attrs="{'readonly': [('state', '!=', 'draft'), ('id', '!=', False)]}"
options="{'no_create': True}"
groups="uom.group_uom"
/>
</field>
</field>
Expand Down
Loading

0 comments on commit b3f956c

Please sign in to comment.