From 9fa38eeab2382144ad37cfb4755ead114dd48dc3 Mon Sep 17 00:00:00 2001 From: Gaurav Panchal Date: Thu, 2 Jul 2015 15:49:34 +0530 Subject: [PATCH] [ADD]mrp: add product category on manufacturing order and bill of materials --- addons/mrp/mrp.py | 16 ++++++++++++++++ addons/mrp/mrp_view.xml | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 262104f0308..de8bd18a3d5 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -151,6 +151,9 @@ class mrp_bom(osv.osv): _description = 'Bill of Material' _inherit = ['mail.thread'] + def _get_bom_ids_from_product_template_ids(self, cr, uid, product_template_ids, context=None): + return self.pool['mrp.bom'].search(cr, uid, [('product_tmpl_id', 'in', product_template_ids)], context=context) + _columns = { 'name': fields.char('Name'), 'code': fields.char('Reference', size=16), @@ -163,6 +166,11 @@ class mrp_bom(osv.osv): domain="['&', ('product_tmpl_id','=',product_tmpl_id), ('type','!=', 'service')]", help="If a product variant is defined the BOM is available only for this product."), 'bom_line_ids': fields.one2many('mrp.bom.line', 'bom_id', 'BoM Lines', copy=True), + 'categ_id': fields.related('product_tmpl_id', 'categ_id', type='many2one', relation='product.category', string='Product Category', readonly=True, + store = { + 'mrp.bom': (lambda self, cr, uid, ids, c=None: ids, ['product_tmpl_id'], 10), + 'product.template': (_get_bom_ids_from_product_template_ids, ['categ_id'], 10) + }), 'product_qty': fields.float('Product Quantity', required=True, digits_compute=dp.get_precision('Product Unit of Measure')), 'product_uom': fields.many2one('product.uom', 'Product Unit of Measure', required=True, help="Unit of Measure (Unit of Measure) is the unit of measurement for the inventory control"), 'date_start': fields.date('Valid From', help="Validity of this BoM. Keep empty if it's always valid."), @@ -541,6 +549,9 @@ class mrp_production(osv.osv): res += self.pool.get("mrp.production").search(cr, uid, [('move_lines', 'in', move.id)], context=context) return res + def _get_mo_ids_from_product_template_ids(self, cr, uid, product_template_ids, context=None): + return self.pool["mrp.production"].search(cr, uid , [('product_id.product_tmpl_id', 'in', product_template_ids)], context=context) + _columns = { 'name': fields.char('Reference', required=True, readonly=True, states={'draft': [('readonly', False)]}, copy=False), 'origin': fields.char('Source Document', readonly=True, states={'draft': [('readonly', False)]}, @@ -606,6 +617,11 @@ class mrp_production(osv.osv): 'company_id': fields.many2one('res.company', 'Company', required=True), 'ready_production': fields.function(_moves_assigned, type='boolean', string="Ready for production", store={'stock.move': (_mrp_from_move, ['state'], 10)}), 'product_tmpl_id': fields.related('product_id', 'product_tmpl_id', type='many2one', relation='product.template', string='Product'), + 'categ_id': fields.related('product_tmpl_id', 'categ_id', type='many2one', relation='product.category', string='Product Category', readonly=True, + store = { + 'mrp.production': (lambda self, cr, uid, ids, c=None: ids, ['product_tmpl_id'], 10), + 'product.template': (_get_mo_ids_from_product_template_ids, ['categ_id'], 10) + }), } _defaults = { diff --git a/addons/mrp/mrp_view.xml b/addons/mrp/mrp_view.xml index d4967c8b94f..dc4fd8547df 100644 --- a/addons/mrp/mrp_view.xml +++ b/addons/mrp/mrp_view.xml @@ -396,6 +396,7 @@ will contain the raw materials, instead of the finished product.

+ @@ -466,12 +467,14 @@ + + @@ -626,6 +629,7 @@ + @@ -864,11 +868,13 @@ + +