[IMP] stock: backorder created only when needed
Before this commit, when the user chose to not make a backorder, a backorder was created then immediatly canceled. This behaviour is now changed as in such a case the backorder is simply not created anymore
This commit is contained in:
@@ -82,8 +82,8 @@ class StockMove(models.Model):
|
||||
super(StockMove, self)._clean_merged()
|
||||
self.write({'created_purchase_line_id': False})
|
||||
|
||||
def _action_done(self):
|
||||
res = super(StockMove, self)._action_done()
|
||||
def _action_done(self, cancel_backorder=False):
|
||||
res = super(StockMove, self)._action_done(cancel_backorder=cancel_backorder)
|
||||
self.mapped('purchase_line_id').sudo()._update_received_qty()
|
||||
return res
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@ class Inventory(models.Model):
|
||||
else:
|
||||
self._action_done()
|
||||
|
||||
def _action_done(self):
|
||||
def _action_done(self, cancel_backorder=False):
|
||||
negative = next((line for line in self.mapped('line_ids') if line.product_qty < 0 and line.product_qty != line.theoretical_qty), False)
|
||||
if negative:
|
||||
raise UserError(_('You cannot set a negative product quantity in an inventory line:\n\t%s - qty: %s') % (negative.product_id.name, negative.product_qty))
|
||||
|
||||
@@ -1084,7 +1084,7 @@ class StockMove(models.Model):
|
||||
def _unreserve_initial_demand(self, new_move):
|
||||
pass
|
||||
|
||||
def _action_done(self):
|
||||
def _action_done(self, cancel_backorder=False):
|
||||
self.filtered(lambda move: move.state == 'draft')._action_confirm() # MRP allows scrapping draft moves
|
||||
moves = self.exists().filtered(lambda x: x.state not in ('done', 'cancel'))
|
||||
moves_todo = self.env['stock.move']
|
||||
@@ -1124,6 +1124,8 @@ class StockMove(models.Model):
|
||||
except UserError:
|
||||
pass
|
||||
move._unreserve_initial_demand(new_move)
|
||||
if cancel_backorder:
|
||||
self.env['stock.move'].browse(new_move)._action_cancel()
|
||||
moves_todo.mapped('move_line_ids')._action_done()
|
||||
# Check the consistency of the result packages; there should be an unique location across
|
||||
# the contained quants.
|
||||
@@ -1140,7 +1142,7 @@ class StockMove(models.Model):
|
||||
if all(move_todo.scrapped for move_todo in moves_todo):
|
||||
return moves_todo
|
||||
|
||||
if picking:
|
||||
if picking and not cancel_backorder:
|
||||
picking._create_backorder()
|
||||
return moves_todo
|
||||
|
||||
|
||||
@@ -351,7 +351,7 @@ class StockMoveLine(models.Model):
|
||||
moves._recompute_state()
|
||||
return res
|
||||
|
||||
def _action_done(self):
|
||||
def _action_done(self, cancel_backorder=False):
|
||||
""" This method is called during a move's `action_done`. It'll actually move a quant from
|
||||
the source location to the destination location, and unreserve if needed in the source
|
||||
location.
|
||||
|
||||
@@ -622,7 +622,7 @@ class Picking(models.Model):
|
||||
new_move._action_confirm()
|
||||
todo_moves |= new_move
|
||||
#'qty_done': ops.qty_done})
|
||||
todo_moves._action_done()
|
||||
todo_moves._action_done(cancel_backorder=self.env.context.get('cancel_backorder'))
|
||||
self.write({'date_done': fields.Datetime.now()})
|
||||
return True
|
||||
|
||||
|
||||
@@ -20,12 +20,7 @@ class StockBackorderConfirmation(models.TransientModel):
|
||||
if float_compare(move.product_uom_qty, move.quantity_done, move.product_uom.rounding) > 0:
|
||||
moves_to_log[move] = (move.quantity_done, move.product_uom_qty)
|
||||
pick_id._log_less_quantities_than_expected(moves_to_log)
|
||||
self.pick_ids.action_done()
|
||||
if cancel_backorder:
|
||||
for pick_id in self.pick_ids:
|
||||
backorder_pick = self.env['stock.picking'].search([('backorder_id', '=', pick_id.id)])
|
||||
backorder_pick.action_cancel()
|
||||
pick_id.message_post(body=_("Back order <em>%s</em> <b>cancelled</b>.") % (backorder_pick.name))
|
||||
self.pick_ids.with_context({'cancel_backorder': cancel_backorder}).action_done()
|
||||
|
||||
def process(self):
|
||||
self._process()
|
||||
|
||||
@@ -348,9 +348,9 @@ class StockMove(models.Model):
|
||||
'price_unit': price_unit if self._is_dropshipped() else -price_unit,
|
||||
})
|
||||
|
||||
def _action_done(self):
|
||||
def _action_done(self, cancel_backorder=False):
|
||||
self.product_price_update_before_done()
|
||||
res = super(StockMove, self)._action_done()
|
||||
res = super(StockMove, self)._action_done(cancel_backorder=cancel_backorder)
|
||||
for move in res:
|
||||
# Apply restrictions on the stock move to be able to make
|
||||
# consistent accounting entries.
|
||||
|
||||
Reference in New Issue
Block a user