Skip to content

Commit

Permalink
[FIX] mrp: avoid accessing empty data
Browse files Browse the repository at this point in the history
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#29087
  • Loading branch information
Whenrow committed Nov 30, 2018
1 parent 25d63ee commit a226723
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
10 changes: 5 additions & 5 deletions addons/mrp/models/mrp_production.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,14 +762,14 @@ def _render_note_exception_quantity_mo(rendering_context):
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)
Expand Down
15 changes: 7 additions & 8 deletions addons/stock/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, _
Expand Down Expand Up @@ -919,14 +920,12 @@ def _log_activity(self, render_method, documents):
"""
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
Expand Down

0 comments on commit a226723

Please sign in to comment.