From b47a121f4485b57350c7168f115fcabecf8437d7 Mon Sep 17 00:00:00 2001 From: "Amit Bhavsar (Open ERP)" Date: Fri, 12 Jul 2013 13:06:54 +0530 Subject: [PATCH] [Imp] Improve code for pricelists. bzr revid: amb@tinyerp.com-20130712073654-1fowt1xojgx0pjdc --- addons/product/pricelist.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/addons/product/pricelist.py b/addons/product/pricelist.py index 2396c56df34..649b721eb46 100644 --- a/addons/product/pricelist.py +++ b/addons/product/pricelist.py @@ -376,20 +376,26 @@ class product_pricelist_item(osv.osv): result.append((-2, _('Supplier Prices on the product form'))) return result - def _default_get(self, cr, uid, fields, context=None): - result = self._price_field_get(cr,uid,context) +# Added default function to fetch the Price type Based on Pricelist type. + def _get_default_base(self, cr, uid, fields, context=None): + product_price_type_obj = self.pool.get('product.price.type') if fields.get('type') == 'purchase': - base_value = [item for item in result if 'Cost Price' in item] - return base_value[0] + product_price_type_ids = product_price_type_obj.search(cr, uid, [('field', '=', 'standard_price')], context=context) + elif fields.get('type') == 'sale': + product_price_type_ids = product_price_type_obj.search(cr, uid, [('field','=','list_price')], context=context) else: - base_value = [item for item in result if 'Public Price' in item] - return base_value[0] + return -1 + if not product_price_type_ids: + return False + else: + pricetype = product_price_type_obj.browse(cr, uid, product_price_type_ids, context=context)[0] + return pricetype.id _name = "product.pricelist.item" _description = "Pricelist item" _order = "sequence, min_quantity desc" _defaults = { - 'base': _default_get, + 'base': _get_default_base, 'min_quantity': lambda *a: 0, 'sequence': lambda *a: 5, 'price_discount': lambda *a: 0,