[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
This commit is contained in:
parent
2083c16606
commit
9481ee5c2f
|
@ -94,6 +94,11 @@ class sale_order(osv.Model):
|
||||||
'tax_id': [(6, 0, taxes_ids)],
|
'tax_id': [(6, 0, taxes_ids)],
|
||||||
'is_delivery': True,
|
'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:
|
if order.order_line:
|
||||||
values['sequence'] = order.order_line[-1].sequence + 1
|
values['sequence'] = order.order_line[-1].sequence + 1
|
||||||
line_id = line_obj.create(cr, uid, values, context=context)
|
line_id = line_obj.create(cr, uid, values, context=context)
|
||||||
|
|
|
@ -87,7 +87,7 @@ class sale_order(osv.osv):
|
||||||
|
|
||||||
_columns = {
|
_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={
|
'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),
|
'sale.order': (lambda self, cr, uid, ids, c={}: ids, ['order_line'], 20),
|
||||||
}, digits_compute= dp.get_precision('Product Price')),
|
}, digits_compute= dp.get_precision('Product Price')),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue