From 14a366b913fc02ac71721159feeab2d1fbb73839 Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Thu, 5 Sep 2019 18:41:25 +0200 Subject: [PATCH 1/5] 12.0 create module stock putaway abc move location dest constraint --- .../__init__.py | 1 + .../__manifest__.py | 19 +++++++++++++++ .../models/__init__.py | 1 + .../models/product_strategy.py | 24 +++++++++++++++++++ .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 2 ++ 6 files changed, 48 insertions(+) create mode 100644 stock_putaway_abc_move_location_dest_constraint/__init__.py create mode 100644 stock_putaway_abc_move_location_dest_constraint/__manifest__.py create mode 100644 stock_putaway_abc_move_location_dest_constraint/models/__init__.py create mode 100644 stock_putaway_abc_move_location_dest_constraint/models/product_strategy.py create mode 100644 stock_putaway_abc_move_location_dest_constraint/readme/CONTRIBUTORS.rst create mode 100644 stock_putaway_abc_move_location_dest_constraint/readme/DESCRIPTION.rst diff --git a/stock_putaway_abc_move_location_dest_constraint/__init__.py b/stock_putaway_abc_move_location_dest_constraint/__init__.py new file mode 100644 index 000000000000..0650744f6bc6 --- /dev/null +++ b/stock_putaway_abc_move_location_dest_constraint/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_putaway_abc_move_location_dest_constraint/__manifest__.py b/stock_putaway_abc_move_location_dest_constraint/__manifest__.py new file mode 100644 index 000000000000..6ad7fbfe0d46 --- /dev/null +++ b/stock_putaway_abc_move_location_dest_constraint/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2019 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +{ + "name": "Stock Move Location Dest Constraint ABC", + "summary": "Constrain location dest matching ABC classification", + "version": "12.0.1.0.0", + "development_status": "Alpha", + "category": "Warehouse Management", + "website": "https://github.com/OCA/stock-logistics-warehouse", + "author": "Camptocamp, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "auto_install": True, + "depends": [ + "stock_move_location_dest_constraint_base", + "stock_putaway_abc" + ], +} diff --git a/stock_putaway_abc_move_location_dest_constraint/models/__init__.py b/stock_putaway_abc_move_location_dest_constraint/models/__init__.py new file mode 100644 index 000000000000..4699d52279e4 --- /dev/null +++ b/stock_putaway_abc_move_location_dest_constraint/models/__init__.py @@ -0,0 +1 @@ +from . import product_strategy diff --git a/stock_putaway_abc_move_location_dest_constraint/models/product_strategy.py b/stock_putaway_abc_move_location_dest_constraint/models/product_strategy.py new file mode 100644 index 000000000000..50ca733a3936 --- /dev/null +++ b/stock_putaway_abc_move_location_dest_constraint/models/product_strategy.py @@ -0,0 +1,24 @@ +# Copyright 2019 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from odoo import api, models +from odoo.exceptions import ValidationError + + +class ABCPutAwayStrategy(models.Model): + + _inherit = 'stock.abc.putaway.strat' + + @api.multi + def validate_abc_location(self, locations): + res = super().validate_abc_location(locations) + product = None + if self.product_id: + product = self.product_id + checked_locations = self.env['stock.location'] + for loc in res: + try: + loc.check_move_dest_constraint(product=product) + except ValidationError: + continue + checked_locations |= loc + return checked_locations diff --git a/stock_putaway_abc_move_location_dest_constraint/readme/CONTRIBUTORS.rst b/stock_putaway_abc_move_location_dest_constraint/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..e31e2f0c4fcf --- /dev/null +++ b/stock_putaway_abc_move_location_dest_constraint/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Akim Juillerat diff --git a/stock_putaway_abc_move_location_dest_constraint/readme/DESCRIPTION.rst b/stock_putaway_abc_move_location_dest_constraint/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..fe973c092b71 --- /dev/null +++ b/stock_putaway_abc_move_location_dest_constraint/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module allows to validate ABC locations according to constraints installed +by modules restricting location destination on stock move lines. From efdffffbcd671e081e798173708588229bd84ea3 Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Fri, 6 Sep 2019 11:16:51 +0200 Subject: [PATCH 2/5] fixup! 12.0 create module stock putaway abc move location dest constraint --- .../models/product_strategy.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stock_putaway_abc_move_location_dest_constraint/models/product_strategy.py b/stock_putaway_abc_move_location_dest_constraint/models/product_strategy.py index 50ca733a3936..96b78de5138e 100644 --- a/stock_putaway_abc_move_location_dest_constraint/models/product_strategy.py +++ b/stock_putaway_abc_move_location_dest_constraint/models/product_strategy.py @@ -9,8 +9,8 @@ class ABCPutAwayStrategy(models.Model): _inherit = 'stock.abc.putaway.strat' @api.multi - def validate_abc_location(self, locations): - res = super().validate_abc_location(locations) + def validate_abc_locations(self, locations): + res = super().validate_abc_locations(locations) product = None if self.product_id: product = self.product_id From d5c170b839ddc4b16897d116b22ac43a6fd6f696 Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Mon, 9 Sep 2019 16:22:26 +0200 Subject: [PATCH 3/5] Merge abc putaway into stock.putaway.rule --- .../models/product_strategy.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stock_putaway_abc_move_location_dest_constraint/models/product_strategy.py b/stock_putaway_abc_move_location_dest_constraint/models/product_strategy.py index 96b78de5138e..0d61d37ee986 100644 --- a/stock_putaway_abc_move_location_dest_constraint/models/product_strategy.py +++ b/stock_putaway_abc_move_location_dest_constraint/models/product_strategy.py @@ -4,9 +4,9 @@ from odoo.exceptions import ValidationError -class ABCPutAwayStrategy(models.Model): +class StockPutawayRule(models.Model): - _inherit = 'stock.abc.putaway.strat' + _inherit = 'stock.putaway.rule' @api.multi def validate_abc_locations(self, locations): From 45c697e286be23d5d54792a21d4c5cfa90a8afcf Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Tue, 17 Sep 2019 11:47:57 +0200 Subject: [PATCH 4/5] Fix calling check_move_dest_constraint on empty recordset --- .../models/__init__.py | 1 + .../models/stock_location.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 stock_putaway_abc_move_location_dest_constraint/models/stock_location.py diff --git a/stock_putaway_abc_move_location_dest_constraint/models/__init__.py b/stock_putaway_abc_move_location_dest_constraint/models/__init__.py index 4699d52279e4..2b9c8b690441 100644 --- a/stock_putaway_abc_move_location_dest_constraint/models/__init__.py +++ b/stock_putaway_abc_move_location_dest_constraint/models/__init__.py @@ -1 +1,2 @@ from . import product_strategy +from . import stock_location diff --git a/stock_putaway_abc_move_location_dest_constraint/models/stock_location.py b/stock_putaway_abc_move_location_dest_constraint/models/stock_location.py new file mode 100644 index 000000000000..a8ac852096c0 --- /dev/null +++ b/stock_putaway_abc_move_location_dest_constraint/models/stock_location.py @@ -0,0 +1,15 @@ +# Copyright 2019 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from odoo import models + + +class StockLocation(models.Model): + + def check_move_dest_constraint(self, line=None, product=None): + # As stock.putaway.rule.location_out_id is not required when + # stock_putaway_abc is installed, we check here that this method + # is called on an existing stock.location to avoid error on ensure_one + # in stock_move_location_dest_constraint_base + if not self: + return False + return super().check_move_dest_constraint(line=line, product=product) From dd85b11698d3d14402c6768e85ebe2c6cf839d0d Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Tue, 17 Sep 2019 12:08:32 +0200 Subject: [PATCH 5/5] fixup! Fix calling check_move_dest_constraint on empty recordset --- .../models/stock_location.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stock_putaway_abc_move_location_dest_constraint/models/stock_location.py b/stock_putaway_abc_move_location_dest_constraint/models/stock_location.py index a8ac852096c0..8cab649a7da7 100644 --- a/stock_putaway_abc_move_location_dest_constraint/models/stock_location.py +++ b/stock_putaway_abc_move_location_dest_constraint/models/stock_location.py @@ -5,6 +5,8 @@ class StockLocation(models.Model): + _inherit = 'stock.location' + def check_move_dest_constraint(self, line=None, product=None): # As stock.putaway.rule.location_out_id is not required when # stock_putaway_abc is installed, we check here that this method