From ac2b70b66eb74cd4e3a6b4fd58aef060c0758a62 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Wed, 21 Nov 2018 16:44:05 +0100 Subject: [PATCH] Add margin in sale.report --- sale_margin_no_onchange/__init__.py | 1 + sale_margin_no_onchange/sale.py | 6 ++-- sale_margin_no_onchange/sale_report.py | 17 ++++++++++ sale_margin_report/__init__.py | 3 -- sale_margin_report/__manifest__.py | 41 ------------------------ sale_margin_report/report/__init__.py | 3 -- sale_margin_report/report/sale_report.py | 39 ---------------------- 7 files changed, 21 insertions(+), 89 deletions(-) create mode 100644 sale_margin_no_onchange/sale_report.py delete mode 100644 sale_margin_report/__init__.py delete mode 100644 sale_margin_report/__manifest__.py delete mode 100644 sale_margin_report/report/__init__.py delete mode 100644 sale_margin_report/report/sale_report.py diff --git a/sale_margin_no_onchange/__init__.py b/sale_margin_no_onchange/__init__.py index 1d47105..64f77eb 100644 --- a/sale_margin_no_onchange/__init__.py +++ b/sale_margin_no_onchange/__init__.py @@ -1,3 +1,4 @@ # -*- encoding: utf-8 -*- from . import sale +from . import sale_report diff --git a/sale_margin_no_onchange/sale.py b/sale_margin_no_onchange/sale.py index 4b5c06f..e182425 100644 --- a/sale_margin_no_onchange/sale.py +++ b/sale_margin_no_onchange/sale.py @@ -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', diff --git a/sale_margin_no_onchange/sale_report.py b/sale_margin_no_onchange/sale_report.py new file mode 100644 index 0000000..9308931 --- /dev/null +++ b/sale_margin_no_onchange/sale_report.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# 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 diff --git a/sale_margin_report/__init__.py b/sale_margin_report/__init__.py deleted file mode 100644 index 006edd3..0000000 --- a/sale_margin_report/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -# -*- coding: utf-8 -*- - -from . import report diff --git a/sale_margin_report/__manifest__.py b/sale_margin_report/__manifest__.py deleted file mode 100644 index f66d489..0000000 --- a/sale_margin_report/__manifest__.py +++ /dev/null @@ -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 -# -# 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 . -# -############################################################################## - - -{ - '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 -. - """, - 'author': 'Akretion', - 'website': 'http://www.akretion.com', - 'depends': ['sale_margin_no_onchange', 'bi_sale_company_currency'], - 'data': [], - 'installable': False, -} diff --git a/sale_margin_report/report/__init__.py b/sale_margin_report/report/__init__.py deleted file mode 100644 index f5028fb..0000000 --- a/sale_margin_report/report/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -# -*- coding: utf-8 -*- - -from . import sale_report diff --git a/sale_margin_report/report/sale_report.py b/sale_margin_report/report/sale_report.py deleted file mode 100644 index a6dcd51..0000000 --- a/sale_margin_report/report/sale_report.py +++ /dev/null @@ -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 -# -# 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 . -# -############################################################################## - -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