From 527e1558c935450229456f438c7d7befba3f0be6 Mon Sep 17 00:00:00 2001 From: "Divyesh Makwana (Open ERP)" Date: Wed, 19 Sep 2012 15:17:51 +0530 Subject: [PATCH 01/18] [ADD] product : Added a constraint to check Minimum Margin must be lower than Maximum Margin. bzr revid: mdi@tinyerp.com-20120919094751-3pjr3h9cuar3wgh5 --- addons/product/pricelist.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/addons/product/pricelist.py b/addons/product/pricelist.py index c333000621a..7af572bf411 100644 --- a/addons/product/pricelist.py +++ b/addons/product/pricelist.py @@ -423,6 +423,9 @@ class product_pricelist_item(osv.osv): readonly=True, relation='res.company', string='Company', store=True) } + _sql_constraints = [ + ('check_margin', 'CHECK (price_min_margin <= price_max_margin)', 'Minimum Margin must be lower than Maximum Margin !'), + ] _constraints = [ (_check_recursion, 'Error ! You cannot assign the Main Pricelist as Other Pricelist in PriceList Item!', ['base_pricelist_id']) ] From c31eb654b2efa794a233b84301bc99fdaced15b0 Mon Sep 17 00:00:00 2001 From: "Divyesh Makwana (Open ERP)" Date: Wed, 19 Sep 2012 16:35:40 +0530 Subject: [PATCH 02/18] [ADD] Added a tooltip for pricelist rule. bzr revid: mdi@tinyerp.com-20120919110540-w4jdpozlsk173gv3 --- addons/product/pricelist.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/product/pricelist.py b/addons/product/pricelist.py index 7af572bf411..9b37dc0fe07 100644 --- a/addons/product/pricelist.py +++ b/addons/product/pricelist.py @@ -401,13 +401,13 @@ class product_pricelist_item(osv.osv): 'product_id': fields.many2one('product.product', 'Product', ondelete='cascade', help="Set a product if this rule only apply to one product. Keep empty for all products"), 'categ_id': fields.many2one('product.category', 'Product Category', ondelete='cascade', help="Set a category of product if this rule only apply to products of a category and his children. Keep empty for all products"), - 'min_quantity': fields.integer('Min. Quantity', required=True, help="The rule only applies if the partner buys/sells more than this quantity."), + 'min_quantity': fields.integer('Min. Quantity', required=True, help="The rule only applies if the partner buys/sells quantity equal to or more than this quantity set."), 'sequence': fields.integer('Sequence', required=True, help="Gives the order in which the pricelist items will be checked. The evaluation gives highest priority to lowest sequence and stops as soon as a matching item is found."), 'base': fields.selection(_price_field_get, 'Based on', required=True, size=-1, help="The mode for computing the price for this rule."), 'base_pricelist_id': fields.many2one('product.pricelist', 'If Other Pricelist'), 'price_surcharge': fields.float('Price Surcharge', - digits_compute= dp.get_precision('Product Price')), + digits_compute= dp.get_precision('Product Price'), help='Specify the fixed amount to add(or substract, if negative) to the amount calculated with the discount.'), 'price_discount': fields.float('Price Discount', digits=(16,4)), 'price_round': fields.float('Price Rounding', digits_compute= dp.get_precision('Product Price'), @@ -416,9 +416,9 @@ class product_pricelist_item(osv.osv): "To have prices that end in 9.99, set rounding 10, surcharge -0.01" \ ), 'price_min_margin': fields.float('Min. Price Margin', - digits_compute= dp.get_precision('Product Price')), + digits_compute= dp.get_precision('Product Price'), help='Specify the minimum amount of margin over the base price.'), 'price_max_margin': fields.float('Max. Price Margin', - digits_compute= dp.get_precision('Product Price')), + digits_compute= dp.get_precision('Product Price'), help='Specify the maximum amount of margin over the base price.'), 'company_id': fields.related('price_version_id','company_id',type='many2one', readonly=True, relation='res.company', string='Company', store=True) } From 2218b02926142ab97dab4f8aeaeebc53a3d3d88e Mon Sep 17 00:00:00 2001 From: "Divyesh Makwana (Open ERP)" Date: Wed, 19 Sep 2012 18:43:05 +0530 Subject: [PATCH 03/18] [FIX] product : Improved the test cases. bzr revid: mdi@tinyerp.com-20120919131305-gyn847qpagdujq0h --- addons/product/product_pricelist_demo.yml | 2 +- addons/product/test/product_pricelist.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/product/product_pricelist_demo.yml b/addons/product/product_pricelist_demo.yml index 39f6cfc16b2..efb812ad5e2 100644 --- a/addons/product/product_pricelist_demo.yml +++ b/addons/product/product_pricelist_demo.yml @@ -47,7 +47,7 @@ - name: 20% Discount given by my supplier sequence: 1 price_min_margin: 2 - price_max_margin: -5 + price_max_margin: 5 product_id: product_product_6 base: -2 - diff --git a/addons/product/test/product_pricelist.yml b/addons/product/test/product_pricelist.yml index 85230261312..66e256d4cd1 100644 --- a/addons/product/test/product_pricelist.yml +++ b/addons/product/test/product_pricelist.yml @@ -49,14 +49,14 @@ !python {model: product.product}: | context.update({'quantity':1, 'date': False, 'partner': ref('base.res_partner_4'), 'pricelist': ref("supplier_pricelist")}) product = self.browse(cr, uid, ref("product_product_6"), context=context) - assert product.price == 785, "cost price is not correspond." + assert product.price == 792, "cost price is not correspond." - I check cost price of LCD Monitor if more than 3 Unit. - !python {model: product.product}: | context.update({'quantity':3}) product = self.browse(cr, uid, ref("product_product_6"), context=context) - assert product.price == 780, "cost price is not correspond." + assert product.price == 787, "cost price is not correspond." - I print the sale prices report. From d86cc61f08b76b0127458487dc7ff3c5c7a1801a Mon Sep 17 00:00:00 2001 From: "Divyesh Makwana (Open ERP)" Date: Mon, 24 Sep 2012 13:01:26 +0530 Subject: [PATCH 04/18] [ADD] product : Added warning message on onchange of min/max margin value. bzr revid: mdi@tinyerp.com-20120924073126-ejkeieiz81zc1udo --- addons/product/pricelist.py | 13 +++++++++++++ addons/product/pricelist_view.xml | 10 +++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/addons/product/pricelist.py b/addons/product/pricelist.py index 9b37dc0fe07..02b2605d8cf 100644 --- a/addons/product/pricelist.py +++ b/addons/product/pricelist.py @@ -437,6 +437,19 @@ class product_pricelist_item(osv.osv): if prod[0]['code']: return {'value': {'name': prod[0]['code']}} return {} + + def onchange_margin(self, cr, uid, ids, price_min_margin, price_max_margin, context=None): + res = {'value': {}} + if not price_min_margin and not price_max_margin: + return res + if price_min_margin > price_max_margin: + res['warning'] = {'title': _('Warning!'), 'message': _('Minimum Margin must be lower than Maximum Margin !.')} + pricelist_rule = self.browse(cr, uid, ids, context=context)[0] + min_margin = pricelist_rule.price_min_margin + max_margin = pricelist_rule.price_max_margin + res['value'].update({'price_min_margin': min_margin, 'price_max_margin': max_margin}) + return res + product_pricelist_item() diff --git a/addons/product/pricelist_view.xml b/addons/product/pricelist_view.xml index dc120660c43..7dcdeae15e8 100644 --- a/addons/product/pricelist_view.xml +++ b/addons/product/pricelist_view.xml @@ -20,7 +20,11 @@ - + + + + + @@ -103,8 +107,8 @@ - - + + From e708ec5345d4e45db0dcaed4211667dfaaa06da0 Mon Sep 17 00:00:00 2001 From: "Divyesh Makwana (Open ERP)" Date: Mon, 24 Sep 2012 14:12:42 +0530 Subject: [PATCH 05/18] [IMP] product : Added warning message on onchange of min/max margin value. bzr revid: mdi@tinyerp.com-20120924084242-v6cly3hpsotn2y4b --- addons/product/pricelist.py | 11 ++++++++--- addons/product/pricelist_view.xml | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/addons/product/pricelist.py b/addons/product/pricelist.py index 02b2605d8cf..3c1d5febc75 100644 --- a/addons/product/pricelist.py +++ b/addons/product/pricelist.py @@ -445,9 +445,14 @@ class product_pricelist_item(osv.osv): if price_min_margin > price_max_margin: res['warning'] = {'title': _('Warning!'), 'message': _('Minimum Margin must be lower than Maximum Margin !.')} pricelist_rule = self.browse(cr, uid, ids, context=context)[0] - min_margin = pricelist_rule.price_min_margin - max_margin = pricelist_rule.price_max_margin - res['value'].update({'price_min_margin': min_margin, 'price_max_margin': max_margin}) + min_margin = 0.0 + max_margin = 0.0 + if price_min_margin: + min_margin = pricelist_rule.price_min_margin + res['value'].update({'price_min_margin': min_margin}) + if price_max_margin: + max_margin = pricelist_rule.price_max_margin + res['value'].update({'price_max_margin': max_margin}) return res product_pricelist_item() diff --git a/addons/product/pricelist_view.xml b/addons/product/pricelist_view.xml index 7dcdeae15e8..47fada812d2 100644 --- a/addons/product/pricelist_view.xml +++ b/addons/product/pricelist_view.xml @@ -107,8 +107,8 @@ - - + + From e8060bc72efcedc8e144515018b3221fed688db7 Mon Sep 17 00:00:00 2001 From: "Divyesh Makwana (Open ERP)" Date: Mon, 24 Sep 2012 14:15:36 +0530 Subject: [PATCH 06/18] [REM] product : Removed constraint on min/max margin value. bzr revid: mdi@tinyerp.com-20120924084536-r429tvqy9jhjytjo --- addons/product/pricelist.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/addons/product/pricelist.py b/addons/product/pricelist.py index 3c1d5febc75..e98086d49e2 100644 --- a/addons/product/pricelist.py +++ b/addons/product/pricelist.py @@ -423,9 +423,6 @@ class product_pricelist_item(osv.osv): readonly=True, relation='res.company', string='Company', store=True) } - _sql_constraints = [ - ('check_margin', 'CHECK (price_min_margin <= price_max_margin)', 'Minimum Margin must be lower than Maximum Margin !'), - ] _constraints = [ (_check_recursion, 'Error ! You cannot assign the Main Pricelist as Other Pricelist in PriceList Item!', ['base_pricelist_id']) ] From eb1ca681283f41fd6bffd19b817b5be04351860b Mon Sep 17 00:00:00 2001 From: "Divyesh Makwana (Open ERP)" Date: Mon, 24 Sep 2012 14:25:03 +0530 Subject: [PATCH 07/18] [IMP] product : Improved onchange on min/max margin value. bzr revid: mdi@tinyerp.com-20120924085503-ckhxdgcvqb0h6qjh --- addons/product/pricelist.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/product/pricelist.py b/addons/product/pricelist.py index e98086d49e2..7ac908e262f 100644 --- a/addons/product/pricelist.py +++ b/addons/product/pricelist.py @@ -446,10 +446,10 @@ class product_pricelist_item(osv.osv): max_margin = 0.0 if price_min_margin: min_margin = pricelist_rule.price_min_margin - res['value'].update({'price_min_margin': min_margin}) + res['value'] = dict(res['value'], price_min_margin = min_margin) if price_max_margin: max_margin = pricelist_rule.price_max_margin - res['value'].update({'price_max_margin': max_margin}) + res['value'] = dict(res['value'], price_max_margin = max_margin) return res product_pricelist_item() From d4013af9e5e5bfe270dc8187ee8c000b975f541d Mon Sep 17 00:00:00 2001 From: "Divyesh Makwana (Open ERP)" Date: Mon, 24 Sep 2012 15:23:22 +0530 Subject: [PATCH 08/18] [IMP] product : Improved onchange on min/max margin value. bzr revid: mdi@tinyerp.com-20120924095322-jtgzlxkohon6qc6y --- addons/product/pricelist.py | 13 +++---------- addons/product/pricelist_view.xml | 4 ++-- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/addons/product/pricelist.py b/addons/product/pricelist.py index 7ac908e262f..7d47f2e2136 100644 --- a/addons/product/pricelist.py +++ b/addons/product/pricelist.py @@ -436,20 +436,13 @@ class product_pricelist_item(osv.osv): return {} def onchange_margin(self, cr, uid, ids, price_min_margin, price_max_margin, context=None): - res = {'value': {}} + res = {'value': {'price_min_margin': 0.0, 'price_max_margin': 0.0}} if not price_min_margin and not price_max_margin: return res if price_min_margin > price_max_margin: res['warning'] = {'title': _('Warning!'), 'message': _('Minimum Margin must be lower than Maximum Margin !.')} - pricelist_rule = self.browse(cr, uid, ids, context=context)[0] - min_margin = 0.0 - max_margin = 0.0 - if price_min_margin: - min_margin = pricelist_rule.price_min_margin - res['value'] = dict(res['value'], price_min_margin = min_margin) - if price_max_margin: - max_margin = pricelist_rule.price_max_margin - res['value'] = dict(res['value'], price_max_margin = max_margin) + else: + res = {'value': {'price_min_margin': price_min_margin, 'price_max_margin': price_max_margin}} return res product_pricelist_item() diff --git a/addons/product/pricelist_view.xml b/addons/product/pricelist_view.xml index 47fada812d2..7dcdeae15e8 100644 --- a/addons/product/pricelist_view.xml +++ b/addons/product/pricelist_view.xml @@ -107,8 +107,8 @@ - - + + 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 09/18] [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 @@ - - + + From 8957669dca01745b87f3eb832d11a5d2c386c2c7 Mon Sep 17 00:00:00 2001 From: "Divyesh Makwana (Open ERP)" Date: Mon, 24 Sep 2012 17:14:20 +0530 Subject: [PATCH 10/18] [ADD] product : Improved the warning message. bzr revid: mdi@tinyerp.com-20120924114420-qy1lviihna6odv6e --- addons/product/pricelist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/product/pricelist.py b/addons/product/pricelist.py index 7cac03b6a5d..92c054b82bd 100644 --- a/addons/product/pricelist.py +++ b/addons/product/pricelist.py @@ -440,7 +440,7 @@ class product_pricelist_item(osv.osv): 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: - raise osv.except_osv(_('Warning!'), _('In \'%s\' pricelist rule, minimum margin must be lower than maximum margin !.') % (name)) + raise osv.except_osv(_('Warning!'), _('Minimum margin must be lower than maximum margin in \'%s\' pricelist rule !.') % (name)) return super(product_pricelist_item, self).write(cr, uid, ids, vals, context=context) From 3bcf43b06b3a80643faf1597fe4e8f95c42432e5 Mon Sep 17 00:00:00 2001 From: "Divyesh Makwana (Open ERP)" Date: Mon, 24 Sep 2012 17:45:42 +0530 Subject: [PATCH 11/18] [ADD] product : Override create method in order to check 'Min margin' and 'Max margin'. bzr revid: mdi@tinyerp.com-20120924121542-0031rv1ozrxlvc9a --- addons/product/pricelist.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/addons/product/pricelist.py b/addons/product/pricelist.py index 92c054b82bd..4f848201d9d 100644 --- a/addons/product/pricelist.py +++ b/addons/product/pricelist.py @@ -434,13 +434,22 @@ class product_pricelist_item(osv.osv): if prod[0]['code']: return {'value': {'name': prod[0]['code']}} return {} - - def write(self, cr, uid, ids, vals, context=None): - name = self.browse(cr, uid, ids, context=context)[0].name + + def create(self, cr, uid, vals, context=None): + name = vals.get('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: raise osv.except_osv(_('Warning!'), _('Minimum margin must be lower than maximum margin in \'%s\' pricelist rule !.') % (name)) + return super(product_pricelist_item, self).create(cr, uid, vals, context=context) + + def write(self, cr, uid, ids, vals, context=None): + price_min_margin = vals.get('price_min_margin', 0.0) + price_max_margin = vals.get('price_max_margin', 0.0) + for rule in self.browse(cr, uid, ids, context=context): + name = rule.name + if price_min_margin > price_max_margin: + raise osv.except_osv(_('Warning!'), _('Minimum margin must be lower than maximum margin in \'%s\' pricelist rule !.') % (name)) return super(product_pricelist_item, self).write(cr, uid, ids, vals, context=context) From fc9b27af796744fb645941de20a74fc136abbbda Mon Sep 17 00:00:00 2001 From: "Divyesh Makwana (Open ERP)" Date: Mon, 24 Sep 2012 18:30:43 +0530 Subject: [PATCH 12/18] [IMP] product : Improved the warning message. bzr revid: mdi@tinyerp.com-20120924130043-euwxbfmk5q58vqw4 --- addons/product/pricelist.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/product/pricelist.py b/addons/product/pricelist.py index 4f848201d9d..14392c79f10 100644 --- a/addons/product/pricelist.py +++ b/addons/product/pricelist.py @@ -440,7 +440,7 @@ class product_pricelist_item(osv.osv): 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: - raise osv.except_osv(_('Warning!'), _('Minimum margin must be lower than maximum margin in \'%s\' pricelist rule !.') % (name)) + raise osv.except_osv(_('Warning!'), _('Minimum margin must be lower than maximum margin in \'%s\' pricelist rule!') % (name)) return super(product_pricelist_item, self).create(cr, uid, vals, context=context) def write(self, cr, uid, ids, vals, context=None): @@ -449,7 +449,7 @@ class product_pricelist_item(osv.osv): for rule in self.browse(cr, uid, ids, context=context): name = rule.name if price_min_margin > price_max_margin: - raise osv.except_osv(_('Warning!'), _('Minimum margin must be lower than maximum margin in \'%s\' pricelist rule !.') % (name)) + raise osv.except_osv(_('Warning!'), _('Minimum margin must be lower than maximum margin in \'%s\' pricelist rule!') % (name)) return super(product_pricelist_item, self).write(cr, uid, ids, vals, context=context) From 2ea34c71f8e9a7ae84e6cff31862469027e19dd8 Mon Sep 17 00:00:00 2001 From: "Divyesh Makwana (Open ERP)" Date: Tue, 25 Sep 2012 12:26:19 +0530 Subject: [PATCH 13/18] [IMP] product : Override create and write method in order to check 'Min margin' and 'Max margin'. bzr revid: mdi@tinyerp.com-20120925065619-g2n8h78ioou3q7ch --- addons/product/pricelist.py | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/addons/product/pricelist.py b/addons/product/pricelist.py index 14392c79f10..c011dcd3aa6 100644 --- a/addons/product/pricelist.py +++ b/addons/product/pricelist.py @@ -436,23 +436,42 @@ class product_pricelist_item(osv.osv): return {} def create(self, cr, uid, vals, context=None): - name = vals.get('name', '') + name = vals.get('name', False) + sequence = vals.get('sequence', False) 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: - raise osv.except_osv(_('Warning!'), _('Minimum margin must be lower than maximum margin in \'%s\' pricelist rule!') % (name)) + if name: + raise osv.except_osv(_('Warning!'), _('Minimum margin must be lower than maximum margin for pricelist rule: \'%s\'(sequence: %s).') % (name, sequence)) + else: + raise osv.except_osv(_('Warning!'), _('Minimum margin must be lower than maximum margin for pricelist rule having sequence %s.') % (sequence)) return super(product_pricelist_item, self).create(cr, uid, vals, context=context) def write(self, cr, uid, ids, vals, context=None): - price_min_margin = vals.get('price_min_margin', 0.0) - price_max_margin = vals.get('price_max_margin', 0.0) for rule in self.browse(cr, uid, ids, context=context): - name = rule.name + if vals.get('name', False): + name = vals['name'] + else: + name = rule.name + if vals.get('sequence', False): + sequence = vals['sequence'] + else: + sequence = rule.sequence + if vals.get('price_min_margin', False): + price_min_margin = vals['price_min_margin'] + else: + price_min_margin = rule.price_min_margin + if vals.get('price_max_margin', False): + price_max_margin = vals['price_max_margin'] + else: + price_max_margin = rule.price_max_margin if price_min_margin > price_max_margin: - raise osv.except_osv(_('Warning!'), _('Minimum margin must be lower than maximum margin in \'%s\' pricelist rule!') % (name)) + if name: + raise osv.except_osv(_('Warning!'), _('Minimum margin must be lower than maximum margin for pricelist rule: \'%s\'(sequence: %s).') % (name, sequence)) + else: + raise osv.except_osv(_('Warning!'), _('Minimum margin must be lower than maximum margin for pricelist rule having sequence %s.') % (sequence)) return super(product_pricelist_item, self).write(cr, uid, ids, vals, context=context) - product_pricelist_item() From 974935a6f87195ee75a02fc20f88edc400133920 Mon Sep 17 00:00:00 2001 From: "Divyesh Makwana (Open ERP)" Date: Tue, 25 Sep 2012 12:41:37 +0530 Subject: [PATCH 14/18] [IMP] product : Override create and write method in order to check 'Min margin' and 'Max margin'. bzr revid: mdi@tinyerp.com-20120925071137-dchr17sj1nzxginy --- addons/product/pricelist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/product/pricelist.py b/addons/product/pricelist.py index c011dcd3aa6..d44899d0688 100644 --- a/addons/product/pricelist.py +++ b/addons/product/pricelist.py @@ -449,7 +449,7 @@ class product_pricelist_item(osv.osv): def write(self, cr, uid, ids, vals, context=None): for rule in self.browse(cr, uid, ids, context=context): - if vals.get('name', False): + if vals.has_key('name'): name = vals['name'] else: name = rule.name From 5d910cc881691510df33f223aceb40fc2cda0768 Mon Sep 17 00:00:00 2001 From: "Divyesh Makwana (Open ERP)" Date: Tue, 25 Sep 2012 12:57:01 +0530 Subject: [PATCH 15/18] [IMP] product : Override create and write method in order to check 'Min margin' and 'Max margin'. bzr revid: mdi@tinyerp.com-20120925072701-6nus286naxzujp1e --- addons/product/pricelist.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/addons/product/pricelist.py b/addons/product/pricelist.py index d44899d0688..a0d8ce8170d 100644 --- a/addons/product/pricelist.py +++ b/addons/product/pricelist.py @@ -448,22 +448,20 @@ class product_pricelist_item(osv.osv): return super(product_pricelist_item, self).create(cr, uid, vals, context=context) def write(self, cr, uid, ids, vals, context=None): + name = None + if vals.has_key('name'): + name = vals['name'] + sequence = vals.get('sequence', False) + price_min_margin = vals.get('price_min_margin', 0.0) + price_max_margin = vals.get('price_max_margin', 0.0) for rule in self.browse(cr, uid, ids, context=context): - if vals.has_key('name'): - name = vals['name'] - else: + if name is None: name = rule.name - if vals.get('sequence', False): - sequence = vals['sequence'] - else: + if not sequence: sequence = rule.sequence - if vals.get('price_min_margin', False): - price_min_margin = vals['price_min_margin'] - else: + if not price_min_margin: price_min_margin = rule.price_min_margin - if vals.get('price_max_margin', False): - price_max_margin = vals['price_max_margin'] - else: + if not price_max_margin: price_max_margin = rule.price_max_margin if price_min_margin > price_max_margin: if name: From 6a5f24f92d4249183c78cfa6c473398a9757ff29 Mon Sep 17 00:00:00 2001 From: "Divyesh Makwana (Open ERP)" Date: Tue, 25 Sep 2012 15:34:57 +0530 Subject: [PATCH 16/18] [IMP] product : Improved the tooltip. bzr revid: mdi@tinyerp.com-20120925100457-o1yw9k2opljaz4m6 --- addons/product/pricelist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/product/pricelist.py b/addons/product/pricelist.py index a0d8ce8170d..6403a24ae81 100644 --- a/addons/product/pricelist.py +++ b/addons/product/pricelist.py @@ -401,7 +401,7 @@ class product_pricelist_item(osv.osv): 'product_id': fields.many2one('product.product', 'Product', ondelete='cascade', help="Set a product if this rule only apply to one product. Keep empty for all products"), 'categ_id': fields.many2one('product.category', 'Product Category', ondelete='cascade', help="Set a category of product if this rule only apply to products of a category and his children. Keep empty for all products"), - 'min_quantity': fields.integer('Min. Quantity', required=True, help="The rule only applies if the partner buys/sells quantity equal to or more than this quantity set."), + 'min_quantity': fields.integer('Min. Quantity', required=True, help="The rule only applies if the partner buys/sells equal to or more than this quantity."), 'sequence': fields.integer('Sequence', required=True, help="Gives the order in which the pricelist items will be checked. The evaluation gives highest priority to lowest sequence and stops as soon as a matching item is found."), 'base': fields.selection(_price_field_get, 'Based on', required=True, size=-1, help="The mode for computing the price for this rule."), 'base_pricelist_id': fields.many2one('product.pricelist', 'If Other Pricelist'), From 26ba2b8c0f9961d73ea78d7b69ec5992661d786e Mon Sep 17 00:00:00 2001 From: "Divyesh Makwana (Open ERP)" Date: Tue, 25 Sep 2012 15:48:50 +0530 Subject: [PATCH 17/18] [IMP] product : Improved the tooltip. bzr revid: mdi@tinyerp.com-20120925101850-q9soju7mvol43eyo --- addons/product/pricelist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/product/pricelist.py b/addons/product/pricelist.py index 6403a24ae81..a8695476e64 100644 --- a/addons/product/pricelist.py +++ b/addons/product/pricelist.py @@ -407,7 +407,7 @@ class product_pricelist_item(osv.osv): 'base_pricelist_id': fields.many2one('product.pricelist', 'If Other Pricelist'), 'price_surcharge': fields.float('Price Surcharge', - digits_compute= dp.get_precision('Product Price'), help='Specify the fixed amount to add(or substract, if negative) to the amount calculated with the discount.'), + digits_compute= dp.get_precision('Product Price'), help='Specify the fixed amount to add or substract(if negative) to the amount calculated with the discount.'), 'price_discount': fields.float('Price Discount', digits=(16,4)), 'price_round': fields.float('Price Rounding', digits_compute= dp.get_precision('Product Price'), From 28063542d6c2b8884327716caa0b0ccc8f283d12 Mon Sep 17 00:00:00 2001 From: "Divyesh Makwana (Open ERP)" Date: Tue, 25 Sep 2012 17:18:22 +0530 Subject: [PATCH 18/18] [ADD] product : Added a constraint to check 'Min margin' and 'Max margin'. bzr revid: mdi@tinyerp.com-20120925114822-ahjtslxh1g0inypw --- addons/product/pricelist.py | 48 +++++++++---------------------------- 1 file changed, 11 insertions(+), 37 deletions(-) diff --git a/addons/product/pricelist.py b/addons/product/pricelist.py index a8695476e64..64c4aba9980 100644 --- a/addons/product/pricelist.py +++ b/addons/product/pricelist.py @@ -394,6 +394,15 @@ class product_pricelist_item(osv.osv): return False return True + def _check_margin(self, cr, uid, ids, context=None): + for item in self.browse(cr, uid, ids, context=context): + if item.price_min_margin > item.price_max_margin: + if item.name: + raise osv.except_osv(_('Warning!'), _('Minimum margin must be lower than maximum margin for pricelist rule: \'%s\'(sequence: %s).') % (item.name, item.sequence)) + else: + raise osv.except_osv(_('Warning!'), _('Minimum margin must be lower than maximum margin for pricelist rule having sequence %s.') % (item.sequence)) + return True + _columns = { 'name': fields.char('Rule Name', size=64, help="Explicit rule name for this pricelist line."), 'price_version_id': fields.many2one('product.pricelist.version', 'Price List Version', required=True, select=True, ondelete='cascade'), @@ -424,7 +433,8 @@ class product_pricelist_item(osv.osv): } _constraints = [ - (_check_recursion, 'Error ! You cannot assign the Main Pricelist as Other Pricelist in PriceList Item!', ['base_pricelist_id']) + (_check_recursion, 'Error ! You cannot assign the Main Pricelist as Other Pricelist in PriceList Item!', ['base_pricelist_id']), + (_check_margin, '', ['price_min_margin', 'price_max_margin']) ] def product_id_change(self, cr, uid, ids, product_id, context=None): @@ -434,42 +444,6 @@ class product_pricelist_item(osv.osv): if prod[0]['code']: return {'value': {'name': prod[0]['code']}} return {} - - def create(self, cr, uid, vals, context=None): - name = vals.get('name', False) - sequence = vals.get('sequence', False) - 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: - if name: - raise osv.except_osv(_('Warning!'), _('Minimum margin must be lower than maximum margin for pricelist rule: \'%s\'(sequence: %s).') % (name, sequence)) - else: - raise osv.except_osv(_('Warning!'), _('Minimum margin must be lower than maximum margin for pricelist rule having sequence %s.') % (sequence)) - return super(product_pricelist_item, self).create(cr, uid, vals, context=context) - - def write(self, cr, uid, ids, vals, context=None): - name = None - if vals.has_key('name'): - name = vals['name'] - sequence = vals.get('sequence', False) - price_min_margin = vals.get('price_min_margin', 0.0) - price_max_margin = vals.get('price_max_margin', 0.0) - for rule in self.browse(cr, uid, ids, context=context): - if name is None: - name = rule.name - if not sequence: - sequence = rule.sequence - if not price_min_margin: - price_min_margin = rule.price_min_margin - if not price_max_margin: - price_max_margin = rule.price_max_margin - if price_min_margin > price_max_margin: - if name: - raise osv.except_osv(_('Warning!'), _('Minimum margin must be lower than maximum margin for pricelist rule: \'%s\'(sequence: %s).') % (name, sequence)) - else: - raise osv.except_osv(_('Warning!'), _('Minimum margin must be lower than maximum margin for pricelist rule having sequence %s.') % (sequence)) - return super(product_pricelist_item, self).write(cr, uid, ids, vals, context=context) - product_pricelist_item()