From 03a8f3bfe9a2638aec9bed316efd2b750def451a Mon Sep 17 00:00:00 2001 From: Naresh Choksy Date: Fri, 10 Oct 2008 14:29:13 +0530 Subject: [PATCH] Merged mrp_bom_hyerarchy into BoM module. Changed the tree view of a BoM so that it uses the child_complete_id instead of the current one2many. bzr revid: nch@tinyerp.com-20081010085913-6pev3fjzf0ag0j89 --- addons/mrp/__terp__.py | 3 +- addons/mrp/mrp.py | 34 +++++++++++++------ addons/mrp/mrp_view.xml | 75 ++++++++++++++++++++--------------------- 3 files changed, 62 insertions(+), 50 deletions(-) diff --git a/addons/mrp/__terp__.py b/addons/mrp/__terp__.py index 3f4b301fe11..cbba88cd2bf 100644 --- a/addons/mrp/__terp__.py +++ b/addons/mrp/__terp__.py @@ -47,7 +47,8 @@ * Cost method by product: standard price, average price * Easy analysis of troubles or needs * Very flexible - + * Allows to browse Bill of Materials in complete structure + that include child and phantom BoMs It supports complete integration and planification of stockable goods, consumable of services. Services are completly integrated with the rest of the software. For instance, you can set up a sub-contracting service diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index ecb383363d9..4891ea146b9 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -39,7 +39,7 @@ from mx import DateTime #---------------------------------------------------------- # Workcenters #---------------------------------------------------------- -# capacity_hour : capacity per hour. default: 1.0. +# capacity_hour : capacity per hour. default: 1.0. # Eg: If 5 concurrent operations at one time: capacity = 5 (because 5 employees) # unit_per_cycle : how many units are produced for one cycle # @@ -115,7 +115,7 @@ class mrp_routing(osv.osv): 'note': fields.text('Description'), 'workcenter_lines': fields.one2many('mrp.routing.workcenter', 'routing_id', 'Workcenters'), - 'location_id': fields.many2one('stock.location', 'Production Location', + 'location_id': fields.many2one('stock.location', 'Production Location', help="Keep empty if you produce at the location where the finnished products are needed." \ "Put a location if you produce at a fixed location. This can be a partner location " \ "if you subcontract the manufacturing operations." @@ -147,6 +147,17 @@ mrp_routing_workcenter() class mrp_bom(osv.osv): _name = 'mrp.bom' _description = 'Bill of Material' + def _child_compute(self, cr, uid, ids, name, arg, context={}): + result = {} + for bom in self.browse(cr, uid, ids, context=context): + result[bom.id] = map(lambda x: x.id, bom.bom_lines) + ok = ((name=='child_complete_ids') and (bom.product_id.supply_method=='produce')) + if bom.type=='phantom' or ok: + sids = self.pool.get('mrp.bom').search(cr, uid, [('bom_id','=',False),('product_id','=',bom.product_id.id)]) + if sids: + bom2 = self.pool.get('mrp.bom').browse(cr, uid, sids[0], context=context) + result[bom.id] += map(lambda x: x.id, bom2.bom_lines) + return result def _compute_type(self, cr, uid, ids, field_name, arg, context): res = dict(map(lambda x: (x,''), ids)) for line in self.browse(cr, uid, ids): @@ -185,7 +196,9 @@ class mrp_bom(osv.osv): 'routing_id': fields.many2one('mrp.routing', 'Routing', help="The list of operations (list of workcenters) to produce the finnished product. The routing is mainly used to compute workcenter costs during operations and to plan futur loads on workcenters based on production plannification."), 'property_ids': fields.many2many('mrp.property', 'mrp_bom_property_rel', 'bom_id','property_id', 'Properties'), 'revision_ids': fields.one2many('mrp.bom.revision', 'bom_id', 'BoM Revisions'), - 'revision_type': fields.selection([('numeric','numeric indices'),('alpha','alphabetical indices')], 'indice type') + 'revision_type': fields.selection([('numeric','numeric indices'),('alpha','alphabetical indices')], 'indice type'), + 'child_ids': fields.function(_child_compute,relation='mrp.bom', method=True, string="BoM Hyerarchy", type='many2many'), + 'child_complete_ids': fields.function(_child_compute,relation='mrp.bom', method=True, string="BoM Hyerarchy", type='many2many') } _defaults = { 'active': lambda *a: 1, @@ -198,6 +211,7 @@ class mrp_bom(osv.osv): _sql_constraints = [ ('bom_qty_zero', 'CHECK (product_qty>0)', 'All product quantities must be greater than 0 !'), ] + def _check_recursion(self, cr, uid, ids): level = 500 while len(ids): @@ -211,7 +225,7 @@ class mrp_bom(osv.osv): (_check_recursion, 'Error ! You can not create recursive BoM.', ['parent_id']) ] - + def onchange_product_id(self, cr, uid, ids, product_id, name, context={}): if product_id: prod=self.pool.get('product.product').browse(cr,uid,[product_id])[0] @@ -283,7 +297,7 @@ class mrp_bom(osv.osv): def set_indices(self, cr, uid, ids, context = {}): if not ids or (ids and not ids[0]): - return True + return True res = self.read(cr, uid, ids, ['revision_ids', 'revision_type']) rev_ids = res[0]['revision_ids'] idx = 1 @@ -310,7 +324,7 @@ class mrp_bom_revision(osv.osv): 'author_id': fields.many2one('res.users', 'Author'), 'bom_id': fields.many2one('mrp.bom', 'BoM', select=True), } - + _defaults = { 'author_id': lambda x,y,z,c: z, 'date': lambda *a: time.strftime('%Y-%m-%d'), @@ -603,7 +617,7 @@ class mrp_production(osv.osv): 'state': 'waiting' } res_final_id = self.pool.get('stock.move').create(cr, uid, data) - + self.write(cr, uid, [production.id], {'move_created_ids': [(6, 'WTF', [res_final_id])]}) moves = [] for line in production.product_lines: @@ -973,14 +987,14 @@ class mrp_procurement(osv.osv): newdate = newdate - DateTime.RelativeDateTime(days=company.po_lead) context.update({'lang':partner.lang}) product=self.pool.get('product.product').browse(cr,uid,procurement.product_id.id,context=context) - + line = { 'name': product.name, 'product_qty': qty, 'product_id': procurement.product_id.id, 'product_uom': uom_id, 'price_unit': price, - 'date_planned': newdate.strftime('%Y-%m-%d %H:%M:%S'), + 'date_planned': newdate.strftime('%Y-%m-%d %H:%M:%S'), 'move_dest_id': res_id, 'notes':product.description_purchase, } @@ -991,7 +1005,7 @@ class mrp_procurement(osv.osv): if partner_id: taxep_id = self.pool.get('res.partner').property_get(cr, uid,partner_id,property_pref=['property_account_supplier_tax']).get('property_account_supplier_tax',False) if taxep_id: - taxep=self.pool.get('account.tax').browse(cr, uid,taxep_id) + taxep=self.pool.get('account.tax').browse(cr, uid,taxep_id) if not taxep or not taxep.id: taxes_ids = [x.id for x in procurement.product_id.product_tmpl_id.supplier_taxes_id] else: diff --git a/addons/mrp/mrp_view.xml b/addons/mrp/mrp_view.xml index ab7d23c3d27..b22ca8ec6b6 100644 --- a/addons/mrp/mrp_view.xml +++ b/addons/mrp/mrp_view.xml @@ -1,13 +1,13 @@ - + - + - + mrp.property.group.form mrp.property.group @@ -30,7 +30,7 @@ - + mrp.property.tree mrp.property @@ -66,11 +66,11 @@ tree,form - + - + mrp.workcenter.tree mrp.workcenter @@ -129,11 +129,11 @@ - + - + mrp.routing.workcenter.tree mrp.routing.workcenter @@ -147,7 +147,7 @@ - + mrp.routing.workcenter.form mrp.routing.workcenter @@ -164,7 +164,7 @@ - + mrp.routing.form mrp.routing @@ -203,11 +203,11 @@ - + - + mrp.bom.form mrp.bom @@ -237,7 +237,7 @@ - + @@ -248,11 +248,12 @@ - + + mrp.bom.tree mrp.bom tree - bom_lines + child_complete_ids @@ -274,7 +275,7 @@ - + Bill of Material Structure ir.actions.act_window @@ -293,7 +294,7 @@ [('bom_id','=',False)] - + Bill of Materials Components ir.actions.act_window @@ -311,14 +312,14 @@ tree - + Bill of Materials Structure - + mrp.bom.revision mrp.bom.revision @@ -346,11 +347,11 @@ - + - + mrp.production.tree mrp.production @@ -367,8 +368,7 @@ - - + mrp.production.calendar mrp.production @@ -393,8 +393,7 @@ - - + mrp.production.form mrp.production @@ -490,7 +489,7 @@ [('state','=','confirmed')] - + New Production Order ir.actions.act_window @@ -499,7 +498,7 @@ form,tree,calendar,graph - + mrp.production.workcenter.line.form mrp.production.workcenter.line @@ -528,7 +527,7 @@ - + mrp.production.lot.line.form mrp.production.lot.line @@ -561,9 +560,7 @@ - - - + mrp.production.product.line.form mrp.production.product.line @@ -593,11 +590,11 @@ - + - + mrp.procurement.tree mrp.procurement @@ -677,7 +674,7 @@ - + Draft procurements ir.actions.act_window @@ -696,7 +693,7 @@ [('state','=','confirmed')] - + Exceptions procurements ir.actions.act_window @@ -706,7 +703,7 @@ [('state','=','exception')] - + Exceptions procurements to fix ir.actions.act_window @@ -716,7 +713,7 @@ [('state','=','exception'), ('message', '<>', '')] - + Temporary Procurement Exceptions ir.actions.act_window @@ -726,7 +723,7 @@ [('state','=','exception'), ('message', '=', '')] - + New Procurement ir.actions.act_window @@ -735,7 +732,7 @@ form,tree - + stock.warehouse.orderpoint.tree