Skip to content

Commit

Permalink
[MIG] stock_owner_restriction: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosRoca13 committed Jan 28, 2025
1 parent 6d0c1d3 commit 090fa5e
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 41 deletions.
5 changes: 3 additions & 2 deletions stock_owner_restriction/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Stock Owner Restriction
!! source digest: sha256:885d32742bfef03a27c8c9373bfecefea44e5758c69cc6f525399e7aa025751b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
:alt: Production/Stable
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
Expand Down Expand Up @@ -129,6 +129,7 @@ Contributors
- Sergio Teruel
- César A. Sánchez
- Luis D. Lafaurie
- Carlos Roca

Maintainers
-----------
Expand Down
7 changes: 2 additions & 5 deletions stock_owner_restriction/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, SUPERUSER_ID
from . import models


def uninstall_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
def uninstall_hook(env):
picking_types = env["stock.picking.type"].search(
[("owner_restriction", "!=", False)]
)
picking_types.write({"owner_restriction": False})


def set_default_owner_restriction(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
def set_default_owner_restriction(env):
picking_types = env["stock.picking.type"].search(
[("owner_restriction", "=", False)]
)
Expand Down
4 changes: 2 additions & 2 deletions stock_owner_restriction/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
{
"name": "Stock Owner Restriction",
"summary": "Do not reserve quantity with assigned owner",
"version": "16.0.1.1.2",
"development_status": "Beta",
"version": "18.0.1.0.0",
"development_status": "Production/Stable",
"category": "stock",
"website": "https://github.com/OCA/stock-logistics-workflow",
"author": "Tecnativa, Odoo Community Association (OCA)",
Expand Down
5 changes: 1 addition & 4 deletions stock_owner_restriction/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ def _action_assign(self, force_qty=False):
and moves_to_assign.picking_type_id.owner_restriction
== "partner_or_unassigned"
and sum(
move.reserved_availability - move.product_uom_qty
for move in moves_to_assign
move.quantity - move.product_uom_qty for move in moves_to_assign
)
< 0
):
Expand All @@ -66,7 +65,6 @@ def _action_assign(self, force_qty=False):
def _update_reserved_quantity(
self,
need,
available_quantity,
location_id,
lot_id=None,
package_id=None,
Expand All @@ -78,7 +76,6 @@ def _update_reserved_quantity(
owner_id = restricted_owner_id
return super()._update_reserved_quantity(
need,
available_quantity,
location_id,
lot_id=lot_id,
package_id=package_id,
Expand Down
23 changes: 16 additions & 7 deletions stock_owner_restriction/models/stock_quant.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def _gather(
package_id=None,
owner_id=None,
strict=False,
qty=0,
):
records = super()._gather(
product_id,
Expand All @@ -32,6 +33,7 @@ def _gather(
package_id=package_id,
owner_id=self._get_restriction_owner_id(location_id, owner_id),
strict=strict,
qty=qty,
)
restricted_owner_id = self.env.context.get("force_restricted_owner_id", None)
if owner_id is None or restricted_owner_id is None:
Expand All @@ -41,20 +43,27 @@ def _gather(
)

@api.model
def read_group(
self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True
def _read_group(
self,
domain,
groupby=(),
aggregates=(),
having=(),
offset=0,
limit=None,
order=None,
):
restricted_owner_id = self.env.context.get("force_restricted_owner_id", None)
if restricted_owner_id is not None:
domain = expression.AND([domain, [("owner_id", "=", restricted_owner_id)]])
return super(StockQuant, self).read_group(
return super()._read_group(
domain,
fields,
groupby,
groupby=groupby,
aggregates=aggregates,
having=having,
offset=offset,
limit=limit,
orderby=orderby,
lazy=lazy,
order=order,
)

@api.model
Expand Down
1 change: 1 addition & 0 deletions stock_owner_restriction/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
> - Sergio Teruel
> - César A. Sánchez
> - Luis D. Lafaurie
> - Carlos Roca
3 changes: 2 additions & 1 deletion stock_owner_restriction/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ <h1 class="title">Stock Owner Restriction</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:885d32742bfef03a27c8c9373bfecefea44e5758c69cc6f525399e7aa025751b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.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-workflow/tree/18.0/stock_owner_restriction"><img alt="OCA/stock-logistics-workflow" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--workflow-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/stock-logistics-workflow-18-0/stock-logistics-workflow-18-0-stock_owner_restriction"><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-workflow&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><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-workflow/tree/18.0/stock_owner_restriction"><img alt="OCA/stock-logistics-workflow" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--workflow-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/stock-logistics-workflow-18-0/stock-logistics-workflow-18-0-stock_owner_restriction"><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-workflow&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 stock module to allow
restriction of product quantities (quants) for stock operations such as
reserve quantities or product quantity available info.</p>
Expand Down Expand Up @@ -475,6 +475,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<li>Sergio Teruel</li>
<li>César A. Sánchez</li>
<li>Luis D. Lafaurie</li>
<li>Carlos Roca</li>
</ul>
</blockquote>
</li>
Expand Down
29 changes: 11 additions & 18 deletions stock_owner_restriction/tests/test_stock_owner_restriction.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,22 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests.common import TransactionCase

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


class TestStockOwnerRestriction(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))
# models
cls.picking_model = cls.env["stock.picking"]
cls.move_model = cls.env["stock.move"]
cls.ResPartner = cls.env["res.partner"]

# warehouse and picking types
cls.warehouse = cls.env.ref("stock.stock_warehouse_shop0")
cls.picking_type_out = cls.env.ref("stock.chi_picking_type_out")
cls.warehouse = cls.env.ref("stock.warehouse0")
cls.picking_type_out = cls.env.ref("stock.picking_type_out")
cls.customer_location = cls.env.ref("stock.stock_location_customers")

# Allow all companies for OdooBot user and set default user company
Expand All @@ -42,7 +35,7 @@ def setUpClass(cls):

# products
cls.product = cls.env["product.product"].create(
{"name": "Test restriction", "type": "product"}
{"name": "Test restriction", "type": "consu", "is_storable": True}
)
quant_vals = {
"product_id": cls.product.id,
Expand Down Expand Up @@ -99,7 +92,7 @@ def test_restrict_reserve_qty(self):
# For standard_behavior Odoo does not take into account the owner in
# quants, so Odoo has been reserved 500 quantities without owner and
# 500 quantities with owner
self.assertEqual(self.picking_out.move_ids.reserved_availability, 1000.00)
self.assertEqual(self.picking_out.move_ids.quantity, 1000.00)
self.assertEqual(len(self.picking_out.move_line_ids), 2)
self.assertEqual(self.picking_out.move_line_ids.mapped("owner_id"), self.owner)

Expand All @@ -108,7 +101,7 @@ def test_restrict_reserve_qty(self):
self.picking_type_out.owner_restriction = "unassigned_owner"
self.picking_out.do_unreserve()
self.picking_out.action_assign()
self.assertEqual(self.picking_out.move_ids.reserved_availability, 500.00)
self.assertEqual(self.picking_out.move_ids.quantity, 500.00)
self.assertEqual(len(self.picking_out.move_line_ids), 1)
self.assertFalse(self.picking_out.move_line_ids.mapped("owner_id"))

Expand All @@ -119,7 +112,7 @@ def test_restrict_reserve_qty(self):
self.picking_type_out.owner_restriction = "picking_partner"
self.picking_out.do_unreserve()
self.picking_out.action_assign()
self.assertEqual(self.picking_out.move_ids.reserved_availability, 0.0)
self.assertEqual(self.picking_out.move_ids.quantity, 0.0)
self.assertEqual(len(self.picking_out.move_line_ids), 0)
self.assertEqual(self.picking_out.state, "confirmed")

Expand All @@ -131,7 +124,7 @@ def test_restrict_reserve_qty(self):
self.picking_out.partner_id = self.owner
self.picking_out.do_unreserve()
self.picking_out.action_assign()
self.assertEqual(self.picking_out.move_ids.reserved_availability, 500.00)
self.assertEqual(self.picking_out.move_ids.quantity, 500.00)
self.assertEqual(len(self.picking_out.move_line_ids), 1)
self.assertTrue(self.picking_out.move_line_ids.mapped("owner_id"))
self.assertEqual(self.picking_out.state, "assigned")
Expand All @@ -143,7 +136,7 @@ def test_restrict_reserve_qty(self):
self.picking_type_out.owner_restriction = "partner_or_unassigned"
self.picking_out.do_unreserve()
self.picking_out.action_assign()
self.assertEqual(self.picking_out.move_ids.reserved_availability, 1000.00)
self.assertEqual(self.picking_out.move_ids.quantity, 1000.00)
self.assertEqual(len(self.picking_out.move_line_ids), 2)
self.assertEqual(self.picking_out.move_line_ids.mapped("owner_id"), self.owner)

Expand All @@ -154,7 +147,7 @@ def test_restrict_reserve_qty(self):
self.picking_out.partner_id = False
self.picking_out.do_unreserve()
self.picking_out.action_assign()
self.assertEqual(self.picking_out.move_ids.reserved_availability, 500.00)
self.assertEqual(self.picking_out.move_ids.quantity, 500.00)
self.assertEqual(len(self.picking_out.move_line_ids), 1)

def test_search_qty(self):
Expand Down
4 changes: 2 additions & 2 deletions stock_owner_restriction/views/stock_picking_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
</field>
<field name="owner_id" position="attributes">
<attribute
name="attrs"
>{'invisible': [('picking_type_code', '!=', 'incoming'), ('owner_restriction', '!=', 'picking_partner')]}</attribute>
name="invisible"
>picking_type_code != 'incoming' and owner_restriction != 'picking_partner'</attribute>
</field>
</field>
</record>
Expand Down

0 comments on commit 090fa5e

Please sign in to comment.