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'),
}