Add margin in sale.report
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
|
|
||||||
from . import sale
|
from . import sale
|
||||||
|
from . import sale_report
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class SaleOrderLine(models.Model):
|
|||||||
# Also defined in bi_sale_company_currency
|
# Also defined in bi_sale_company_currency
|
||||||
company_currency_id = fields.Many2one(
|
company_currency_id = fields.Many2one(
|
||||||
related='order_id.company_id.currency_id',
|
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(
|
standard_price_company_currency = fields.Float(
|
||||||
string='Cost Price in Company Currency', readonly=True,
|
string='Cost Price in Company Currency', readonly=True,
|
||||||
digits=dp.get_precision('Product Price'),
|
digits=dp.get_precision('Product Price'),
|
||||||
@@ -77,7 +77,7 @@ class SaleOrderLine(models.Model):
|
|||||||
sale_uom = self.env['product.uom'].browse(sale_uom_id)
|
sale_uom = self.env['product.uom'].browse(sale_uom_id)
|
||||||
# convert from product UoM to sale UoM
|
# convert from product UoM to sale UoM
|
||||||
std_price = pp.uom_id._compute_price(
|
std_price = pp.uom_id._compute_price(
|
||||||
standard_price, sale_uom)
|
pp.standard_price, sale_uom)
|
||||||
vals['standard_price_company_currency'] = std_price
|
vals['standard_price_company_currency'] = std_price
|
||||||
return super(SaleOrderLine, self).create(vals)
|
return super(SaleOrderLine, self).create(vals)
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ class SaleOrder(models.Model):
|
|||||||
|
|
||||||
# Also defined in bi_sale_company_currency
|
# Also defined in bi_sale_company_currency
|
||||||
company_currency_id = fields.Many2one(
|
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")
|
string="Company Currency")
|
||||||
margin_sale_currency = fields.Monetary(
|
margin_sale_currency = fields.Monetary(
|
||||||
string='Margin in Sale Currency',
|
string='Margin in Sale Currency',
|
||||||
|
|||||||
17
sale_margin_no_onchange/sale_report.py
Normal file
17
sale_margin_no_onchange/sale_report.py
Normal 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
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
from . import report
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
##############################################################################
|
|
||||||
#
|
|
||||||
# Sale Margin Report module for Odoo
|
|
||||||
# Copyright (C) 2016 Akretion (http://www.akretion.com)
|
|
||||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as
|
|
||||||
# published by the Free Software Foundation, either version 3 of the
|
|
||||||
# License, or (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
##############################################################################
|
|
||||||
|
|
||||||
|
|
||||||
{
|
|
||||||
'name': 'Sale Margin Report',
|
|
||||||
'version': '0.1',
|
|
||||||
'category': 'Sales Management',
|
|
||||||
'license': 'AGPL-3',
|
|
||||||
'summary': 'Add margin measure in Sales Analysis',
|
|
||||||
'description': """
|
|
||||||
This module adds the measure *Margin* in the Sales Analysis pivot table. It is in a separate module because it depends on the module *bi_sale_company_currency* (in which I re-wrote the Sales Analysis pivot table).
|
|
||||||
|
|
||||||
This module has been written by Alexis de Lattre from Akretion
|
|
||||||
<alexis.delattre@akretion.com>.
|
|
||||||
""",
|
|
||||||
'author': 'Akretion',
|
|
||||||
'website': 'http://www.akretion.com',
|
|
||||||
'depends': ['sale_margin_no_onchange', 'bi_sale_company_currency'],
|
|
||||||
'data': [],
|
|
||||||
'installable': False,
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
from . import sale_report
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
##############################################################################
|
|
||||||
#
|
|
||||||
# Sale Margin Report module for Odoo
|
|
||||||
# Copyright (C) 2016 Akretion (http://www.akretion.com/)
|
|
||||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as
|
|
||||||
# published by the Free Software Foundation, either version 3 of the
|
|
||||||
# License, or (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
##############################################################################
|
|
||||||
|
|
||||||
from openerp import models, fields
|
|
||||||
import openerp.addons.decimal_precision as dp
|
|
||||||
|
|
||||||
|
|
||||||
class SaleReportBi(models.Model):
|
|
||||||
_inherit = "sale.report.bi"
|
|
||||||
|
|
||||||
margin_company_currency = fields.Float(
|
|
||||||
string='Margin', readonly=True,
|
|
||||||
digits=dp.get_precision('Account'))
|
|
||||||
|
|
||||||
def _select(self):
|
|
||||||
select = super(SaleReportBi, self)._select()
|
|
||||||
select += """
|
|
||||||
, sum(sol.margin_company_currency) AS margin_company_currency
|
|
||||||
"""
|
|
||||||
return select
|
|
||||||
Reference in New Issue
Block a user