summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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()