Depend on stock_putaway_rule

This commit is contained in:
Akim Juillerat
2019-09-09 15:15:33 +02:00
parent 9aede696e1
commit f35bd9727e
4 changed files with 16 additions and 20 deletions

View File

@@ -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

View File

@@ -12,7 +12,7 @@
"application": False,
"installable": True,
"depends": [
"stock",
"stock_putaway_rule",
],
"data": [
"data/stock_location.xml",

View File

@@ -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

View File

@@ -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)