Add margin in invoice report
Consequence: no more need for module account_invoice_margin_report
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from . import account_invoice
|
from . import account_invoice
|
||||||
|
from . import account_invoice_report
|
||||||
|
|||||||
62
account_invoice_margin/account_invoice_report.py
Normal file
62
account_invoice_margin/account_invoice_report.py
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
# -*- 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 models, fields, api
|
||||||
|
|
||||||
|
|
||||||
|
class AccountInvoiceReport(models.Model):
|
||||||
|
_inherit = 'account.invoice.report'
|
||||||
|
|
||||||
|
margin = fields.Float(string='Margin', readonly=True)
|
||||||
|
# why digits=0 ??? Why is it like that in the native "account" module
|
||||||
|
user_currency_margin = fields.Float(
|
||||||
|
string="Margin", compute='_compute_user_currency_margin', digits=0)
|
||||||
|
|
||||||
|
_depends = {
|
||||||
|
'account.invoice': [
|
||||||
|
'account_id', 'amount_total_company_signed',
|
||||||
|
'commercial_partner_id', 'company_id',
|
||||||
|
'currency_id', 'date_due', 'date_invoice', 'fiscal_position_id',
|
||||||
|
'journal_id', 'partner_bank_id', 'partner_id', 'payment_term_id',
|
||||||
|
'residual', 'state', 'type', 'user_id',
|
||||||
|
],
|
||||||
|
'account.invoice.line': [
|
||||||
|
'account_id', 'invoice_id', 'price_subtotal', 'product_id',
|
||||||
|
'quantity', 'uom_id', 'account_analytic_id',
|
||||||
|
'margin_company_currency',
|
||||||
|
],
|
||||||
|
'product.product': ['product_tmpl_id'],
|
||||||
|
'product.template': ['categ_id'],
|
||||||
|
'product.uom': ['category_id', 'factor', 'name', 'uom_type'],
|
||||||
|
'res.currency.rate': ['currency_id', 'name'],
|
||||||
|
'res.partner': ['country_id'],
|
||||||
|
}
|
||||||
|
|
||||||
|
@api.depends('currency_id', 'date', 'margin')
|
||||||
|
def _compute_user_currency_margin(self):
|
||||||
|
context = dict(self._context or {})
|
||||||
|
user_currency_id = self.env.user.company_id.currency_id
|
||||||
|
currency_rate_id = self.env['res.currency.rate'].search([
|
||||||
|
('rate', '=', 1),
|
||||||
|
'|',
|
||||||
|
('company_id', '=', self.env.user.company_id.id),
|
||||||
|
('company_id', '=', False)], limit=1)
|
||||||
|
base_currency_id = currency_rate_id.currency_id
|
||||||
|
ctx = context.copy()
|
||||||
|
for record in self:
|
||||||
|
ctx['date'] = record.date
|
||||||
|
record.user_currency_margin = base_currency_id.with_context(
|
||||||
|
ctx).compute(record.margin, user_currency_id)
|
||||||
|
|
||||||
|
# TODO check for refunds
|
||||||
|
def _sub_select(self):
|
||||||
|
select_str = super(AccountInvoiceReport, self)._sub_select()
|
||||||
|
select_str += ", SUM(ail.margin_company_currency) AS margin"
|
||||||
|
return select_str
|
||||||
|
|
||||||
|
def _select(self):
|
||||||
|
select_str = super(AccountInvoiceReport, self)._select()
|
||||||
|
select_str += ", sub.margin AS margin"
|
||||||
|
return select_str
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
from . import report
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
##############################################################################
|
|
||||||
#
|
|
||||||
# Account Invoice Margin Report module for Odoo
|
|
||||||
# Copyright (C) 2015 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': 'Account Invoice Margin Report',
|
|
||||||
'version': '0.1',
|
|
||||||
'category': 'Accounting & Finance',
|
|
||||||
'license': 'AGPL-3',
|
|
||||||
'summary': 'Add margin measure in Invoices Analysis',
|
|
||||||
'description': """
|
|
||||||
This module adds the measure *Margin* in the Invoices Analysis pivot table. It is in a separate module because it depends on the module *bi_invoice_company_currency* (in which I re-wrote the Invoice 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': ['account_invoice_margin', 'bi_invoice_company_currency'],
|
|
||||||
'data': [],
|
|
||||||
'installable': False,
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
from . import invoice_report
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
##############################################################################
|
|
||||||
#
|
|
||||||
# Account Invoice Margin Report module for Odoo
|
|
||||||
# Copyright (C) 2015 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 AccountInvoiceReportBi(models.Model):
|
|
||||||
_inherit = "account.invoice.report.bi"
|
|
||||||
|
|
||||||
margin_company_currency = fields.Float(
|
|
||||||
string='Margin', readonly=True,
|
|
||||||
digits=dp.get_precision('Account'))
|
|
||||||
|
|
||||||
def _select(self):
|
|
||||||
select = super(AccountInvoiceReportBi, self)._select()
|
|
||||||
select += """
|
|
||||||
, sum(ail.margin_company_currency) AS margin_company_currency
|
|
||||||
"""
|
|
||||||
return select
|
|
||||||
Reference in New Issue
Block a user