Files
odoo_source/addons/mrp/models/product.py
T
Josse Colpaert 2ddc35a530 [REF][NEWPIE] mrp: new MRP
This commit contains the core of the new MRP. It contains a whole refactoring
of the MRP application, with improved and new features, written in new API.
Among other here are the main manufacturing workflow improvements :

 - Picking type not only for pickings but also for manufacturing orders
 - Properties replaced by picking type
 - BoM can only be produced with its routing (no other)
 - Either produce without routing with only production orders, or produce with
   routing
 - By default, there is an order in the work orders (serially), but you can
   override it to be able to work in parallel
 - Time clocking on work orders and block time on work centers with reporting
   on OEE, performance, losses, ...
 - Real-time adaptation of timings on operations
 - Lots/serial numbers can be inputted like in the pickings on manufacturing
   orders.  It is also possible to input them in the work orders.
 - Material availability independent of production order state (possibility to
   start production when only part of it is there)
 - Work sheets on work orders
 - Put messages on work orders to make your workers pay attention to something
 - Full traceability link to see for each produced piece of stock, the
   consumed pieces, ...
 - Separate scrap object (a scrap is not done based on an original move
   anymore)
 - Separate unbuild system (if you want to unbuild into its original
   components)

Thanks to all people that helped during this development, notably but not
limited to Chirag A Dodiya (cod@odoo.com), Gaurav Panchal (gan@odoo.com),
Jignesh Rathod (jir@odoo.com), Mansi Trivedi (mtr@odoo.com), Pariket Trivedi
(ptr@odoo.com).
2016-07-04 16:22:37 +02:00

62 lines
2.7 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
class ProductTemplate(models.Model):
_inherit = "product.template"
bom_ids = fields.One2many('mrp.bom', 'product_tmpl_id', 'Bill of Materials')
bom_count = fields.Integer('# Bill of Material', compute='_compute_bom_count')
mo_count = fields.Integer('# Manufacturing Orders', compute='_compute_mo_count')
produce_delay = fields.Float(
'Manufacturing Lead Time', default=0.0,
help="Average delay in days to produce this product. In the case of multi-level BOM, the manufacturing lead times of the components will be added.")
def _compute_bom_count(self):
read_group_res = self.env['mrp.bom'].read_group([('product_tmpl_id', 'in', self.ids)], ['product_tmpl_id'], ['product_tmpl_id'])
mapped_data = dict([(data['product_tmpl_id'][0], data['product_tmpl_id_count']) for data in read_group_res])
for product in self:
product.bom_count = mapped_data.get(product.id, 0)
@api.one
def _compute_mo_count(self):
# TDE FIXME: directly use a read_group
self.mo_count = sum(self.mapped('product_variant_ids').mapped('mo_count'))
@api.multi
def action_view_mos(self):
product_ids = self.mapped('product_variant_ids').ids
action = self.env.ref('mrp.act_product_mrp_production').read()[0]
if len(self) == 1 and len(product_ids) == 1:
action['context'] = {'default_product_id': product_ids[0], 'search_default_product_id': product_ids[0]}
else:
action['domain'] = [('product_id', 'in', product_ids)]
action['context'] = {}
return action
class ProductProduct(models.Model):
_inherit = "product.product"
mo_count = fields.Integer('# Manufacturing Orders', compute='_compute_mo_count')
def _compute_mo_count(self):
read_group_res = self.env['mrp.production'].read_group([('product_id', 'in', self.ids)], ['product_id'], ['product_id'])
mapped_data = dict([(data['product_id'][0], data['product_id_count']) for data in read_group_res])
for product in self:
product.mo_count = mapped_data.get(product.id, 0)
@api.multi
def action_view_bom(self):
action = self.env.ref('mrp.product_open_bom').read()[0]
template_ids = self.mapped('product_tmpl_id').ids
# bom specific to this variant or global to template
action['context'] = {
'default_product_tmpl_id': template_ids[0],
'default_product_id': self.ids[0],
}
action['domain'] = ['|', ('product_id', 'in', [self.ids]), '&', ('product_id', '=', False), ('product_tmpl_id', 'in', template_ids)]
return action