From cf93f34e3925276d76da78cc9c9d7dc11a938115 Mon Sep 17 00:00:00 2001 From: JasminSForgeFlow Date: Wed, 18 Dec 2024 13:21:11 +0530 Subject: [PATCH] [MIG] stock_helper: Migration to 18.0 --- stock_helper/README.rst | 14 +++---- stock_helper/__manifest__.py | 2 +- stock_helper/models/stock_location.py | 40 ++++++++++++------- stock_helper/static/description/index.html | 6 +-- .../tests/test_location_source_from_route.py | 2 +- 5 files changed, 38 insertions(+), 26 deletions(-) diff --git a/stock_helper/README.rst b/stock_helper/README.rst index 3c5cac128e30..3f3c15e06ae1 100644 --- a/stock_helper/README.rst +++ b/stock_helper/README.rst @@ -17,13 +17,13 @@ Stock Helpers :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html :alt: License: LGPL-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/17.0/stock_helper + :target: https://github.com/OCA/stock-logistics-warehouse/tree/18.0/stock_helper :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-17-0/stock-logistics-warehouse-17-0-stock_helper + :target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-18-0/stock-logistics-warehouse-18-0-stock_helper :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=17.0 + :target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-warehouse&target_branch=18.0 :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| @@ -42,7 +42,7 @@ Bug Tracker Bugs are tracked on `GitHub 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -57,8 +57,8 @@ Authors Contributors ------------ -- Guewen Baconnier -- Christopher Ormaza +- Guewen Baconnier +- Christopher Ormaza Maintainers ----------- @@ -73,6 +73,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 `_ project on GitHub. +This module is part of the `OCA/stock-logistics-warehouse `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_helper/__manifest__.py b/stock_helper/__manifest__.py index e7bba61b8f8d..b8f04a829e20 100644 --- a/stock_helper/__manifest__.py +++ b/stock_helper/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Stock Helpers", "summary": "Add methods shared between various stock modules", - "version": "17.0.1.1.1", + "version": "18.0.1.0.0", "development_status": "Production/Stable", "author": "Camptocamp, Odoo Community Association (OCA)", "website": "https://github.com/OCA/stock-logistics-warehouse", diff --git a/stock_helper/models/stock_location.py b/stock_helper/models/stock_location.py index 1a1d813a17db..fd9e1e6f705d 100644 --- a/stock_helper/models/stock_location.py +++ b/stock_helper/models/stock_location.py @@ -2,7 +2,7 @@ # Copyright 2022-2023 Michael Tietz (MT Software) # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). -from odoo import models +from odoo import api, models class StockLocation(models.Model): @@ -20,19 +20,31 @@ def is_sublocation_of(self, others, func=any): # below one of the other location without using SQL. return func(self.parent_path.startswith(other.parent_path) for other in others) + @api.model + def _get_stock_rule(self, location, route, procure_method): + Rule = self.env["stock.rule"] + res = Rule.search( + [ + ("route_id", "=", route.id), + ("location_dest_id", "=", location.id), + ("procure_method", "=", procure_method), + ], + limit=1, + ) + if not res: + res = Rule.search( + [ + ("route_id", "=", route.id), + ("location_src_id", "=", location.id), + ], + limit=1, + ) + return res + def _get_source_location_from_route(self, route, procure_method): self.ensure_one() route.ensure_one() - values = { - "route_ids": route, - } - current_location = self - while current_location: - rule = self.env["procurement.group"]._get_rule( - self.env["product.product"], current_location, values - ) - if not rule: - return self.browse() - if rule.procure_method == procure_method: - return rule.location_src_id - current_location = rule.location_src_id + rule = self._get_stock_rule(self, route, procure_method) + if not rule: + return self.browse() + return rule.location_src_id diff --git a/stock_helper/static/description/index.html b/stock_helper/static/description/index.html index 3100b5e55d22..073eca7a5bf3 100644 --- a/stock_helper/static/description/index.html +++ b/stock_helper/static/description/index.html @@ -369,7 +369,7 @@

Stock Helpers

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! source digest: sha256:fb518cc48413d9879c043a9164bdaf25cee06d723fb62343a910233620a2c893 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Production/Stable License: LGPL-3 OCA/stock-logistics-warehouse Translate me on Weblate Try me on Runboat

+

Production/Stable License: LGPL-3 OCA/stock-logistics-warehouse Translate me on Weblate Try me on Runboat

Add methods to be used by other modules. This is not a functional module.

Table of contents

@@ -389,7 +389,7 @@

Bug Tracker

Bugs are tracked on GitHub 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.

+feedback.

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

@@ -416,7 +416,7 @@

Maintainers

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 project on GitHub.

+

This module is part of the OCA/stock-logistics-warehouse project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

diff --git a/stock_helper/tests/test_location_source_from_route.py b/stock_helper/tests/test_location_source_from_route.py index 6fb0ecefe282..9ad73435cbc9 100644 --- a/stock_helper/tests/test_location_source_from_route.py +++ b/stock_helper/tests/test_location_source_from_route.py @@ -29,7 +29,7 @@ def test_get_source_location_from_route(self): location = source_location source_location = location._get_source_location_from_route( - route, "make_to_stock" + route, "make_to_order" ) self.assertEqual(source_location, self.wh.lot_stock_id)