[FIX] code cleanup (addon purchase)
remove useless one2many field in product.product, and improves the way purchase_count is computed bzr revid: ged@openerp.com-20140506150732-e0ztuzqm7hqu183p
This commit is contained in:
parent
2b67c9c77b
commit
c941eb8ca4
|
@ -1296,15 +1296,13 @@ class product_product(osv.Model):
|
||||||
_inherit = 'product.product'
|
_inherit = 'product.product'
|
||||||
|
|
||||||
def _purchase_count(self, cr, uid, ids, field_name, arg, context=None):
|
def _purchase_count(self, cr, uid, ids, field_name, arg, context=None):
|
||||||
res = dict(map(lambda x: (x,0), ids))
|
Purchase = self.pool['purchase.order']
|
||||||
try:
|
return {
|
||||||
for purchase in self.browse(cr, uid, ids, context=context):
|
product_id: Purchase.search_count(cr,uid, [('order_line.product_id', '=', product_id)], context=context)
|
||||||
res[purchase.id] = len(purchase.purchase_ids)
|
for product_id in ids
|
||||||
except:
|
}
|
||||||
pass
|
|
||||||
return res
|
|
||||||
_columns = {
|
_columns = {
|
||||||
'purchase_ids': fields.one2many('purchase.order', 'product_id', 'Purchases'),
|
|
||||||
'purchase_count': fields.function(_purchase_count, string='# Purchases', type='integer'),
|
'purchase_count': fields.function(_purchase_count, string='# Purchases', type='integer'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue