From 9481ee5c2f14c3ff185fbcd5a8bf790a8042024c Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Fri, 29 Jan 2016 16:43:10 +0100 Subject: [PATCH] [FIX] sale_margin: Cost price in a SO line The margin in a SO line is the difference between the price unit and the cost price of this SO line. In function "_product_margin" in model "sale.order.line", the cost price is equal to the purchase_price or the standard_price of the product. Then the cost price in the SO line must be set with the same value when creating SO line linked to the delivery. opw:668090 --- addons/delivery/sale.py | 5 +++++ addons/sale_margin/sale_margin.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/addons/delivery/sale.py b/addons/delivery/sale.py index 3512fb53b61..c6b89de649b 100644 --- a/addons/delivery/sale.py +++ b/addons/delivery/sale.py @@ -94,6 +94,11 @@ class sale_order(osv.Model): 'tax_id': [(6, 0, taxes_ids)], 'is_delivery': True, } + res = line_obj.product_id_change(cr, uid, ids, order.pricelist_id.id, values['product_id'], + qty=values['product_uom_qty'], uom=False, qty_uos=0, uos=False, name='', partner_id=order.partner_id.id, + lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False, context=None) + if res['value'].get('purchase_price'): + values['purchase_price'] = res['value'].get('purchase_price') if order.order_line: values['sequence'] = order.order_line[-1].sequence + 1 line_id = line_obj.create(cr, uid, values, context=context) diff --git a/addons/sale_margin/sale_margin.py b/addons/sale_margin/sale_margin.py index f1d2e7652ce..0cd3cdf14e4 100644 --- a/addons/sale_margin/sale_margin.py +++ b/addons/sale_margin/sale_margin.py @@ -87,7 +87,7 @@ class sale_order(osv.osv): _columns = { '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.line': (_get_order, ['margin', 'purchase_price', 'order_id'], 20), 'sale.order': (lambda self, cr, uid, ids, c={}: ids, ['order_line'], 20), }, digits_compute= dp.get_precision('Product Price')), }