fixup! fixup! 12.0 create module stock move location dest constraint base

This commit is contained in:
Akim Juillerat
2019-09-05 17:56:36 +02:00
parent fda3740295
commit 1aec0b60a5
2 changed files with 22 additions and 17 deletions

View File

@@ -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 @@ class PutAwayStrategy(models.Model):
_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

View File

@@ -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 @@ class StockLocation(models.Model):
"""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