From ca5e95b7ef87cc5e8a330bbe909ce9bd5c3f2c52 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 7 May 2014 11:34:42 +0200 Subject: [PATCH] [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 --- addons/stock/product.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/addons/stock/product.py b/addons/stock/product.py index 863b7111bb0..ae31909cfc1 100644 --- a/addons/stock/product.py +++ b/addons/stock/product.py @@ -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'), }