mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
Depend on stock_putaway_rule
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
"application": False,
|
||||
"installable": True,
|
||||
"depends": [
|
||||
"stock",
|
||||
"stock_putaway_rule",
|
||||
],
|
||||
"data": [
|
||||
"data/stock_location.xml",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user