diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 3e7bd10f05e..1ee84e00d9a 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -356,7 +356,10 @@ class StockMove(models.Model): def write(self, vals): # FIXME: pim fix your crap - if vals.get('product_uom_qty'): + if 'product_uom_qty' in vals: + for move in self.filtered(lambda m: m.state not in ('done', 'draft') and m.picking_id): + if vals['product_uom_qty'] != move.product_uom_qty: + self.env['stock.move.line']._log_message(move.picking_id, move, 'stock.track_move_template', vals) if self.env.context.get('do_not_unreserve') is None: move_to_unreserve = self.filtered(lambda m: m.state not in ['draft', 'done', 'cancel'] and m.reserved_availability > vals.get('product_uom_qty')) move_to_unreserve._do_unreserve() @@ -995,7 +998,7 @@ class StockMove(models.Model): 'move_line_ids': [], 'backorder_id': picking.id }) - picking.message_post('Backorder Created') #message needs to be improved + picking.message_post(_('The backorder %s has been created.') % (backorder_picking.id, backorder_picking.name)) moves_to_backorder.write({'picking_id': backorder_picking.id}) moves_to_backorder.mapped('move_line_ids').write({'picking_id': backorder_picking.id}) moves_to_backorder._action_assign() diff --git a/addons/stock/models/stock_move_line.py b/addons/stock/models/stock_move_line.py index 03874b0308d..e827658e2e9 100644 --- a/addons/stock/models/stock_move_line.py +++ b/addons/stock/models/stock_move_line.py @@ -279,6 +279,11 @@ class StockMoveLine(models.Model): Quant._update_available_quantity(product_id, location_dest_id, quantity, lot_id=lot_id, package_id=result_package_id, owner_id=owner_id, in_date=in_date) # 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')) + + # Log a note + if ml.picking_id: + ml._log_message(ml.picking_id, ml, 'stock.track_move_template', vals) + res = super(StockMoveLine, self).write(vals) # As stock_account values according to a move's `product_uom_qty`, we consider that any @@ -383,6 +388,22 @@ class StockMoveLine(models.Model): # Reset the reserved quantity as we just moved it to the destination location. (self - ml_to_delete).with_context(bypass_reservation_update=True).write({'product_uom_qty': 0.00}) + def _log_message(self, record, move, template, vals): + data = vals.copy() + if 'lot_id' in vals and vals['lot_id'] != move.lot_id.id: + data['lot_name'] = self.env['stock.production.lot'].browse(vals.get('lot_id')).name + if 'location_id' in vals: + data['location_name'] = self.env['stock.location_id'].browse(vals.get('location_id')).name + if 'location_dest_id' in vals: + data['location_dest_name'] = self.env['stock.location_id'].browse(vals.get('location_dest_id')).name + if 'package_id' in vals and vals['package_id'] != move.package_id.id: + data['package_name'] = self.env['stock.quant.package'].browse(vals.get('package_id')).name + if 'package_result_id' in vals and vals['package_result_id'] != move.package_result_id.id: + data['result_package_name'] = self.env['stock.quant.package'].browse(vals.get('result_package_id')).name + if 'owner_id' in vals and vals['owner_id'] != move.owner_id.id: + data['owner_name'] = self.env['res.partner'].browse(vals.get('owner_id')).name + record.message_post_with_view(template, values={'move': move, 'vals': dict(vals, **data)}, subtype_id=self.env.ref('mail.mt_note').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 possible to impact quants that were not reserved. It is therefore necessary to edit or diff --git a/addons/stock/views/stock_template.xml b/addons/stock/views/stock_template.xml index 01e7296afa9..1d4760a5c25 100644 --- a/addons/stock/views/stock_template.xml +++ b/addons/stock/views/stock_template.xml @@ -9,4 +9,96 @@ + + + + + +