From 71f9c08e804a8dae253b3ce199de1850fe161db4 Mon Sep 17 00:00:00 2001
From: Josse Colpaert <jco@odoo.com>
Date: Mon, 2 Oct 2017 20:26:07 +0200
Subject: [PATCH] [FIX] mrp: make sure the note is logged when you change done
 qties

The production_id on the stock move line is a helper field for work
orders and you can not assume it is always set correctly.  As
non-tracked stock moves create the stock move lines themselves it is not
set.

So, for logging notes, we check the 2 production order fields through
the moves.
---
 addons/mrp/models/stock_move.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/addons/mrp/models/stock_move.py b/addons/mrp/models/stock_move.py
index 4eb94b2379a3..9a1d826f953b 100644
--- a/addons/mrp/models/stock_move.py
+++ b/addons/mrp/models/stock_move.py
@@ -37,8 +37,9 @@ class StockMoveLine(models.Model):
                 move_line.production_id.move_raw_ids.mapped('move_line_ids')\
                     .filtered(lambda r: r.done_wo and not r.done_move and r.lot_produced_id == move_line.lot_id)\
                     .write({'lot_produced_id': vals['lot_id']})
-            if move_line.production_id and move_line.state == 'done' and any(field in vals for field in ('lot_id', 'location_id', 'qty_done')):
-                move_line._log_message(move_line.production_id, move_line, 'mrp.track_production_move_template', vals)
+            production = move_line.move_id.production_id or move_line.move_id.raw_material_production_id
+            if production and move_line.state == 'done' and any(field in vals for field in ('lot_id', 'location_id', 'qty_done')):
+                move_line._log_message(production, move_line, 'mrp.track_production_move_template', vals)
         return super(StockMoveLine, self).write(vals)
 
 
-- 
GitLab