From c13b9a1262b2c575d08f0fe96100b016254330c9 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 7 May 2014 15:41:34 +0200 Subject: [PATCH] [FIX] code cleanup (addon procurement) improves the _orderpoint_count method. Also, as a bonus, the preexisting orderpoint_ids is not used in any other place, so it can be removed as well bzr revid: ged@openerp.com-20140507134134-isaor8ulq4pf5wrt --- addons/procurement/procurement.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/addons/procurement/procurement.py b/addons/procurement/procurement.py index a34e4171e75..94f428e3df5 100644 --- a/addons/procurement/procurement.py +++ b/addons/procurement/procurement.py @@ -615,15 +615,12 @@ class product_template(osv.osv): class product_product(osv.osv): _inherit="product.product" def _orderpoint_count(self, cr, uid, ids, field_name, arg, context=None): - res = dict(map(lambda x: (x,0), ids)) - try: - for orderpoint in self.browse(cr, uid, ids, context=context): - res[orderpoint.id] = len(orderpoint.orderpoint_ids) - except: - pass - return res + OrderPoints = self.pool('stock.warehouse.orderpoint') + return { + product_id: OrderPoints.search_count(cr, uid, [('product_id', '=', product_id)], context=context) + for product_id in ids + } _columns = { - 'orderpoint_ids': fields.one2many('stock.warehouse.orderpoint', 'product_id', 'Minimum Stock Rules'), 'orderpoint_count': fields.function(_orderpoint_count, string='# Orderpoints', type='integer'), }