From 8c4be231cc4f62b2e677bf237cfc9c9ada95e159 Mon Sep 17 00:00:00 2001 From: "ARA (OpenERP)" Date: Fri, 25 Feb 2011 18:09:01 +0530 Subject: [PATCH 1/3] [FIX] sale_margin: sale margin module : wrong computation lp bug: https://launchpad.net/bugs/715470 fixed bzr revid: ara@tinyerp.com-20110225123901-d5jn5p87blk73ksj --- addons/sale_margin/sale_margin.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/addons/sale_margin/sale_margin.py b/addons/sale_margin/sale_margin.py index f7bbf41e5d3..51fd4987825 100644 --- a/addons/sale_margin/sale_margin.py +++ b/addons/sale_margin/sale_margin.py @@ -48,8 +48,18 @@ class sale_order_line(osv.osv): res[line.id] = round((line.price_unit*line.product_uos_qty*(100.0-line.discount)/100.0) -(line.product_id.standard_price*line.product_uos_qty), 2) return res + def _get_sale_order(self, cr, uid, ids, context=None): + list_order_line = [] + for line in self.pool.get('sale.order').browse(cr, uid, ids, context=context): + for i in line.order_line: + list_order_line.append(i.id) + return list_order_line + _columns = { - 'margin': fields.function(_product_margin, method=True, string='Margin', store=True), + 'margin': fields.function(_product_margin, method=True, string='Margin', + store = { + 'sale.order': (_get_sale_order, None, 6), + }), 'purchase_price': fields.float('Cost Price', digits=(16,2)) } From fc5860236967d4d3c5f27f56fc7ef852df147184 Mon Sep 17 00:00:00 2001 From: "ARA (OpenERP)" Date: Fri, 25 Feb 2011 18:50:10 +0530 Subject: [PATCH 2/3] [FIX] sale_margin: sale margin module : wrong computation bzr revid: ara@tinyerp.com-20110225132010-iox9poe0eptdbynr --- addons/sale_margin/sale_margin.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/addons/sale_margin/sale_margin.py b/addons/sale_margin/sale_margin.py index 51fd4987825..8c7fc7bf4f1 100644 --- a/addons/sale_margin/sale_margin.py +++ b/addons/sale_margin/sale_margin.py @@ -48,9 +48,10 @@ class sale_order_line(osv.osv): res[line.id] = round((line.price_unit*line.product_uos_qty*(100.0-line.discount)/100.0) -(line.product_id.standard_price*line.product_uos_qty), 2) return res - def _get_sale_order(self, cr, uid, ids, context=None): + def _get_order_line(self, cr, uid, ids, context=None): + obj_sale_order = self.pool.get('sale.order') list_order_line = [] - for line in self.pool.get('sale.order').browse(cr, uid, ids, context=context): + for line in obj_sale_order.browse(cr, uid, ids, context=context): for i in line.order_line: list_order_line.append(i.id) return list_order_line @@ -58,7 +59,7 @@ class sale_order_line(osv.osv): _columns = { 'margin': fields.function(_product_margin, method=True, string='Margin', store = { - 'sale.order': (_get_sale_order, None, 6), + 'sale.order': (_get_order_line, None, 5), }), 'purchase_price': fields.float('Cost Price', digits=(16,2)) } From 206952d86eae6201c910ccb1a8fab8e51ef6c07d Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Thu, 10 Mar 2011 15:45:22 +0100 Subject: [PATCH 3/3] [FIX] adapted the fix of bug lp:715470 to use properly the store feature lp bug: https://launchpad.net/bugs/715470 fixed bzr revid: qdp-launchpad@openerp.com-20110310144522-tcx99kf8cdjuwpwi --- addons/sale_margin/sale_margin.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/addons/sale_margin/sale_margin.py b/addons/sale_margin/sale_margin.py index 8c7fc7bf4f1..619d0a96f97 100644 --- a/addons/sale_margin/sale_margin.py +++ b/addons/sale_margin/sale_margin.py @@ -48,19 +48,9 @@ class sale_order_line(osv.osv): res[line.id] = round((line.price_unit*line.product_uos_qty*(100.0-line.discount)/100.0) -(line.product_id.standard_price*line.product_uos_qty), 2) return res - def _get_order_line(self, cr, uid, ids, context=None): - obj_sale_order = self.pool.get('sale.order') - list_order_line = [] - for line in obj_sale_order.browse(cr, uid, ids, context=context): - for i in line.order_line: - list_order_line.append(i.id) - return list_order_line - _columns = { 'margin': fields.function(_product_margin, method=True, string='Margin', - store = { - 'sale.order': (_get_order_line, None, 5), - }), + store = True), 'purchase_price': fields.float('Cost Price', digits=(16,2)) } @@ -77,8 +67,14 @@ class sale_order(osv.osv): result[sale.id] += line.margin or 0.0 return result + def _get_order(self, cr, uid, ids, context=None): + return super(self,sale_order)._get_order(cr, uid, ids, context=context) + _columns = { - 'margin': fields.function(_product_margin, method=True, string='Margin', store=True, help="It gives profitability by calculating the difference between the Unit Price and Cost Price."), + 'margin': fields.function(_product_margin, method=True, string='Margin', help="It gives profitability by calculating the difference between the Unit Price and Cost Price.", store={ + 'sale.order.line': (_get_order, ['margin'], 20), + 'sale.order': (lambda self, cr, uid, ids, c={}: ids, ['order_line'], 20), + }), } sale_order()