Files
odoo_source/addons/mrp/models/stock_picking.py
T
Josse Colpaert ffe13756f5 [FIX] mrp: manufacturing vignette in inventory dashboard
When clicking on the "manufacturing" vignette in the inventory
dashboard, the records were not filtered correctly (example: add a new
warehouse, a new "manufacturing" vignette appears for this warehouse in
the inventory dashboard, clicking on it would display the MO of all the
warehouses).

With this fix, as with the pickings, it will only show the count of MO
filtered to that specific picking type in the vignette, and clicking on
it will displayed the filtered ones.

We implementent the method of the compute field the same way the similar
method for the picking is implemented.

fixes #15008
2017-01-17 14:43:06 +01:00

30 lines
1.4 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
class StockPickingType(models.Model):
_inherit = 'stock.picking.type'
code = fields.Selection(selection_add=[('mrp_operation', 'Manufacturing Operation')])
count_mo_todo = fields.Integer(compute='_get_mo_count')
count_mo_waiting = fields.Integer(compute='_get_mo_count')
count_mo_late = fields.Integer(compute='_get_mo_count')
def _get_mo_count(self):
mrp_picking_types = self.filtered(lambda picking: picking.code == 'mrp_operation')
if not mrp_picking_types:
return
domains = {
'count_mo_waiting': [('availability', '=', 'waiting')],
'count_mo_todo': [('state', 'in', ('confirmed', 'planned', 'progress'))],
'count_mo_late': [('date_planned_start', '<', fields.Date.today()), ('state', '=', 'confirmed')],
}
for field in domains:
data = self.env['mrp.production'].read_group(domains[field] +
[('state', 'not in', ('done', 'cancel')), ('picking_type_id', 'in', self.ids)],
['picking_type_id'], ['picking_type_id'])
count = dict(map(lambda x: (x['picking_type_id'] and x['picking_type_id'][0], x['picking_type_id_count']), data))
for record in mrp_picking_types:
record[field] = count.get(record.id, 0)