[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
This commit is contained in:
Gery Debongnie 2014-05-07 14:52:48 +02:00
parent aeebac88d9
commit 5e5333a1e9
1 changed files with 14 additions and 16 deletions

View File

@ -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: