From d306cc49c88205efced594871db8d7c46ba6c9b0 Mon Sep 17 00:00:00 2001 From: "Divyesh Makwana (Open ERP)" Date: Mon, 24 Sep 2012 17:03:57 +0530 Subject: [PATCH] [ADD] product : Override write method in order to check 'Min margin' and 'Max margin'. bzr revid: mdi@tinyerp.com-20120924113357-195gynto9xm7ae2a --- addons/product/pricelist.py | 15 +++++++-------- addons/product/pricelist_view.xml | 4 ++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/addons/product/pricelist.py b/addons/product/pricelist.py index 7d47f2e2136..7cac03b6a5d 100644 --- a/addons/product/pricelist.py +++ b/addons/product/pricelist.py @@ -435,15 +435,14 @@ class product_pricelist_item(osv.osv): return {'value': {'name': prod[0]['code']}} return {} - def onchange_margin(self, cr, uid, ids, price_min_margin, price_max_margin, context=None): - res = {'value': {'price_min_margin': 0.0, 'price_max_margin': 0.0}} - if not price_min_margin and not price_max_margin: - return res + def write(self, cr, uid, ids, vals, context=None): + name = self.browse(cr, uid, ids, context=context)[0].name + price_min_margin = vals.get('price_min_margin', 0.0) + price_max_margin = vals.get('price_max_margin', 0.0) if price_min_margin > price_max_margin: - res['warning'] = {'title': _('Warning!'), 'message': _('Minimum Margin must be lower than Maximum Margin !.')} - else: - res = {'value': {'price_min_margin': price_min_margin, 'price_max_margin': price_max_margin}} - return res + raise osv.except_osv(_('Warning!'), _('In \'%s\' pricelist rule, minimum margin must be lower than maximum margin !.') % (name)) + return super(product_pricelist_item, self).write(cr, uid, ids, vals, context=context) + product_pricelist_item() diff --git a/addons/product/pricelist_view.xml b/addons/product/pricelist_view.xml index 7dcdeae15e8..03835721709 100644 --- a/addons/product/pricelist_view.xml +++ b/addons/product/pricelist_view.xml @@ -107,8 +107,8 @@ - - + +