diff --git a/stock_removal_location_by_priority/__manifest__.py b/stock_removal_location_by_priority/__manifest__.py index fce1a463a..dc934cbe1 100644 --- a/stock_removal_location_by_priority/__manifest__.py +++ b/stock_removal_location_by_priority/__manifest__.py @@ -1,10 +1,10 @@ -# Copyright 2017 ForgeFlow S.L. +# Copyright 2024 ForgeFlow S.L. # (http://www.forgeflow.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). { "name": "Stock Removal Location by Priority", "summary": "Establish a removal priority on stock locations.", - "version": "16.0.1.0.0", + "version": "17.0.1.0.0", "author": "ForgeFlow, " "Odoo Community Association (OCA)", "website": "https://github.com/OCA/stock-logistics-warehouse", "category": "Warehouse", diff --git a/stock_removal_location_by_priority/init_hook.py b/stock_removal_location_by_priority/init_hook.py index 8e937cabd..03e061089 100644 --- a/stock_removal_location_by_priority/init_hook.py +++ b/stock_removal_location_by_priority/init_hook.py @@ -1,4 +1,4 @@ -# Copyright 2017 ForgeFlow, S.L. +# Copyright 2024 ForgeFlow, S.L. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). import logging @@ -6,7 +6,7 @@ import logging logger = logging.getLogger(__name__) -def pre_init_hook(cr): +def pre_init_hook(env): """ The objective of this hook is to speed up the installation of the module on an existing Odoo instance. @@ -14,8 +14,8 @@ def pre_init_hook(cr): Without this script, big databases can take a long time to install this module. """ - set_stock_location_removal_priority_default(cr) - set_stock_quant_removal_priority_default(cr) + set_stock_location_removal_priority_default(env.cr) + set_stock_quant_removal_priority_default(env.cr) def set_stock_location_removal_priority_default(cr): diff --git a/stock_removal_location_by_priority/models/res_config_settings.py b/stock_removal_location_by_priority/models/res_config_settings.py index 16db2c8c7..800b0052e 100644 --- a/stock_removal_location_by_priority/models/res_config_settings.py +++ b/stock_removal_location_by_priority/models/res_config_settings.py @@ -1,4 +1,4 @@ -# Copyright 2017-18 ForgeFlow S.L. +# Copyright 2017-24 ForgeFlow S.L. # (http://www.forgeflow.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). diff --git a/stock_removal_location_by_priority/models/stock_location.py b/stock_removal_location_by_priority/models/stock_location.py index 0e5cf9fbd..ad6526e6a 100644 --- a/stock_removal_location_by_priority/models/stock_location.py +++ b/stock_removal_location_by_priority/models/stock_location.py @@ -1,4 +1,4 @@ -# Copyright 2017 ForgeFlow S.L. +# Copyright 2024 ForgeFlow S.L. # (http://www.forgeflow.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). diff --git a/stock_removal_location_by_priority/models/stock_quant.py b/stock_removal_location_by_priority/models/stock_quant.py index fcc590b86..f73f1ad34 100644 --- a/stock_removal_location_by_priority/models/stock_quant.py +++ b/stock_removal_location_by_priority/models/stock_quant.py @@ -1,4 +1,4 @@ -# Copyright 2017-18 ForgeFlow S.L. +# Copyright 2017-24 ForgeFlow S.L. # (http://www.forgeflow.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). @@ -14,15 +14,21 @@ class StockQuant(models.Model): ) @api.model - def _get_removal_strategy_order(self, removal_strategy): + def _get_removal_strategy_domain_order(self, domain, removal_strategy, qty): if self.user_has_groups( "stock_removal_location_by_priority.group_removal_priority" ): if removal_strategy == "fifo": - return "in_date ASC, removal_priority ASC, id" + return domain, "in_date ASC, removal_priority ASC, id" elif removal_strategy == "lifo": - return "in_date DESC, removal_priority ASC, id desc" + return domain, "in_date DESC, removal_priority ASC, id desc" raise UserError( _("Removal strategy %s not implemented.") % (removal_strategy,) ) - return super(StockQuant, self)._get_removal_strategy_order(removal_strategy) + return super()._get_removal_strategy_domain_order(domain, removal_strategy, qty) + + def _get_removal_strategy_sort_key(self, removal_strategy): + key, reverse = super()._get_removal_strategy_sort_key(removal_strategy) + if removal_strategy == "fifo": + key = lambda q: (q.removal_priority, q.in_date, q.id) # noqa: E731 + return key, reverse diff --git a/stock_removal_location_by_priority/security/stock_security.xml b/stock_removal_location_by_priority/security/stock_security.xml index b05afeecf..fac204f29 100644 --- a/stock_removal_location_by_priority/security/stock_security.xml +++ b/stock_removal_location_by_priority/security/stock_security.xml @@ -1,5 +1,5 @@ - diff --git a/stock_removal_location_by_priority/tests/test_stock_removal_location_by_priority.py b/stock_removal_location_by_priority/tests/test_stock_removal_location_by_priority.py index bf694c4d3..58fdc1649 100644 --- a/stock_removal_location_by_priority/tests/test_stock_removal_location_by_priority.py +++ b/stock_removal_location_by_priority/tests/test_stock_removal_location_by_priority.py @@ -1,4 +1,4 @@ -# Copyright 2017-18 ForgeFlow S.L. +# Copyright 2017-24 ForgeFlow S.L. # (http://www.forgeflow.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). @@ -10,7 +10,7 @@ from odoo.tests.common import TransactionCase class TestStockRemovalLocationByPriority(TransactionCase): def setUp(self): - super(TestStockRemovalLocationByPriority, self).setUp() + super().setUp() self.res_users_model = self.env["res.users"] self.stock_location_model = self.env["stock.location"] self.stock_warehouse_model = self.env["stock.warehouse"] diff --git a/stock_removal_location_by_priority/views/res_config_settings_views.xml b/stock_removal_location_by_priority/views/res_config_settings_views.xml index f1f05f9c0..1e11b2a11 100644 --- a/stock_removal_location_by_priority/views/res_config_settings_views.xml +++ b/stock_removal_location_by_priority/views/res_config_settings_views.xml @@ -1,5 +1,5 @@ - @@ -7,18 +7,12 @@ res.config.settings - -
-
- -
-
-
-
+ + + +
Use Removal Priority in Locations
+
diff --git a/stock_removal_location_by_priority/views/stock_location_view.xml b/stock_removal_location_by_priority/views/stock_location_view.xml index 8b09dd6a6..0807480ae 100644 --- a/stock_removal_location_by_priority/views/stock_location_view.xml +++ b/stock_removal_location_by_priority/views/stock_location_view.xml @@ -1,5 +1,5 @@ -