[FIX] code cleanup (addon stock)
improves the _move_count method by removing try statement and using better logic. Also, removes now useless one2many field (move_ids) bzr revid: ged@openerp.com-20140507093442-ew1gc06r58tbl9ug
This commit is contained in:
parent
2d924f3e22
commit
ca5e95b7ef
|
@ -353,13 +353,11 @@ class product_product(osv.osv):
|
|||
res[id][f] = stock.get(id, 0.0)
|
||||
return res
|
||||
def _move_count(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = dict(map(lambda x: (x,0), ids))
|
||||
try:
|
||||
for move in self.browse(cr, uid, ids, context=context):
|
||||
res[move.id] = len(move.move_ids)
|
||||
except:
|
||||
pass
|
||||
return res
|
||||
Move = self.pool['stock.move']
|
||||
return {
|
||||
product_id: Move.search_count(cr, uid, [('product_id', '=', product_id)], context=context)
|
||||
for product_id in ids
|
||||
}
|
||||
_columns = {
|
||||
'reception_count': fields.function(_stock_move_count, string="Reception", type='integer', multi='pickings'),
|
||||
'delivery_count': fields.function(_stock_move_count, string="Delivery", type='integer', multi='pickings'),
|
||||
|
@ -420,7 +418,6 @@ class product_product(osv.osv):
|
|||
help="If real-time valuation is enabled for a product, the system will automatically write journal entries corresponding to stock moves." \
|
||||
"The inventory variation account set on the product category will represent the current inventory value, and the stock input and stock output account will hold the counterpart moves for incoming and outgoing products."
|
||||
, required=True),
|
||||
'move_ids': fields.one2many('stock.move', 'product_id', 'Moves'),
|
||||
'move_count': fields.function(_move_count, string='# Moves', type='integer'),
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue