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..2b9c8b690441 --- /dev/null +++ b/stock_putaway_abc_move_location_dest_constraint/models/__init__.py @@ -0,0 +1,2 @@ +from . import product_strategy +from . import stock_location 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..0d61d37ee986 --- /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 StockPutawayRule(models.Model): + + _inherit = 'stock.putaway.rule' + + @api.multi + def validate_abc_locations(self, locations): + res = super().validate_abc_locations(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/models/stock_location.py b/stock_putaway_abc_move_location_dest_constraint/models/stock_location.py new file mode 100644 index 000000000000..8cab649a7da7 --- /dev/null +++ b/stock_putaway_abc_move_location_dest_constraint/models/stock_location.py @@ -0,0 +1,17 @@ +# Copyright 2019 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from odoo import models + + +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 + # 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) 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 <akim.juillerat@camptocamp.com> 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.