From 1e603b0f00d430b852f5c5fcde75d0a106fac376 Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Thu, 5 Sep 2019 13:29:17 +0200 Subject: [PATCH 1/6] 12.0 create module stock move location dest constraint base --- .../README.rst | 94 ++++ .../__init__.py | 1 + .../__manifest__.py | 21 + .../data/stock_location.xml | 4 + .../models/__init__.py | 3 + .../models/product_strategy.py | 14 + .../models/stock_location.py | 38 ++ .../models/stock_move.py | 16 + .../readme/CONFIGURE.rst | 6 + .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 4 + .../readme/USAGE.rst | 4 + .../static/description/index.html | 440 ++++++++++++++++++ .../views/stock_location.xml | 13 + 14 files changed, 659 insertions(+) create mode 100644 stock_move_location_dest_constraint_base/README.rst create mode 100644 stock_move_location_dest_constraint_base/__init__.py create mode 100644 stock_move_location_dest_constraint_base/__manifest__.py create mode 100644 stock_move_location_dest_constraint_base/data/stock_location.xml create mode 100644 stock_move_location_dest_constraint_base/models/__init__.py create mode 100644 stock_move_location_dest_constraint_base/models/product_strategy.py create mode 100644 stock_move_location_dest_constraint_base/models/stock_location.py create mode 100644 stock_move_location_dest_constraint_base/models/stock_move.py create mode 100644 stock_move_location_dest_constraint_base/readme/CONFIGURE.rst create mode 100644 stock_move_location_dest_constraint_base/readme/CONTRIBUTORS.rst create mode 100644 stock_move_location_dest_constraint_base/readme/DESCRIPTION.rst create mode 100644 stock_move_location_dest_constraint_base/readme/USAGE.rst create mode 100644 stock_move_location_dest_constraint_base/static/description/index.html create mode 100644 stock_move_location_dest_constraint_base/views/stock_location.xml diff --git a/stock_move_location_dest_constraint_base/README.rst b/stock_move_location_dest_constraint_base/README.rst new file mode 100644 index 000000000000..5efd5f54ac8d --- /dev/null +++ b/stock_move_location_dest_constraint_base/README.rst @@ -0,0 +1,94 @@ +========================================= +Stock Move Location Dest Constraints Base +========================================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png + :target: https://odoo-community.org/page/development-status + :alt: Alpha +.. |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 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fcrm-lightgray.png?logo=github + :target: https://github.com/OCA/crm/tree/12.0/stock_move_location_dest_constraint_base + :alt: OCA/crm +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/crm-12-0/crm-12-0-stock_move_location_dest_constraint_base + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/111/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module provides a base mechanism to constrain the selection of destination +location on stock move lines. +It also adds a checkbox 'Bypass constraints' on stock location to deactivate +the checks implemented by installed modules. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +When installing the module, all the existing stock location will be set to +bypass constraints. +Therefore the user must manually activate the constraints on existing +locations. +However, any location created after the module installation will have the +constraints activated as the flag will not be set to True automatically. + +Usage +===== + +To define new constraints on stock location, function +`check_move_dest_constraint` on `stock.location` must be overriden to throw a +ValidationError if the location is not allowed for selected product or stock +move line. + +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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Camptocamp + +Contributors +~~~~~~~~~~~~ + +* Akim Juillerat + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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/crm `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_move_location_dest_constraint_base/__init__.py b/stock_move_location_dest_constraint_base/__init__.py new file mode 100644 index 000000000000..0650744f6bc6 --- /dev/null +++ b/stock_move_location_dest_constraint_base/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_move_location_dest_constraint_base/__manifest__.py b/stock_move_location_dest_constraint_base/__manifest__.py new file mode 100644 index 000000000000..70225de6d95e --- /dev/null +++ b/stock_move_location_dest_constraint_base/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2019 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +{ + "name": "Stock Move Location Dest Constraints Base", + "summary": "Base module to constrain dest location on stock move line", + "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, + "depends": [ + "stock", + ], + "data": [ + "data/stock_location.xml", + "views/stock_location.xml", + ], +} diff --git a/stock_move_location_dest_constraint_base/data/stock_location.xml b/stock_move_location_dest_constraint_base/data/stock_location.xml new file mode 100644 index 000000000000..8965427d56e7 --- /dev/null +++ b/stock_move_location_dest_constraint_base/data/stock_location.xml @@ -0,0 +1,4 @@ + + + + diff --git a/stock_move_location_dest_constraint_base/models/__init__.py b/stock_move_location_dest_constraint_base/models/__init__.py new file mode 100644 index 000000000000..a7bfc8dd4bfd --- /dev/null +++ b/stock_move_location_dest_constraint_base/models/__init__.py @@ -0,0 +1,3 @@ +from . import product_strategy +from . import stock_location +from . import stock_move diff --git a/stock_move_location_dest_constraint_base/models/product_strategy.py b/stock_move_location_dest_constraint_base/models/product_strategy.py new file mode 100644 index 000000000000..f42e005d763c --- /dev/null +++ b/stock_move_location_dest_constraint_base/models/product_strategy.py @@ -0,0 +1,14 @@ +# Copyright 2019 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from odoo import api, models + + +class PutAwayStrategy(models.Model): + _inherit = 'product.putaway' + + def _get_putaway_rule(self, product): + """Activate constraint when looking for putaway rules""" + self = self.with_context( + _filter_on_constraints=True, _constraint_product=product.id + ) + return super()._get_putaway_rule(product) diff --git a/stock_move_location_dest_constraint_base/models/stock_location.py b/stock_move_location_dest_constraint_base/models/stock_location.py new file mode 100644 index 000000000000..c31bd9df2815 --- /dev/null +++ b/stock_move_location_dest_constraint_base/models/stock_location.py @@ -0,0 +1,38 @@ +# Copyright 2019 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from odoo import api, models, fields +from odoo.exceptions import ValidationError + + +class StockLocation(models.Model): + + _inherit = 'stock.location' + + bypass_constraints = fields.Boolean() + + def check_move_dest_constraint(self, line=None, product=None): + """Raise Validation error if not allowed""" + self.ensure_one() + return True + + @api.model + def _set_bypass_on_existing_locations(self): + """Set bypass_constrains on all the existing locations""" + existing_locations = self.search([]) + existing_locations.write({'bypass_constraints': True}) + + def filtered(self, func): + """Filter locations according to installed constraints""" + locations = super().filtered(func) + if self.env.context.get('_filter_on_constraints'): + product_id = self.env.context.get('_constraint_product') + product = self.env['product.product'].browse(product_id) + new_locations = self.browse() + for loc in locations: + try: + loc.check_move_dest_constraint(product=product) + except ValidationError: + continue + new_locations |= loc + locations = new_locations + return locations diff --git a/stock_move_location_dest_constraint_base/models/stock_move.py b/stock_move_location_dest_constraint_base/models/stock_move.py new file mode 100644 index 000000000000..243a200856ce --- /dev/null +++ b/stock_move_location_dest_constraint_base/models/stock_move.py @@ -0,0 +1,16 @@ +# Copyright 2019 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from odoo import api, models + + +class StockMoveLine(models.Model): + + _inherit = 'stock.move.line' + + @api.constrains('location_dest_id') + def _check_location_dest_id(self): + """Check if destination location is allowed""" + for line in self: + if line.location_dest_id.bypass_constraints: + continue + line.location_dest_id.check_move_dest_constraint(line=line) diff --git a/stock_move_location_dest_constraint_base/readme/CONFIGURE.rst b/stock_move_location_dest_constraint_base/readme/CONFIGURE.rst new file mode 100644 index 000000000000..c74d6593cca2 --- /dev/null +++ b/stock_move_location_dest_constraint_base/readme/CONFIGURE.rst @@ -0,0 +1,6 @@ +When installing the module, all the existing stock location will be set to +bypass constraints. +Therefore the user must manually activate the constraints on existing +locations. +However, any location created after the module installation will have the +constraints activated as the flag will not be set to True automatically. diff --git a/stock_move_location_dest_constraint_base/readme/CONTRIBUTORS.rst b/stock_move_location_dest_constraint_base/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..e31e2f0c4fcf --- /dev/null +++ b/stock_move_location_dest_constraint_base/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Akim Juillerat diff --git a/stock_move_location_dest_constraint_base/readme/DESCRIPTION.rst b/stock_move_location_dest_constraint_base/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..0a5286076484 --- /dev/null +++ b/stock_move_location_dest_constraint_base/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +This module provides a base mechanism to constrain the selection of destination +location on stock move lines. +It also adds a checkbox 'Bypass constraints' on stock location to deactivate +the checks implemented by installed modules. diff --git a/stock_move_location_dest_constraint_base/readme/USAGE.rst b/stock_move_location_dest_constraint_base/readme/USAGE.rst new file mode 100644 index 000000000000..4bbcc1cd7ffc --- /dev/null +++ b/stock_move_location_dest_constraint_base/readme/USAGE.rst @@ -0,0 +1,4 @@ +To define new constraints on stock location, function +`check_move_dest_constraint` on `stock.location` must be overriden to throw a +ValidationError if the location is not allowed for selected product or stock +move line. diff --git a/stock_move_location_dest_constraint_base/static/description/index.html b/stock_move_location_dest_constraint_base/static/description/index.html new file mode 100644 index 000000000000..f8f477d9f83c --- /dev/null +++ b/stock_move_location_dest_constraint_base/static/description/index.html @@ -0,0 +1,440 @@ + + + + + + +Stock Move Location Dest Constraints Base + + + +
+

Stock Move Location Dest Constraints Base

+ + +

Alpha License: AGPL-3 OCA/crm Translate me on Weblate Try me on Runbot

+

This module provides a base mechanism to constrain the selection of destination +location on stock move lines. +It also adds a checkbox ‘Bypass constraints’ on stock location to deactivate +the checks implemented by installed modules.

+

Table of contents

+ +
+

Configuration

+

When installing the module, all the existing stock location will be set to +bypass constraints. +Therefore the user must manually activate the constraints on existing +locations. +However, any location created after the module installation will have the +constraints activated as the flag will not be set to True automatically.

+
+
+

Usage

+

To define new constraints on stock location, function +check_move_dest_constraint on stock.location must be overriden to throw a +ValidationError if the location is not allowed for selected product or stock +move line.

+
+
+

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 smashing it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Camptocamp
  • +
+
+ +
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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

+

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

+
+
+
+ + diff --git a/stock_move_location_dest_constraint_base/views/stock_location.xml b/stock_move_location_dest_constraint_base/views/stock_location.xml new file mode 100644 index 000000000000..c1acb1f0611d --- /dev/null +++ b/stock_move_location_dest_constraint_base/views/stock_location.xml @@ -0,0 +1,13 @@ + + + + stock.location.form.inherit + + stock.location + + + + + + + From fda3740295fe7db582bb96ef006ea841a0a4e9dd Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Thu, 5 Sep 2019 14:23:04 +0200 Subject: [PATCH 2/6] fixup! 12.0 create module stock move location dest constraint base --- .../models/product_strategy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stock_move_location_dest_constraint_base/models/product_strategy.py b/stock_move_location_dest_constraint_base/models/product_strategy.py index f42e005d763c..170418ed34a8 100644 --- a/stock_move_location_dest_constraint_base/models/product_strategy.py +++ b/stock_move_location_dest_constraint_base/models/product_strategy.py @@ -1,6 +1,6 @@ # Copyright 2019 Camptocamp SA # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) -from odoo import api, models +from odoo import models class PutAwayStrategy(models.Model): From 1aec0b60a5aafb9b8db8cc04ea7d1bca22bc263d Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Thu, 5 Sep 2019 17:56:36 +0200 Subject: [PATCH 3/6] fixup! fixup! 12.0 create module stock move location dest constraint base --- .../models/product_strategy.py | 22 +++++++++++++++++++ .../models/stock_location.py | 17 -------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/stock_move_location_dest_constraint_base/models/product_strategy.py b/stock_move_location_dest_constraint_base/models/product_strategy.py index 170418ed34a8..2218f6ab2b44 100644 --- a/stock_move_location_dest_constraint_base/models/product_strategy.py +++ b/stock_move_location_dest_constraint_base/models/product_strategy.py @@ -1,6 +1,7 @@ # Copyright 2019 Camptocamp SA # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) from odoo import models +from odoo.exceptions import ValidationError class PutAwayStrategy(models.Model): @@ -12,3 +13,24 @@ def _get_putaway_rule(self, product): _filter_on_constraints=True, _constraint_product=product.id ) return super()._get_putaway_rule(product) + + +class FixedPutAwayStrategy(models.Model): + + _inherit = 'stock.fixed.putaway.strat' + + def filtered(self, func): + """Filter putaway strats according to installed constraints""" + putaway_strats = super().filtered(func) + if self.env.context.get('_filter_on_constraints'): + product_id = self.env.context.get('_constraint_product') + product = self.env['product.product'].browse(product_id) + filtered_putaways = self.browse() + for put in putaway_strats: + try: + put.location_id.check_move_dest_constraint(product=product) + except ValidationError: + continue + filtered_putaways |= put + putaway_strats = filtered_putaways + return putaway_strats diff --git a/stock_move_location_dest_constraint_base/models/stock_location.py b/stock_move_location_dest_constraint_base/models/stock_location.py index c31bd9df2815..622a8de901d7 100644 --- a/stock_move_location_dest_constraint_base/models/stock_location.py +++ b/stock_move_location_dest_constraint_base/models/stock_location.py @@ -1,7 +1,6 @@ # Copyright 2019 Camptocamp SA # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) from odoo import api, models, fields -from odoo.exceptions import ValidationError class StockLocation(models.Model): @@ -20,19 +19,3 @@ def _set_bypass_on_existing_locations(self): """Set bypass_constrains on all the existing locations""" existing_locations = self.search([]) existing_locations.write({'bypass_constraints': True}) - - def filtered(self, func): - """Filter locations according to installed constraints""" - locations = super().filtered(func) - if self.env.context.get('_filter_on_constraints'): - product_id = self.env.context.get('_constraint_product') - product = self.env['product.product'].browse(product_id) - new_locations = self.browse() - for loc in locations: - try: - loc.check_move_dest_constraint(product=product) - except ValidationError: - continue - new_locations |= loc - locations = new_locations - return locations From 9aede696e17e8800d0675fc0b571fdf3c721e161 Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Fri, 6 Sep 2019 11:18:17 +0200 Subject: [PATCH 4/6] fixup! fixup! fixup! 12.0 create module stock move location dest constraint base --- .../models/product_strategy.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stock_move_location_dest_constraint_base/models/product_strategy.py b/stock_move_location_dest_constraint_base/models/product_strategy.py index 2218f6ab2b44..27d8e7a383e6 100644 --- a/stock_move_location_dest_constraint_base/models/product_strategy.py +++ b/stock_move_location_dest_constraint_base/models/product_strategy.py @@ -28,7 +28,9 @@ def filtered(self, func): filtered_putaways = self.browse() for put in putaway_strats: try: - put.location_id.check_move_dest_constraint(product=product) + put.fixed_location_id.check_move_dest_constraint( + product=product + ) except ValidationError: continue filtered_putaways |= put From f35bd9727e6ecd583731cdbf896081771a3b4761 Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Mon, 9 Sep 2019 15:15:33 +0200 Subject: [PATCH 5/6] Depend on stock_putaway_rule --- oca_dependencies.txt | 1 + .../__manifest__.py | 2 +- .../models/product_strategy.py | 26 +++++-------------- .../models/stock_location.py | 7 +++++ 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/oca_dependencies.txt b/oca_dependencies.txt index e4926f44a534..35f72bb42c2f 100644 --- a/oca_dependencies.txt +++ b/oca_dependencies.txt @@ -4,3 +4,4 @@ account-analytic product-attribute server-ux web +stock-logistics-warehouse https://github.com/grindtildeath/stock-logistics-warehouse 12.0_add_stock_putaway_rule diff --git a/stock_move_location_dest_constraint_base/__manifest__.py b/stock_move_location_dest_constraint_base/__manifest__.py index 70225de6d95e..8cc61b4c9014 100644 --- a/stock_move_location_dest_constraint_base/__manifest__.py +++ b/stock_move_location_dest_constraint_base/__manifest__.py @@ -12,7 +12,7 @@ "application": False, "installable": True, "depends": [ - "stock", + "stock_putaway_rule", ], "data": [ "data/stock_location.xml", diff --git a/stock_move_location_dest_constraint_base/models/product_strategy.py b/stock_move_location_dest_constraint_base/models/product_strategy.py index 27d8e7a383e6..4f98a583b072 100644 --- a/stock_move_location_dest_constraint_base/models/product_strategy.py +++ b/stock_move_location_dest_constraint_base/models/product_strategy.py @@ -4,35 +4,23 @@ from odoo.exceptions import ValidationError -class PutAwayStrategy(models.Model): - _inherit = 'product.putaway' - - def _get_putaway_rule(self, product): - """Activate constraint when looking for putaway rules""" - self = self.with_context( - _filter_on_constraints=True, _constraint_product=product.id - ) - return super()._get_putaway_rule(product) - - -class FixedPutAwayStrategy(models.Model): - - _inherit = 'stock.fixed.putaway.strat' +class StockPutawayRule(models.Model): + _inherit = 'stock.putaway.rule' def filtered(self, func): """Filter putaway strats according to installed constraints""" - putaway_strats = super().filtered(func) + putaway_rules = super().filtered(func) if self.env.context.get('_filter_on_constraints'): product_id = self.env.context.get('_constraint_product') product = self.env['product.product'].browse(product_id) filtered_putaways = self.browse() - for put in putaway_strats: + for put in putaway_rules: try: - put.fixed_location_id.check_move_dest_constraint( + put.location_out_id.check_move_dest_constraint( product=product ) except ValidationError: continue filtered_putaways |= put - putaway_strats = filtered_putaways - return putaway_strats + putaway_rules = filtered_putaways + return putaway_rules diff --git a/stock_move_location_dest_constraint_base/models/stock_location.py b/stock_move_location_dest_constraint_base/models/stock_location.py index 622a8de901d7..87adf8f3c2df 100644 --- a/stock_move_location_dest_constraint_base/models/stock_location.py +++ b/stock_move_location_dest_constraint_base/models/stock_location.py @@ -19,3 +19,10 @@ def _set_bypass_on_existing_locations(self): """Set bypass_constrains on all the existing locations""" existing_locations = self.search([]) existing_locations.write({'bypass_constraints': True}) + + def _get_putaway_strategy(self, product): + """Activate constraint when looking for putaway rules""" + self = self.with_context( + _filter_on_constraints=True, _constraint_product=product.id + ) + return super()._get_putaway_strategy(product) From d13fecca820ba017a14e2054e3e6a1a744cabc09 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Fri, 13 Sep 2019 16:49:59 +0200 Subject: [PATCH 6/6] Fix method name --- .../models/stock_location.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stock_move_location_dest_constraint_base/models/stock_location.py b/stock_move_location_dest_constraint_base/models/stock_location.py index 87adf8f3c2df..5025a9e4aa6c 100644 --- a/stock_move_location_dest_constraint_base/models/stock_location.py +++ b/stock_move_location_dest_constraint_base/models/stock_location.py @@ -20,9 +20,9 @@ def _set_bypass_on_existing_locations(self): existing_locations = self.search([]) existing_locations.write({'bypass_constraints': True}) - def _get_putaway_strategy(self, product): + def get_putaway_strategy(self, product): """Activate constraint when looking for putaway rules""" self = self.with_context( _filter_on_constraints=True, _constraint_product=product.id ) - return super()._get_putaway_strategy(product) + return super().get_putaway_strategy(product)