From f35bd9727e6ecd583731cdbf896081771a3b4761 Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Mon, 9 Sep 2019 15:15:33 +0200 Subject: [PATCH] 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 e4926f44a..35f72bb42 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 70225de6d..8cc61b4c9 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 27d8e7a38..4f98a583b 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 import models 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 622a8de90..87adf8f3c 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 @@ class StockLocation(models.Model): """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)