From 0d74dce709fc237a26f8e194f546f0c61be60a33 Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Thu, 23 Apr 2015 11:59:34 +0200 Subject: [PATCH] [FIX] sale_margin: sale margin accuracy Unit Price, Cost Price and Margin must have the same accuracy. opw:632511 --- addons/sale_margin/sale_margin.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/addons/sale_margin/sale_margin.py b/addons/sale_margin/sale_margin.py index ec1bd83dd50..cdc3d99043d 100644 --- a/addons/sale_margin/sale_margin.py +++ b/addons/sale_margin/sale_margin.py @@ -19,6 +19,7 @@ ############################################################################## from openerp.osv import fields, osv +import openerp.addons.decimal_precision as dp class sale_order_line(osv.osv): _inherit = "sale.order.line" @@ -52,13 +53,13 @@ class sale_order_line(osv.osv): for line in self.browse(cr, uid, ids, context=context): res[line.id] = 0 if line.product_id: - res[line.id] = round(line.price_subtotal - ((line.purchase_price or line.product_id.standard_price) * line.product_uos_qty), 2) + res[line.id] = line.price_subtotal - ((line.purchase_price or line.product_id.standard_price) * line.product_uos_qty) return res _columns = { - 'margin': fields.function(_product_margin, string='Margin', + 'margin': fields.function(_product_margin, string='Margin', digits_compute= dp.get_precision('Product Price'), store = True), - 'purchase_price': fields.float('Cost Price', digits=(16,2)) + 'purchase_price': fields.float('Cost Price', digits_compute= dp.get_precision('Product Price')) } @@ -83,7 +84,7 @@ class sale_order(osv.osv): 'margin': fields.function(_product_margin, string='Margin', help="It gives profitability by calculating the difference between the Unit Price and the cost price.", store={ 'sale.order.line': (_get_order, ['margin', 'purchase_price'], 20), 'sale.order': (lambda self, cr, uid, ids, c={}: ids, ['order_line'], 20), - }), + }, digits_compute= dp.get_precision('Product Price')), }