[FIX] code cleanup (addon account_analytic_default)
improves the _rules_count method (remove try/catch and better logic), and removes now useless one2many field rules_ids bzr revid: ged@openerp.com-20140507090841-jptga7kjrverd25n
This commit is contained in:
parent
943f2d4e4e
commit
d8fef2825e
|
@ -117,15 +117,12 @@ class sale_order_line(osv.osv):
|
|||
class product_product(osv.Model):
|
||||
_inherit = 'product.product'
|
||||
def _rules_count(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = dict(map(lambda x: (x,0), ids))
|
||||
try:
|
||||
for rule in self.browse(cr, uid, ids, context=context):
|
||||
res[rule.id] = len(rule.rules_ids)
|
||||
except:
|
||||
pass
|
||||
return res
|
||||
Analytic = self.pool['account.analytic.default']
|
||||
return {
|
||||
product_id: Analytic.search_count(cr, uid, [('product_id', '=', product_id)], context=context)
|
||||
for product_id in ids
|
||||
}
|
||||
_columns = {
|
||||
'rules_ids': fields.one2many('account.analytic.default', 'product_id', 'Analytic Rules '),
|
||||
'rules_count': fields.function(_rules_count, string='# Analytic Rules', type='integer'),
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue