summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Lejeune <sle@openerp.com>2017-07-19 20:09:19 +0200
committerSimon Lejeune <sle@openerp.com>2017-07-19 20:09:19 +0200
commit0ae679e433ee4c5ca32ae1302d87d7fb33e0c78d (patch)
tree33ea5595a6e9470fd7112cbb402b4db84f13fc38
parent52c21bd53eced97d8471c2536e2c086611e7b43b (diff)
[FIX] stock: scrap and sublocations
Following the previous commit, it appears than the scrap mechanism needs some rigorousness when looking for quants characteristics (i.e. if we look for a quant without `lot_id`, it should not return one with one) but some flexibility with the location (i.e. we can look in sublocations to find one with the given characteristics). Before this commit, we centralized everything related to quant's search in stock_quant.py and the `_gather` method, which has a `strict` kw. As we exposed the `_get_quantity` method but is only used in stock_scrap, and that the `strict` flag does not fulfill the needs of stock_scrap, we inline the appropriate search, as it was done previously.
-rw-r--r--addons/stock/models/stock_quant.py6
-rw-r--r--addons/stock/models/stock_scrap.py11
2 files changed, 7 insertions, 10 deletions
diff --git a/addons/stock/models/stock_quant.py b/addons/stock/models/stock_quant.py
index 24f7a847dbf..15084292a5e 100644
--- a/addons/stock/models/stock_quant.py
+++ b/addons/stock/models/stock_quant.py
@@ -103,12 +103,6 @@ class StockQuant(models.Model):
return self.search(domain, order=removal_strategy_order)
@api.model
- def _get_quantity(self, product_id, location_id, lot_id=None, package_id=None, owner_id=None, strict=False):
- self = self.sudo()
- quants = self._gather(product_id, location_id, lot_id=lot_id, package_id=package_id, owner_id=owner_id, strict=strict)
- return sum(quants.mapped('quantity'))
-
- @api.model
def _get_available_quantity(self, product_id, location_id, lot_id=None, package_id=None, owner_id=None, strict=False):
""" Return the available quantity, i.e. the sum of `quantity` minus the sum of
`reserved_quantity`, for the set of quants sharing the combination of `product_id,
diff --git a/addons/stock/models/stock_scrap.py b/addons/stock/models/stock_scrap.py
index 839987cee2e..4eba509a8de 100644
--- a/addons/stock/models/stock_scrap.py
+++ b/addons/stock/models/stock_scrap.py
@@ -80,10 +80,13 @@ class StockScrap(models.Model):
for scrap in self:
move = self.env['stock.move'].create(scrap._prepare_move_values())
if self.product_id.type == 'product':
- quantity_in_stock = self.env['stock.quant']._get_quantity(
- self.product_id, self.location_id, lot_id=self.lot_id,
- package_id=self.package_id, owner_id=self.owner_id, strict=True
- )
+ quantity_in_stock = sum(self.env['stock.quant'].search([
+ ('product_id', '=', self.product_id.id),
+ ('lot_id', '=', self.lot_id and self.lot_id.id or False),
+ ('package_id', '=', self.package_id and self.package_id.id or False),
+ ('owner_id', '=', self.owner_id and self.owner_id.id or False),
+ ('location_id', 'child_of', self.location_id.id)
+ ]).mapped('quantity'))
if quantity_in_stock < move.product_qty: # FIXME: float compare
raise UserError(_('You cannot scrap a move without having available stock for %s. You can correct it with an inventory adjustment.') % move.product_id.name)
move.action_done()