From 5e5333a1e9956d207def489076d4e26073fcd037 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 7 May 2014 14:52:48 +0200 Subject: [PATCH] [FIX] code cleanup (addon mrp) change the way bom_count, bom_strct and mo_count are computed, removes the try/except/pass statements, improves the logic. Also, for some reason, bom_strct is the same as bom_count, but I don't really know what it is supposed to be, and the Bom Structure and Bill of materials buttons leads to views with the same number of items. bzr revid: ged@openerp.com-20140507125248-ctv491ktx008v9ic --- addons/mrp/mrp.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 537e3f5bfda..5e5afd9de7c 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -1111,24 +1111,22 @@ class mrp_production_product_line(osv.osv): class product_product(osv.osv): _inherit = "product.product" - def _bom_count(self, cr, uid, ids, field_name, arg, context=None): - res = dict(map(lambda x: (x,{'bom_count': 0, 'mo_count': 0, 'bom_strct':0}), ids)) - try: - for bom in self.browse(cr, uid, ids, context=context): - res[bom.id] = { - 'bom_count': len(bom.bom_ids), - 'mo_count': len(bom.mo_ids), - 'bom_strct':len(bom.bom_ids), - } - except: - pass - return res + def _bom_orders_count(self, cr, uid, ids, field_name, arg, context=None): + Bom = self.pool('mrp.bom') + Production = self.pool('mrp.production') + return { + product_id: { + 'bom_count': Bom.search_count(cr, uid, [('product_id', '=', product_id), ('bom_id', '=', False)], context=context), + 'mo_count': Production.search_count(cr,uid, [('product_id', '=', product_id)], context=context), + 'bom_strct': Bom.search_count(cr, uid, [('product_id', '=', product_id), ('bom_id', '=', False)], context=context), + } + for product_id in ids + } _columns = { 'bom_ids': fields.one2many('mrp.bom', 'product_id', 'Bill of Materials'), - 'mo_ids': fields.one2many('mrp.production', 'product_id', 'Manufacturing Orders'), - 'bom_count': fields.function(_bom_count, string='# Bill of Material', type='integer', multi="bom_count"), - 'bom_strct': fields.function(_bom_count, string='# Bill of Material Structure', type='integer', multi="bom_count"), - 'mo_count': fields.function(_bom_count, string='# Manufacturing Orders', type='integer', multi="bom_count"), + 'bom_count': fields.function(_bom_orders_count, string='# Bill of Material', type='integer', multi="_bom_order_count"), + 'bom_strct': fields.function(_bom_orders_count, string='# Bill of Material Structure', type='integer', multi="_bom_order_count"), + 'mo_count': fields.function(_bom_orders_count, string='# Manufacturing Orders', type='integer', multi="_bom_order_count"), } # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: