Add margin in sale.report

This commit is contained in:
Alexis de Lattre
2018-11-21 16:44:05 +01:00
parent f480332d3a
commit 7b51c993ec
3 changed files with 21 additions and 3 deletions

View File

@@ -1,3 +1,4 @@
# -*- encoding: utf-8 -*-
from . import sale
from . import sale_report

View File

@@ -14,7 +14,7 @@ class SaleOrderLine(models.Model):
# Also defined in bi_sale_company_currency
company_currency_id = fields.Many2one(
related='order_id.company_id.currency_id',
readonly=True, store=True, compute_sudo=True, string='Company Currency')
readonly=True, store=True, string='Company Currency')
standard_price_company_currency = fields.Float(
string='Cost Price in Company Currency', readonly=True,
digits=dp.get_precision('Product Price'),
@@ -77,7 +77,7 @@ class SaleOrderLine(models.Model):
sale_uom = self.env['product.uom'].browse(sale_uom_id)
# convert from product UoM to sale UoM
std_price = pp.uom_id._compute_price(
standard_price, sale_uom)
pp.standard_price, sale_uom)
vals['standard_price_company_currency'] = std_price
return super(SaleOrderLine, self).create(vals)
@@ -108,7 +108,7 @@ class SaleOrder(models.Model):
# Also defined in bi_sale_company_currency
company_currency_id = fields.Many2one(
related='company_id.currency_id', readonly=True, store=True, compute_sudo=True,
related='company_id.currency_id', readonly=True, store=True,
string="Company Currency")
margin_sale_currency = fields.Monetary(
string='Margin in Sale Currency',

View File

@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
class SaleReport(models.Model):
_inherit = 'sale.report'
margin = fields.Float(string='Margin', readonly=True)
def _select(self):
select_str = super(SaleReport, self)._select()
select_str += ", SUM(l.margin_company_currency) AS margin"
return select_str