diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 68ef37c5e8c..056e259b1a0 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -674,7 +674,7 @@ class StockMove(models.Model): ) return vals - def _increase_reserved_quantity(self, need, available_quantity, location_id, lot_id=None, package_id=None, owner_id=None, strict=True): + def _update_reserved_quantity(self, need, available_quantity, location_id, lot_id=None, package_id=None, owner_id=None, strict=True): """ Create or update move lines. """ self.ensure_one() @@ -689,7 +689,7 @@ class StockMove(models.Model): taken_quantity = min(available_quantity, need) # Find a candidate move line to update or create a new one. - quants = self.env['stock.quant']._increase_reserved_quantity( + quants = self.env['stock.quant']._update_reserved_quantity( self.product_id, location_id, taken_quantity, lot_id=lot_id, package_id=package_id, owner_id=owner_id, strict=strict ) @@ -733,7 +733,7 @@ class StockMove(models.Model): if available_quantity <= 0: continue need = move.product_qty - move.reserved_availability - taken_quantity = move._increase_reserved_quantity(need, available_quantity, move.location_id, strict=False) + taken_quantity = move._update_reserved_quantity(need, available_quantity, move.location_id, strict=False) if need == taken_quantity: move.state = 'assigned' else: @@ -770,7 +770,7 @@ class StockMove(models.Model): available_move_lines[(move_line.location_id, move_line.lot_id, move_line.result_package_id, move_line.owner_id)] -= move_line.product_qty for (location_id, lot_id, package_id, owner_id), quantity in available_move_lines.items(): need = move.product_qty - sum(move.move_line_ids.mapped('product_qty')) - taken_quantity = move._increase_reserved_quantity(need, quantity, location_id, lot_id, package_id, owner_id) + taken_quantity = move._update_reserved_quantity(need, quantity, location_id, lot_id, package_id, owner_id) if need - taken_quantity == 0.0: move.state = 'assigned' break diff --git a/addons/stock/models/stock_move_line.py b/addons/stock/models/stock_move_line.py index 5d4e24b24a9..c2768c11a27 100644 --- a/addons/stock/models/stock_move_line.py +++ b/addons/stock/models/stock_move_line.py @@ -99,16 +99,16 @@ class StockMoveLine(models.Model): Quant = self.env['stock.quant'] quantity = ml.product_uom_id._compute_quantity(ml.qty_done, ml.move_id.product_id.uom_id,rounding_method='HALF-UP') if ml.location_id.should_impact_quants() and ml.product_id.type == 'product': - available_qty = Quant._decrease_available_quantity(ml.product_id, ml.location_id, quantity, lot_id=ml.lot_id, package_id=ml.package_id, owner_id=ml.owner_id) + available_qty = Quant._update_available_quantity(ml.product_id, ml.location_id, -quantity, lot_id=ml.lot_id, package_id=ml.package_id, owner_id=ml.owner_id) if available_qty < 0 and ml.lot_id: # see if we can compensate the negative quants with some untracked quants untracked_qty = Quant._get_available_quantity(ml.product_id, ml.location_id, lot_id=False, package_id=ml.package_id, owner_id=ml.owner_id, strict=True) if untracked_qty: taken_from_untracked_qty = min(untracked_qty, abs(quantity)) - Quant._decrease_available_quantity(ml.product_id, ml.location_id, taken_from_untracked_qty, lot_id=False, package_id=ml.package_id, owner_id=ml.owner_id) - Quant._increase_available_quantity(ml.product_id, ml.location_id, taken_from_untracked_qty, lot_id=ml.lot_id, package_id=ml.package_id, owner_id=ml.owner_id) + Quant._update_available_quantity(ml.product_id, ml.location_id, -taken_from_untracked_qty, lot_id=False, package_id=ml.package_id, owner_id=ml.owner_id) + Quant._update_available_quantity(ml.product_id, ml.location_id, taken_from_untracked_qty, lot_id=ml.lot_id, package_id=ml.package_id, owner_id=ml.owner_id) if ml.location_dest_id.should_impact_quants() and ml.product_id.type == 'product': - Quant._increase_available_quantity(ml.product_id, ml.location_dest_id, quantity, lot_id=ml.lot_id, package_id=ml.result_package_id, owner_id=ml.owner_id) + Quant._update_available_quantity(ml.product_id, ml.location_dest_id, quantity, lot_id=ml.lot_id, package_id=ml.result_package_id, owner_id=ml.owner_id) next_moves = ml.move_id.move_dest_ids.filtered(lambda move: move.state not in ('done', 'cancel')) next_moves.do_unreserve() next_moves.action_assign() @@ -132,10 +132,10 @@ class StockMoveLine(models.Model): if ml.location_id.should_impact_quants() and ml.product_id.type == 'product': qty_to_decrease = ml.product_qty - ml.product_uom_id._compute_quantity(vals['product_uom_qty'], ml.product_id.uom_id, rounding_method='HALF-UP') try: - Quant._decrease_reserved_quantity(ml.product_id, ml.location_id, qty_to_decrease, lot_id=ml.lot_id, package_id=ml.package_id, owner_id=ml.owner_id) + Quant._update_reserved_quantity(ml.product_id, ml.location_id, -qty_to_decrease, lot_id=ml.lot_id, package_id=ml.package_id, owner_id=ml.owner_id) except UserError: if ml.lot_id: - Quant._decrease_reserved_quantity(ml.product_id, ml.location_id, qty_to_decrease, lot_id=False, package_id=ml.package_id, owner_id=ml.owner_id) + Quant._update_reserved_quantity(ml.product_id, ml.location_id, -qty_to_decrease, lot_id=False, package_id=ml.package_id, owner_id=ml.owner_id) else: raise @@ -156,24 +156,24 @@ class StockMoveLine(models.Model): for ml in self.filtered(lambda ml: ml.state in ['partially_available', 'assigned']): if ml.location_id.should_impact_quants() and ml.product_id.type == 'product': try: - Quant._decrease_reserved_quantity(ml.product_id, ml.location_id, ml.product_qty, lot_id=ml.lot_id, package_id=ml.package_id, owner_id=ml.owner_id) + Quant._update_reserved_quantity(ml.product_id, ml.location_id, -ml.product_qty, lot_id=ml.lot_id, package_id=ml.package_id, owner_id=ml.owner_id) except UserError: if ml.lot_id: - Quant._decrease_reserved_quantity(ml.product_id, ml.location_id, ml.product_qty, lot_id=False, package_id=ml.package_id, owner_id=ml.owner_id) + Quant._update_reserved_quantity(ml.product_id, ml.location_id, -ml.product_qty, lot_id=False, package_id=ml.package_id, owner_id=ml.owner_id) else: raise if updates.get('location_id', ml.location_id).should_impact_quants() and ml.product_id.type == 'product': new_product_qty = 0 try: - q = Quant._increase_reserved_quantity(ml.product_id, updates.get('location_id', ml.location_id), ml.product_qty, lot_id=updates.get('lot_id', ml.lot_id), + q = Quant._update_reserved_quantity(ml.product_id, updates.get('location_id', ml.location_id), ml.product_qty, lot_id=updates.get('lot_id', ml.lot_id), package_id=updates.get('package_id', ml.package_id), owner_id=updates.get('owner_id', ml.owner_id), strict=True) new_product_qty = sum([x[1] for x in q]) except UserError: if updates.get('lot_id'): # If we were not able to reserve on tracked quants, we can use untracked ones. try: - q = Quant._increase_reserved_quantity(ml.product_id, updates.get('location_id', ml.location_id), ml.product_qty, lot_id=False, + q = Quant._update_reserved_quantity(ml.product_id, updates.get('location_id', ml.location_id), ml.product_qty, lot_id=False, package_id=updates.get('package_id', ml.package_id), owner_id=updates.get('owner_id', ml.owner_id), strict=True) new_product_qty = sum([x[1] for x in q]) except UserError: @@ -188,10 +188,10 @@ class StockMoveLine(models.Model): for ml in self.filtered(lambda ml: ml.move_id.state == 'done'): # undo the original move line if ml.location_dest_id.should_impact_quants() and ml.product_id.type == 'product': - Quant._decrease_available_quantity(ml.product_id, ml.location_dest_id, ml.qty_done, lot_id=ml.lot_id, + Quant._update_available_quantity(ml.product_id, ml.location_dest_id, -ml.qty_done, lot_id=ml.lot_id, package_id=ml.package_id, owner_id=ml.owner_id) if ml.location_id.should_impact_quants() and ml.product_id.type == 'product': - Quant._increase_available_quantity(ml.product_id, ml.location_id, ml.qty_done, lot_id=ml.lot_id, + Quant._update_available_quantity(ml.product_id, ml.location_id, ml.qty_done, lot_id=ml.lot_id, package_id=ml.package_id, owner_id=ml.owner_id) # move what's been actually done @@ -206,17 +206,17 @@ class StockMoveLine(models.Model): quantity = ml.move_id.product_uom._compute_quantity(qty_done, ml.move_id.product_id.uom_id, rounding_method='HALF-UP') if location_id.should_impact_quants() and ml.product_id.type == 'product': ml._free_reservation(product_id, location_id, quantity, lot_id=lot_id, package_id=package_id, owner_id=owner_id) - available_qty = Quant._decrease_available_quantity(product_id, location_id, quantity, lot_id=lot_id, package_id=package_id, owner_id=owner_id) + available_qty = Quant._update_available_quantity(product_id, location_id, -quantity, lot_id=lot_id, package_id=package_id, owner_id=owner_id) if available_qty < 0 and lot_id: # see if we can compensate the negative quants with some untracked quants untracked_qty = Quant._get_available_quantity(product_id, location_id, lot_id=False, package_id=package_id, owner_id=owner_id, strict=True) if untracked_qty: taken_from_untracked_qty = min(untracked_qty, abs(available_qty)) - Quant._decrease_available_quantity(product_id, location_id, taken_from_untracked_qty, lot_id=False, package_id=package_id, owner_id=owner_id) - Quant._increase_available_quantity(product_id, location_id, taken_from_untracked_qty, lot_id=lot_id, package_id=package_id, owner_id=owner_id) + Quant._update_available_quantity(product_id, location_id, -taken_from_untracked_qty, lot_id=False, package_id=package_id, owner_id=owner_id) + Quant._update_available_quantity(product_id, location_id, taken_from_untracked_qty, lot_id=lot_id, package_id=package_id, owner_id=owner_id) ml._free_reservation(ml.product_id, location_id, untracked_qty, lot_id=False, package_id=package_id, owner_id=owner_id) if location_dest_id.should_impact_quants() and ml.product_id.type == 'product' and qty_done: - Quant._increase_available_quantity(product_id, location_dest_id, quantity, lot_id=lot_id, package_id=result_package_id, owner_id=owner_id) + Quant._update_available_quantity(product_id, location_dest_id, quantity, lot_id=lot_id, package_id=result_package_id, owner_id=owner_id) # Unreserve and reserve following move in order to have the real reserved quantity on move_line. next_moves |= ml.move_id.move_dest_ids.filtered(lambda move: move.state not in ('done', 'cancel')) res = super(StockMoveLine, self).write(vals) @@ -232,7 +232,7 @@ class StockMoveLine(models.Model): raise UserError(_('You can not delete pack operations of a done picking')) # Unlinking a pack operation should unreserve. if ml.location_id.should_impact_quants() and ml.product_id.type == 'product' and not float_is_zero(ml.product_qty, precision_digits=precision): - self.env['stock.quant']._decrease_reserved_quantity(ml.product_id, ml.location_id, ml.product_qty, lot_id=ml.lot_id, + self.env['stock.quant']._update_reserved_quantity(ml.product_id, ml.location_id, -ml.product_qty, lot_id=ml.lot_id, package_id=ml.package_id, owner_id=ml.owner_id) return super(StockMoveLine, self).unlink() @@ -252,23 +252,23 @@ class StockMoveLine(models.Model): # unreserve what's been reserved if ml.location_id.should_impact_quants() and ml.product_id.type == 'product' and ml.product_qty: try: - Quant._decrease_reserved_quantity(ml.product_id, ml.location_id, ml.product_qty, lot_id=ml.lot_id, package_id=ml.package_id, owner_id=ml.owner_id) + Quant._update_reserved_quantity(ml.product_id, ml.location_id, -ml.product_qty, lot_id=ml.lot_id, package_id=ml.package_id, owner_id=ml.owner_id) except UserError: - Quant._decrease_reserved_quantity(ml.product_id, ml.location_id, ml.product_qty, lot_id=False, package_id=ml.package_id, owner_id=ml.owner_id) + Quant._update_reserved_quantity(ml.product_id, ml.location_id, -ml.product_qty, lot_id=False, package_id=ml.package_id, owner_id=ml.owner_id) # move what's been actually done quantity = ml.product_uom_id._compute_quantity(ml.qty_done, ml.move_id.product_id.uom_id, rounding_method='HALF-UP') if ml.location_id.should_impact_quants() and ml.product_id.type == 'product': - available_qty = Quant._decrease_available_quantity(ml.product_id, ml.location_id, quantity, lot_id=ml.lot_id, package_id=ml.package_id, owner_id=ml.owner_id) + available_qty = Quant._update_available_quantity(ml.product_id, ml.location_id, -quantity, lot_id=ml.lot_id, package_id=ml.package_id, owner_id=ml.owner_id) if available_qty < 0 and ml.lot_id: # see if we can compensate the negative quants with some untracked quants untracked_qty = Quant._get_available_quantity(ml.product_id, ml.location_id, lot_id=False, package_id=ml.package_id, owner_id=ml.owner_id, strict=True) if untracked_qty: taken_from_untracked_qty = min(untracked_qty, abs(quantity)) - Quant._decrease_available_quantity(ml.product_id, ml.location_id, taken_from_untracked_qty, lot_id=False, package_id=ml.package_id, owner_id=ml.owner_id) - Quant._increase_available_quantity(ml.product_id, ml.location_id, taken_from_untracked_qty, lot_id=ml.lot_id, package_id=ml.package_id, owner_id=ml.owner_id) + Quant._update_available_quantity(ml.product_id, ml.location_id, -taken_from_untracked_qty, lot_id=False, package_id=ml.package_id, owner_id=ml.owner_id) + Quant._update_available_quantity(ml.product_id, ml.location_id, taken_from_untracked_qty, lot_id=ml.lot_id, package_id=ml.package_id, owner_id=ml.owner_id) if ml.location_dest_id.should_impact_quants() and ml.product_id.type == 'product': - Quant._increase_available_quantity(ml.product_id, ml.location_dest_id, quantity, lot_id=ml.lot_id, package_id=ml.result_package_id, owner_id=ml.owner_id) + Quant._update_available_quantity(ml.product_id, ml.location_dest_id, quantity, lot_id=ml.lot_id, package_id=ml.result_package_id, owner_id=ml.owner_id) def _free_reservation(self, product_id, location_id, quantity, lot_id=None, package_id=None, owner_id=None): """ When editing a done move line or validating one with some forced quantities, it is diff --git a/addons/stock/models/stock_quant.py b/addons/stock/models/stock_quant.py index 383b6bfedeb..a45d5668030 100644 --- a/addons/stock/models/stock_quant.py +++ b/addons/stock/models/stock_quant.py @@ -131,7 +131,7 @@ class StockQuant(models.Model): return sum(quants.mapped('quantity')) - sum(quants.mapped('reserved_quantity')) @api.model - def _increase_available_quantity(self, product_id, location_id, quantity, lot_id=None, package_id=None, owner_id=None, strict=True): + def _update_available_quantity(self, product_id, location_id, quantity, lot_id=None, package_id=None, owner_id=None, strict=True): self = self.sudo() quants = self._gather(product_id, location_id, lot_id=lot_id, package_id=package_id, owner_id=owner_id, strict=strict) for quant in quants: @@ -160,11 +160,7 @@ class StockQuant(models.Model): return self._get_available_quantity(product_id, location_id, lot_id=lot_id, package_id=package_id, owner_id=owner_id, strict=strict) @api.model - def _decrease_available_quantity(self, product_id, location_id, quantity, lot_id=None, package_id=None, owner_id=None, strict=True): - return self._increase_available_quantity(product_id, location_id, -quantity, lot_id=lot_id, package_id=package_id, owner_id=owner_id, strict=strict) - - @api.model - def _increase_reserved_quantity(self, product_id, location_id, quantity, lot_id=None, package_id=None, owner_id=None, strict=False): + def _update_reserved_quantity(self, product_id, location_id, quantity, lot_id=None, package_id=None, owner_id=None, strict=False): """ Increase the reserved quantity, i.e. increase `reserved_quantity` for the set of quants sharing the combination of `product_id, location_id` if `strict` is set to False or sharing the *exact same characteristics* otherwise. Typically, this method is called when reserving @@ -206,19 +202,6 @@ class StockQuant(models.Model): break return reserved_quants - @api.model - def _decrease_reserved_quantity(self, product_id, location_id, quantity, lot_id=None, package_id=None, owner_id=None, strict=True): - """ Decrease the reserved quantity, i.e. decrease `reserved_quantity`, for the set of - quants sharing the *exact same characteristics* if `strict` is set to True or sharing the - combination of `product_id, location_id` otherwise. Typically, this method is called during - a move line's validation or a move line's unlink and `strict` should be `True` in these - cases, because the characteristics are known. - - :return: a list of tuples (quant, quantity_unreserved) showing on which quant the decrease - of reservation was done and how much the system was able to unreserve on it - """ - return self._increase_reserved_quantity(product_id, location_id, -quantity, lot_id=lot_id, package_id=package_id, owner_id=owner_id, strict=strict) - class QuantPackage(models.Model): """ Packages containing quants and/or other packages """ diff --git a/addons/stock/tests/test_inventory.py b/addons/stock/tests/test_inventory.py index c9a40aa9038..9b627c85e41 100644 --- a/addons/stock/tests/test_inventory.py +++ b/addons/stock/tests/test_inventory.py @@ -26,7 +26,7 @@ class TestInventory(TransactionCase): as expected. """ # make some stock - self.env['stock.quant']._increase_available_quantity(self.product1, self.stock_location, 100) + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 100) self.assertEqual(len(self.env['stock.quant']._gather(self.product1, self.stock_location)), 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 100.0) diff --git a/addons/stock/tests/test_move.py b/addons/stock/tests/test_move.py index 3c1a87e1518..3e072b692b4 100644 --- a/addons/stock/tests/test_move.py +++ b/addons/stock/tests/test_move.py @@ -164,7 +164,7 @@ class StockMove(TransactionCase): stock and that the delivery correctly remove the single quant in stock. """ # make some stock - self.env['stock.quant']._increase_available_quantity(self.product1, self.stock_location, 100) + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 100) self.assertEqual(len(self.env['stock.quant']._gather(self.product1, self.stock_location)), 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 100.0) @@ -265,8 +265,8 @@ class StockMove(TransactionCase): 'name': 'lot1', 'product_id': self.product3.id, }) - self.env['stock.quant']._increase_available_quantity(self.product3, self.stock_location, 2) - self.env['stock.quant']._increase_available_quantity(self.product3, self.stock_location, 3, lot_id=lot1) + self.env['stock.quant']._update_available_quantity(self.product3, self.stock_location, 2) + self.env['stock.quant']._update_available_quantity(self.product3, self.stock_location, 3, lot_id=lot1) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product3, self.stock_location), 5.0) # creation @@ -297,9 +297,9 @@ class StockMove(TransactionCase): 'name': 'lot2', 'product_id': self.product2.id, }) - self.env['stock.quant']._increase_available_quantity(self.product2, self.stock_location, 2) - self.env['stock.quant']._increase_available_quantity(self.product2, self.stock_location, 1, lot_id=lot1) - self.env['stock.quant']._increase_available_quantity(self.product2, self.stock_location, 1, lot_id=lot2) + self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 2) + self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 1, lot_id=lot1) + self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 1, lot_id=lot2) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location), 4.0) # creation @@ -363,8 +363,8 @@ class StockMove(TransactionCase): 'name': 'lot2', 'product_id': self.product2.id, }) - self.env['stock.quant']._increase_available_quantity(self.product2, self.stock_location, 1, lot_id=lot1) - self.env['stock.quant']._increase_available_quantity(self.product2, self.stock_location, 1, lot_id=lot2) + self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 1, lot_id=lot1) + self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 1, lot_id=lot2) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location), 2.0) # creation @@ -381,7 +381,7 @@ class StockMove(TransactionCase): move1.move_line_ids.write({'qty_done': 1.0}) move1.action_done() - self.env['stock.quant']._increase_available_quantity(self.product2, self.stock_location, 2) + self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 2) lot3 = self.env['stock.production.lot'].create({ 'name': 'lot3', 'product_id': self.product2.id, @@ -430,8 +430,8 @@ class StockMove(TransactionCase): 'name': 'lot2', 'product_id': self.product2.id, }) - self.env['stock.quant']._increase_available_quantity(self.product2, self.stock_location, 1, lot_id=lot1) - self.env['stock.quant']._increase_available_quantity(self.product2, self.stock_location, 1, lot_id=lot2) + self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 1, lot_id=lot1) + self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 1, lot_id=lot2) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location), 2.0) # creation @@ -452,7 +452,7 @@ class StockMove(TransactionCase): self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location, lot_id=lot1, strict=True), 0.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location, lot_id=lot2, strict=True), 0.0) - self.env['stock.quant']._increase_available_quantity(self.product2, self.stock_location, 1) + self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 1) lot3 = self.env['stock.production.lot'].create({ 'name': 'lot3', 'product_id': self.product2.id, @@ -479,7 +479,7 @@ class StockMove(TransactionCase): self.assertEqual(move1.state, 'confirmed') # create an untracked quant - self.env['stock.quant']._increase_available_quantity(self.product2, self.stock_location, 1.0) + self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 1.0) lot1 = self.env['stock.production.lot'].create({ 'name': 'lot1', 'product_id': self.product2.id, @@ -505,7 +505,7 @@ class StockMove(TransactionCase): def test_mixed_tracking_reservation_6(self): # create an untracked quant - self.env['stock.quant']._increase_available_quantity(self.product2, self.stock_location, 1.0) + self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 1.0) move1 = self.env['stock.move'].create({ 'name': 'test_jenaimarre_1', 'location_id': self.stock_location.id, @@ -586,7 +586,7 @@ class StockMove(TransactionCase): more than enough products in stock. """ # make some stock - self.env['stock.quant']._increase_available_quantity(self.product1, self.stock_location, 150.0) + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 150.0) self.assertEqual(len(self.env['stock.quant']._gather(self.product1, self.stock_location)), 1.0) move1 = self.env['stock.move'].create({ @@ -607,7 +607,7 @@ class StockMove(TransactionCase): not enough products in stock. """ # make some stock - self.env['stock.quant']._increase_available_quantity(self.product1, self.stock_location, 50.0) + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 50.0) self.assertEqual(len(self.env['stock.quant']._gather(self.product1, self.stock_location)), 1.0) move1 = self.env['stock.move'].create({ @@ -628,7 +628,7 @@ class StockMove(TransactionCase): set the state back to confirmed. """ # make some stock - self.env['stock.quant']._increase_available_quantity(self.product1, self.stock_location, 150.0) + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 150.0) # creation move1 = self.env['stock.move'].create({ @@ -666,7 +666,7 @@ class StockMove(TransactionCase): package1 = self.env['stock.quant.package'].create({'name': 'test_unreserve_2_pack'}) # make some stock - self.env['stock.quant']._increase_available_quantity(self.product1, self.stock_location, 150.0, package_id=package1) + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 150.0, package_id=package1) # creation move1 = self.env['stock.move'].create({ @@ -701,7 +701,7 @@ class StockMove(TransactionCase): """ Similar to `test_unreserve_1` but checking the quants more in details. """ # make some stock - self.env['stock.quant']._increase_available_quantity(self.product1, self.stock_location, 2) + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 2) self.assertEqual(len(self.env['stock.quant']._gather(self.product1, self.stock_location)), 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 2) @@ -742,7 +742,7 @@ class StockMove(TransactionCase): """ Check the unreservation of a partially available stock move. """ # make some stock - self.env['stock.quant']._increase_available_quantity(self.product1, self.stock_location, 2) + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 2) self.assertEqual(len(self.env['stock.quant']._gather(self.product1, self.stock_location)), 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 2) @@ -784,7 +784,7 @@ class StockMove(TransactionCase): untracked product. """ # make some stock - self.env['stock.quant']._increase_available_quantity(self.product1, self.stock_location, 1.0) + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0) self.assertEqual(len(self.env['stock.quant']._gather(self.product1, self.stock_location)), 1.0) move_stock_pack = self.env['stock.move'].create({ @@ -826,7 +826,7 @@ class StockMove(TransactionCase): }) # make some stock - self.env['stock.quant']._increase_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot1) + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot1) self.assertEqual(len(self.env['stock.quant']._gather(self.product1, self.stock_location, lot1)), 1.0) move_stock_pack = self.env['stock.move'].create({ @@ -872,7 +872,7 @@ class StockMove(TransactionCase): move multiple units of an untracked product. """ # make some stock - self.env['stock.quant']._increase_available_quantity(self.product1, self.stock_location, 2.0) + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 2.0) self.assertEqual(len(self.env['stock.quant']._gather(self.product1, self.stock_location)), 1.0) move_stock_pack_1 = self.env['stock.move'].create({ @@ -948,7 +948,7 @@ class StockMove(TransactionCase): }) # make some stock - self.env['stock.quant']._increase_available_quantity(self.product1, self.stock_location, 2.0, lot_id=lot1) + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 2.0, lot_id=lot1) self.assertEqual(len(self.env['stock.quant']._gather(self.product1, self.stock_location, lot1)), 1.0) move_stock_pack_1 = self.env['stock.move'].create({ @@ -1010,7 +1010,7 @@ class StockMove(TransactionCase): move multiple units of an untracked product. """ # make some stock - self.env['stock.quant']._increase_available_quantity(self.product1, self.stock_location, 2.0) + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 2.0) move_stock_pack = self.env['stock.move'].create({ 'name': 'test_link_assign_1_1', @@ -1118,7 +1118,7 @@ class StockMove(TransactionCase): correctly unreserves the other one. """ # make some stock - self.env['stock.quant']._increase_available_quantity(self.product1, self.stock_location, 1.0) + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0) # prepare the conflicting move move1 = self.env['stock.move'].create({ @@ -1179,7 +1179,7 @@ class StockMove(TransactionCase): }) # make some stock - self.env['stock.quant']._increase_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot1) + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot1) # prepare the conflicting move move1 = self.env['stock.move'].create({ @@ -1245,8 +1245,8 @@ class StockMove(TransactionCase): 'usage': 'internal', 'location_id': self.stock_location.id, }) - self.env['stock.quant']._increase_available_quantity(self.product1, shelf1_location, 1.0) - self.env['stock.quant']._increase_available_quantity(self.product1, shelf2_location, 1.0) + self.env['stock.quant']._update_available_quantity(self.product1, shelf1_location, 1.0) + self.env['stock.quant']._update_available_quantity(self.product1, shelf2_location, 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf1_location), 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf2_location), 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 2.0) @@ -1285,8 +1285,8 @@ class StockMove(TransactionCase): 'name': 'lot2', 'product_id': self.product1.id, }) - self.env['stock.quant']._increase_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot1) - self.env['stock.quant']._increase_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot2) + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot1) + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot2) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 2.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot1), 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot2), 1.0) @@ -1321,8 +1321,8 @@ class StockMove(TransactionCase): package1 = self.env['stock.quant.package'].create({'name': 'test_edit_reserved_move_line_3'}) package2 = self.env['stock.quant.package'].create({'name': 'test_edit_reserved_move_line_3'}) - self.env['stock.quant']._increase_available_quantity(self.product1, self.stock_location, 1.0, package_id=package1) - self.env['stock.quant']._increase_available_quantity(self.product1, self.stock_location, 1.0, package_id=package2) + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, package_id=package1) + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, package_id=package2) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 2.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, package_id=package1), 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, package_id=package2), 1.0) @@ -1356,8 +1356,8 @@ class StockMove(TransactionCase): owner1 = self.env['res.partner'].create({'name': 'test_edit_reserved_move_line_4_1'}) owner2 = self.env['res.partner'].create({'name': 'test_edit_reserved_move_line_4_2'}) - self.env['stock.quant']._increase_available_quantity(self.product1, self.stock_location, 1.0, owner_id=owner1) - self.env['stock.quant']._increase_available_quantity(self.product1, self.stock_location, 1.0, owner_id=owner2) + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, owner_id=owner1) + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, owner_id=owner2) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 2.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, owner_id=owner1), 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, owner_id=owner2), 1.0) @@ -1399,8 +1399,8 @@ class StockMove(TransactionCase): }) package1 = self.env['stock.quant.package'].create({'name': 'test_edit_reserved_move_line_5'}) - self.env['stock.quant']._increase_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot1, package_id=package1) - self.env['stock.quant']._increase_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot2) + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot1, package_id=package1) + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot2) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 2.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot1, package_id=package1), 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot2), 1.0) @@ -1442,7 +1442,7 @@ class StockMove(TransactionCase): 'usage': 'internal', 'location_id': self.stock_location.id, }) - self.env['stock.quant']._increase_available_quantity(self.product1, shelf1_location, 1.0) + self.env['stock.quant']._update_available_quantity(self.product1, shelf1_location, 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf1_location), 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf2_location), 0.0) @@ -1481,7 +1481,7 @@ class StockMove(TransactionCase): 'product_id': self.product3.id, }) # make some stock without assigning a lot id - self.env['stock.quant']._increase_available_quantity(self.product3, self.stock_location, 5) + self.env['stock.quant']._update_available_quantity(self.product3, self.stock_location, 5) # creation move1 = self.env['stock.move'].create({ @@ -1533,8 +1533,8 @@ class StockMove(TransactionCase): 'product_id': self.product3.id, }) # make some stock without assigning a lot id - self.env['stock.quant']._increase_available_quantity(self.product3, self.stock_location, 3) - self.env['stock.quant']._increase_available_quantity(self.product3, self.stock_location, 2, lot_id=lot1) + self.env['stock.quant']._update_available_quantity(self.product3, self.stock_location, 3) + self.env['stock.quant']._update_available_quantity(self.product3, self.stock_location, 2, lot_id=lot1) # creation move1 = self.env['stock.move'].create({ @@ -1600,8 +1600,8 @@ class StockMove(TransactionCase): 'usage': 'internal', 'location_id': self.stock_location.id, }) - self.env['stock.quant']._increase_available_quantity(self.product1, shelf1_location, 1.0) - self.env['stock.quant']._increase_available_quantity(self.product1, shelf2_location, 1.0) + self.env['stock.quant']._update_available_quantity(self.product1, shelf1_location, 1.0) + self.env['stock.quant']._update_available_quantity(self.product1, shelf2_location, 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf1_location), 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf2_location), 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 2.0) @@ -1643,8 +1643,8 @@ class StockMove(TransactionCase): 'name': 'lot2', 'product_id': self.product1.id, }) - self.env['stock.quant']._increase_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot1) - self.env['stock.quant']._increase_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot2) + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot1) + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot2) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 2.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot1), 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot2), 1.0) @@ -1680,8 +1680,8 @@ class StockMove(TransactionCase): package1 = self.env['stock.quant.package'].create({'name': 'test_edit_reserved_move_line_3'}) package2 = self.env['stock.quant.package'].create({'name': 'test_edit_reserved_move_line_3'}) - self.env['stock.quant']._increase_available_quantity(self.product1, self.stock_location, 1.0, package_id=package1) - self.env['stock.quant']._increase_available_quantity(self.product1, self.stock_location, 1.0, package_id=package2) + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, package_id=package1) + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, package_id=package2) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 2.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, package_id=package1), 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, package_id=package2), 1.0) @@ -1716,8 +1716,8 @@ class StockMove(TransactionCase): owner1 = self.env['res.partner'].create({'name': 'test_edit_reserved_move_line_4_1'}) owner2 = self.env['res.partner'].create({'name': 'test_edit_reserved_move_line_4_2'}) - self.env['stock.quant']._increase_available_quantity(self.product1, self.stock_location, 1.0, owner_id=owner1) - self.env['stock.quant']._increase_available_quantity(self.product1, self.stock_location, 1.0, owner_id=owner2) + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, owner_id=owner1) + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, owner_id=owner2) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 2.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, owner_id=owner1), 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, owner_id=owner2), 1.0) @@ -1760,8 +1760,8 @@ class StockMove(TransactionCase): }) package1 = self.env['stock.quant.package'].create({'name': 'test_edit_reserved_move_line_5'}) - self.env['stock.quant']._increase_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot1, package_id=package1) - self.env['stock.quant']._increase_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot2) + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot1, package_id=package1) + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot2) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 2.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot1, package_id=package1), 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot2), 1.0) @@ -1804,7 +1804,7 @@ class StockMove(TransactionCase): 'usage': 'internal', 'location_id': self.stock_location.id, }) - self.env['stock.quant']._increase_available_quantity(self.product1, shelf1_location, 1.0) + self.env['stock.quant']._update_available_quantity(self.product1, shelf1_location, 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf1_location), 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf2_location), 0.0) @@ -1848,8 +1848,8 @@ class StockMove(TransactionCase): 'usage': 'internal', 'location_id': self.stock_location.id, }) - self.env['stock.quant']._increase_available_quantity(self.product1, shelf1_location, 1.0) - self.env['stock.quant']._increase_available_quantity(self.product1, shelf2_location, 1.0) + self.env['stock.quant']._update_available_quantity(self.product1, shelf1_location, 1.0) + self.env['stock.quant']._update_available_quantity(self.product1, shelf2_location, 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 2.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf1_location), 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf2_location), 1.0) @@ -1900,7 +1900,7 @@ class StockMove(TransactionCase): 'usage': 'internal', 'location_id': self.stock_location.id, }) - self.env['stock.quant']._increase_available_quantity(self.product1, shelf1_location, 1.0) + self.env['stock.quant']._update_available_quantity(self.product1, shelf1_location, 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf1_location), 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 1.0) @@ -1936,7 +1936,7 @@ class StockMove(TransactionCase): 'usage': 'internal', 'location_id': self.stock_location.id, }) - self.env['stock.quant']._increase_available_quantity(self.product1, shelf1_location, 1.0) + self.env['stock.quant']._update_available_quantity(self.product1, shelf1_location, 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf1_location), 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 1.0) @@ -2065,7 +2065,7 @@ class StockMove(TransactionCase): remaining quantity. """ owner = self.env['res.partner'].create({'name': 'Jean'}) - self.env['stock.quant']._increase_available_quantity(self.product1, self.stock_location, 5.0) + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 5.0) picking = self.env['stock.picking'].create({ 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, @@ -2146,7 +2146,7 @@ class StockMove(TransactionCase): 'name': 'lot1', 'product_id': self.product3.id, }) - self.env['stock.quant']._increase_available_quantity(self.product3, self.stock_location, 5.0, lot_id=lot1) + self.env['stock.quant']._update_available_quantity(self.product3, self.stock_location, 5.0, lot_id=lot1) picking = self.env['stock.picking'].create({ 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, diff --git a/addons/stock/tests/test_move2.py b/addons/stock/tests/test_move2.py index 6a0f6ff86bd..cd362545c86 100644 --- a/addons/stock/tests/test_move2.py +++ b/addons/stock/tests/test_move2.py @@ -52,7 +52,7 @@ class TestPickShip(TestStockCommon): location = self.env['stock.location'].browse(self.stock_location) # make some stock - self.env['stock.quant']._increase_available_quantity(self.productA, location, 10.0) + self.env['stock.quant']._update_available_quantity(self.productA, location, 10.0) picking_pick.action_assign() picking_pick.move_lines[0].move_line_ids[0].qty_done = 10.0 picking_pick.do_transfer() @@ -72,9 +72,9 @@ class TestPickShip(TestStockCommon): """ picking_pick, picking_client = self.create_pick_ship() stock_location = self.env['stock.location'].browse(self.stock_location) - self.env['stock.quant']._increase_available_quantity(self.productA, stock_location, 10.0) + self.env['stock.quant']._update_available_quantity(self.productA, stock_location, 10.0) pack_location = self.env['stock.location'].browse(self.pack_location) - self.env['stock.quant']._increase_available_quantity(self.productA, pack_location, 5.0) + self.env['stock.quant']._update_available_quantity(self.productA, pack_location, 5.0) self.assertEqual(len(self.env['stock.quant']._gather(self.productA, stock_location)), 1.0) self.assertEqual(len(self.env['stock.quant']._gather(self.productA, pack_location)), 1.0) @@ -105,7 +105,7 @@ class TestPickShip(TestStockCommon): def test_mto_moves_return(self): picking_pick, picking_client = self.create_pick_ship() stock_location = self.env['stock.location'].browse(self.stock_location) - self.env['stock.quant']._increase_available_quantity(self.productA, stock_location, 10.0) + self.env['stock.quant']._update_available_quantity(self.productA, stock_location, 10.0) picking_pick.action_assign() picking_pick.move_lines[0].move_line_ids[0].qty_done = 10.0 @@ -135,7 +135,7 @@ class TestPickShip(TestStockCommon): location = self.env['stock.location'].browse(self.stock_location) # make some stock - self.env['stock.quant']._increase_available_quantity(self.productA, location, 10.0) + self.env['stock.quant']._update_available_quantity(self.productA, location, 10.0) picking_pick.action_assign() picking_pick.move_lines[0].move_line_ids[0].qty_done = 5.0 @@ -159,7 +159,7 @@ class TestPickShip(TestStockCommon): location = self.env['stock.location'].browse(self.stock_location) # make some stock - self.env['stock.quant']._increase_available_quantity(self.productA, location, 10.0) + self.env['stock.quant']._update_available_quantity(self.productA, location, 10.0) picking_pick.action_assign() picking_pick.move_lines[0].move_line_ids[0].qty_done = 10.0 picking_pick.action_done() @@ -197,7 +197,7 @@ class TestPickShip(TestStockCommon): location = self.env['stock.location'].browse(self.stock_location) # make some stock - self.env['stock.quant']._increase_available_quantity(self.productA, location, 10.0) + self.env['stock.quant']._update_available_quantity(self.productA, location, 10.0) picking_pick.action_assign() picking_pick.move_lines[0].move_line_ids[0].write({ 'qty_done': 10.0, @@ -246,7 +246,7 @@ class TestSinglePicking(TestStockCommon): # make some stock pack_location = self.env['stock.location'].browse(self.pack_location) - self.env['stock.quant']._increase_available_quantity(self.productA, pack_location, 2) + self.env['stock.quant']._update_available_quantity(self.productA, pack_location, 2) # assign delivery_order.action_confirm() @@ -283,7 +283,7 @@ class TestSinglePicking(TestStockCommon): # make some stock pack_location = self.env['stock.location'].browse(self.pack_location) - self.env['stock.quant']._increase_available_quantity(self.productA, pack_location, 1) + self.env['stock.quant']._update_available_quantity(self.productA, pack_location, 1) # assign to partially available delivery_order.action_confirm() @@ -322,7 +322,7 @@ class TestSinglePicking(TestStockCommon): # make some stock pack_location = self.env['stock.location'].browse(self.pack_location) - self.env['stock.quant']._increase_available_quantity(self.productA, pack_location, 1) + self.env['stock.quant']._update_available_quantity(self.productA, pack_location, 1) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.productA, pack_location), 1.0) # assign to available @@ -377,7 +377,7 @@ class TestSinglePicking(TestStockCommon): # make some stock pack_location = self.env['stock.location'].browse(self.pack_location) - self.env['stock.quant']._increase_available_quantity(self.productA, pack_location, 1) + self.env['stock.quant']._update_available_quantity(self.productA, pack_location, 1) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.productA, pack_location), 1.0) # assign to available @@ -463,7 +463,7 @@ class TestSinglePicking(TestStockCommon): product with one move line. After adding a second unit in stock and recheck availability. The DO should have 2 reserved unit, be in available state and have only one move line. """ - self.env['stock.quant']._increase_available_quantity(self.productA, self.env['stock.location'].browse(self.stock_location), 1.0) + self.env['stock.quant']._update_available_quantity(self.productA, self.env['stock.location'].browse(self.stock_location), 1.0) delivery_order = self.env['stock.picking'].create({ 'location_id': self.stock_location, 'location_dest_id': self.customer_location, @@ -520,7 +520,7 @@ class TestSinglePicking(TestStockCommon): 'product_id': self.productA.id, }) stock_location = self.env['stock.location'].browse(self.stock_location) - self.env['stock.quant']._increase_available_quantity(self.productA, stock_location, 1.0, lot_id=lot1) + self.env['stock.quant']._update_available_quantity(self.productA, stock_location, 1.0, lot_id=lot1) delivery_order = self.env['stock.picking'].create({ 'location_id': self.stock_location, 'location_dest_id': self.customer_location, @@ -580,7 +580,7 @@ class TestSinglePicking(TestStockCommon): 'product_id': self.productA.id, }) stock_location = self.env['stock.location'].browse(self.stock_location) - self.env['stock.quant']._increase_available_quantity(self.productA, stock_location, 1.0, lot_id=lot1) + self.env['stock.quant']._update_available_quantity(self.productA, stock_location, 1.0, lot_id=lot1) delivery_order = self.env['stock.picking'].create({ 'location_id': self.stock_location, 'location_dest_id': self.customer_location, @@ -647,7 +647,7 @@ class TestSinglePicking(TestStockCommon): 'product_id': self.productA.id, }) stock_location = self.env['stock.location'].browse(self.stock_location) - self.env['stock.quant']._increase_available_quantity(self.productA, stock_location, 1.0, lot_id=serial1) + self.env['stock.quant']._update_available_quantity(self.productA, stock_location, 1.0, lot_id=serial1) delivery_order = self.env['stock.picking'].create({ 'location_id': self.stock_location, 'location_dest_id': self.customer_location, diff --git a/addons/stock/tests/test_quant.py b/addons/stock/tests/test_quant.py index a9dae64d77f..3c9c728b96d 100644 --- a/addons/stock/tests/test_quant.py +++ b/addons/stock/tests/test_quant.py @@ -164,7 +164,7 @@ class StockQuant(TransactionCase): self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 0.0) self.assertEqual(len(self.env['stock.quant']._gather(product1, stock_location)), 0) with self.assertRaises(ValidationError): - self.env['stock.quant']._increase_available_quantity(product1, stock_location, 1.0) + self.env['stock.quant']._update_available_quantity(product1, stock_location, 1.0) def test_get_available_quantity_9(self): """ Quantity availability by a demo user with access rights/rules. @@ -190,7 +190,7 @@ class StockQuant(TransactionCase): 'name': 'Product A', 'type': 'product', }) - self.env['stock.quant']._increase_available_quantity(product1, stock_location, 1.0) + self.env['stock.quant']._update_available_quantity(product1, stock_location, 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 1.0) def test_increase_available_quantity_2(self): @@ -208,7 +208,7 @@ class StockQuant(TransactionCase): 'quantity': 1.0, }) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 2.0) - self.env['stock.quant']._increase_available_quantity(product1, stock_location, 1.0) + self.env['stock.quant']._update_available_quantity(product1, stock_location, 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 3.0) self.assertEqual(len(self.env['stock.quant']._gather(product1, stock_location)), 2) @@ -228,7 +228,7 @@ class StockQuant(TransactionCase): quant_id = cr2.fetchone() cr2.execute("SELECT 1 FROM stock_quant WHERE id=%s FOR UPDATE", quant_id) - self.env['stock.quant']._increase_available_quantity(product, stock_location, 1.0) + self.env['stock.quant']._update_available_quantity(product, stock_location, 1.0) cr2.rollback() cr2.close() self.assertEqual(self.env['stock.quant']._get_available_quantity(product, stock_location), 11.0) @@ -243,7 +243,7 @@ class StockQuant(TransactionCase): 'type': 'product', }) self.env = self.env(user=self.env.ref('base.user_demo')) - self.env['stock.quant']._increase_available_quantity(product1, stock_location, 1.0) + self.env['stock.quant']._update_available_quantity(product1, stock_location, 1.0) def test_decrease_available_quantity_1(self): """ Decrease the available quantity when no quants are already in a location. @@ -253,7 +253,7 @@ class StockQuant(TransactionCase): 'name': 'Product A', 'type': 'product', }) - self.env['stock.quant']._decrease_available_quantity(product1, stock_location, 1.0) + self.env['stock.quant']._update_available_quantity(product1, stock_location, -1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), -1.0) def test_decrease_available_quantity_2(self): @@ -272,7 +272,7 @@ class StockQuant(TransactionCase): }) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 2.0) self.assertEqual(len(self.env['stock.quant']._gather(product1, stock_location)), 2) - self.env['stock.quant']._decrease_available_quantity(product1, stock_location, 1.0) + self.env['stock.quant']._update_available_quantity(product1, stock_location, -1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 1.0) self.assertEqual(len(self.env['stock.quant']._gather(product1, stock_location)), 1) @@ -290,7 +290,7 @@ class StockQuant(TransactionCase): # quantity increase cr2 = self.registry.cursor() cr2.execute("SELECT 1 FROM stock_quant WHERE id = %s FOR UPDATE", quants.ids) - self.env['stock.quant']._decrease_available_quantity(product, stock_location, 1.0) + self.env['stock.quant']._update_available_quantity(product, stock_location, -1.0) cr2.rollback() cr2.close() self.assertEqual(self.env['stock.quant']._get_available_quantity(product, stock_location), 9.0) @@ -311,7 +311,7 @@ class StockQuant(TransactionCase): 'quantity': 1.0, }) self.env = self.env(user=self.demo_user) - self.env['stock.quant']._decrease_available_quantity(product1, stock_location, 1.0) + self.env['stock.quant']._update_available_quantity(product1, stock_location, -1.0) self.assertEqual(len(self.env['stock.quant']._gather(product1, stock_location)), 0) def test_increase_reserved_quantity_1(self): @@ -330,7 +330,7 @@ class StockQuant(TransactionCase): }) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 10.0) self.assertEqual(len(self.env['stock.quant']._gather(product1, stock_location)), 1) - self.env['stock.quant']._increase_reserved_quantity(product1, stock_location, 10.0) + self.env['stock.quant']._update_reserved_quantity(product1, stock_location, 10.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 0.0) self.assertEqual(len(self.env['stock.quant']._gather(product1, stock_location)), 1) @@ -351,7 +351,7 @@ class StockQuant(TransactionCase): }) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 10.0) self.assertEqual(len(self.env['stock.quant']._gather(product1, stock_location)), 2) - self.env['stock.quant']._increase_reserved_quantity(product1, stock_location, 10.0) + self.env['stock.quant']._update_reserved_quantity(product1, stock_location, 10.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 0.0) self.assertEqual(len(self.env['stock.quant']._gather(product1, stock_location)), 2) @@ -392,7 +392,7 @@ class StockQuant(TransactionCase): # total reserved quantity: 29 self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 29.0) self.assertEqual(len(self.env['stock.quant']._gather(product1, stock_location)), 4) - self.env['stock.quant']._increase_reserved_quantity(product1, stock_location, 10.0) + self.env['stock.quant']._update_reserved_quantity(product1, stock_location, 10.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 19.0) self.assertEqual(len(self.env['stock.quant']._gather(product1, stock_location)), 4) @@ -420,7 +420,7 @@ class StockQuant(TransactionCase): self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 0.0) self.assertEqual(len(self.env['stock.quant']._gather(product1, stock_location)), 2) with self.assertRaises(UserError): - self.env['stock.quant']._increase_reserved_quantity(product1, stock_location, 10.0) + self.env['stock.quant']._update_reserved_quantity(product1, stock_location, 10.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 0.0) def test_increase_reserved_quantity_5(self): @@ -432,7 +432,7 @@ class StockQuant(TransactionCase): 'type': 'product', }) with self.assertRaises(UserError): - self.env['stock.quant']._increase_reserved_quantity(product1, stock_location, 1.0) + self.env['stock.quant']._update_reserved_quantity(product1, stock_location, 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 0.0) def test_decrease_reserved_quantity_1(self): @@ -449,7 +449,7 @@ class StockQuant(TransactionCase): }) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 0.0) self.assertEqual(len(self.env['stock.quant']._gather(product1, stock_location)), 1) - self.env['stock.quant']._decrease_reserved_quantity(product1, stock_location, 10.0) + self.env['stock.quant']._update_reserved_quantity(product1, stock_location, -10.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 10.0) self.assertEqual(len(self.env['stock.quant']._gather(product1, stock_location)), 1) @@ -462,10 +462,10 @@ class StockQuant(TransactionCase): 'type': 'product', }) with self.assertRaises(UserError): - self.env['stock.quant']._increase_reserved_quantity(product1, stock_location, 1.0) + self.env['stock.quant']._update_reserved_quantity(product1, stock_location, 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 0.0) with self.assertRaises(UserError): - self.env['stock.quant']._decrease_reserved_quantity(product1, stock_location, 1.0) + self.env['stock.quant']._update_reserved_quantity(product1, stock_location, -1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 0.0) def test_action_done_1(self): @@ -475,15 +475,15 @@ class StockQuant(TransactionCase): 'name': 'Product A', 'type': 'product', }) - self.env['stock.quant']._increase_available_quantity(product1, stock_location, 2.0) + self.env['stock.quant']._update_available_quantity(product1, stock_location, 2.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 2.0) - self.env['stock.quant']._increase_reserved_quantity(product1, stock_location, 2.0) + self.env['stock.quant']._update_reserved_quantity(product1, stock_location, 2.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 0.0) - self.env['stock.quant']._decrease_reserved_quantity(product1, stock_location, 2.0) + self.env['stock.quant']._update_reserved_quantity(product1, stock_location, -2.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 2.0) - self.env['stock.quant']._decrease_available_quantity(product1, stock_location, 2.0) + self.env['stock.quant']._update_available_quantity(product1, stock_location, -2.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 0.0) - self.env['stock.quant']._increase_available_quantity(product1, pack_location, 2.0) + self.env['stock.quant']._update_available_quantity(product1, pack_location, 2.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, pack_location), 2.0) def test_mix_tracked_untracked_1(self): @@ -499,27 +499,27 @@ class StockQuant(TransactionCase): }) # add one tracked, one untracked - self.env['stock.quant']._increase_available_quantity(product1, stock_location, 1.0) - self.env['stock.quant']._increase_available_quantity(product1, stock_location, 1.0, lot_id=lot1) + self.env['stock.quant']._update_available_quantity(product1, stock_location, 1.0) + self.env['stock.quant']._update_available_quantity(product1, stock_location, 1.0, lot_id=lot1) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 2.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location, strict=True), 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location, lot_id=lot1), 1.0) - self.env['stock.quant']._increase_reserved_quantity(product1, stock_location, 1.0, lot_id=lot1, strict=True) + self.env['stock.quant']._update_reserved_quantity(product1, stock_location, 1.0, lot_id=lot1, strict=True) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location, strict=True), 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location, lot_id=lot1), 0.0) - self.env['stock.quant']._decrease_reserved_quantity(product1, stock_location, 1.0, lot_id=lot1, strict=True) + self.env['stock.quant']._update_reserved_quantity(product1, stock_location, -1.0, lot_id=lot1, strict=True) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 2.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location, strict=True), 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location, lot_id=lot1), 1.0) with self.assertRaises(UserError): - self.env['stock.quant']._decrease_reserved_quantity(product1, stock_location, 1.0) + self.env['stock.quant']._update_reserved_quantity(product1, stock_location, -1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 2.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location, strict=True), 1.0)