[FIX] mrp: avoid accessing empty data

Once we log an exception via next activity in a production, we search moves that have been updated uphill to write the useful information about the change. The issue is by default, the key 'move_orig_id' is searched while some moves could be linked with 'created_purchase_line_id' key.

This commit avoid mapping 'move_orig_id' on empty recordset and so avoid a traceback.

opw:1911399

closes odoo/odoo#29087
This commit is contained in:
William Henrotin
2018-11-30 08:47:34 +00:00
parent 25d63eee7c
commit a226723e52
2 changed files with 12 additions and 13 deletions
+5 -5
View File
@@ -762,14 +762,14 @@ class MrpProduction(models.Model):
order_exceptions.update(order_exception)
visited_objects += visited
visited_objects = self.env[visited_objects[0]._name].concat(*visited_objects)
visited_objects |= visited_objects.mapped('move_orig_ids')
impacted_pickings = []
if visited_objects._name == 'stock.move':
impacted_pickings = visited_objects.filtered(lambda m: m.state not in ('done', 'cancel')).mapped('picking_id')
impacted_object = []
if visited_objects and visited_objects._name == 'stock.move':
visited_objects |= visited_objects.mapped('move_orig_ids')
impacted_object = visited_objects.filtered(lambda m: m.state not in ('done', 'cancel')).mapped('picking_id')
values = {
'production_order': self,
'order_exceptions': order_exceptions,
'impacted_pickings': impacted_pickings,
'impacted_object': impacted_object,
'cancel': cancel
}
return self.env.ref('mrp.exception_on_mo').render(values=values)
+7 -8
View File
@@ -4,6 +4,7 @@
from collections import namedtuple
import json
import time
from datetime import date
from itertools import groupby
from odoo import api, fields, models, _
@@ -919,14 +920,12 @@ class Picking(models.Model):
"""
for (parent, responsible), rendering_context in documents.items():
note = render_method(rendering_context)
self.env['mail.activity'].create({
'activity_type_id': self.env.ref('mail.mail_activity_data_warning').id,
'note': note,
'user_id': responsible.id,
'res_id': parent.id,
'res_model_id': self.env['ir.model'].search([('model', '=', parent._name)], limit=1).id,
})
parent.activity_schedule(
'mail.mail_activity_data_warning',
date.today(),
note=note,
user_id=responsible.id
)
def _log_less_quantities_than_expected(self, moves):
""" Log an activity on picking that follow moves. The note