diff --git a/account_currency_reports_ux/__init__.py b/account_currency_reports_ux/__init__.py index abbf32ce..8a3896d1 100644 --- a/account_currency_reports_ux/__init__.py +++ b/account_currency_reports_ux/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from . import report +from .hooks import uninstall_hook +from .monkey_patches import * diff --git a/account_currency_reports_ux/__manifest__.py b/account_currency_reports_ux/__manifest__.py index 23fe6295..14d7b0f5 100644 --- a/account_currency_reports_ux/__manifest__.py +++ b/account_currency_reports_ux/__manifest__.py @@ -40,4 +40,6 @@ 'installable': True, 'auto_install': False, 'application': False, + 'post_load': 'monkey_patches', + 'uninstall_hook': 'uninstall_hook' } diff --git a/account_currency_reports_ux/hooks.py b/account_currency_reports_ux/hooks.py new file mode 100644 index 00000000..e72478f2 --- /dev/null +++ b/account_currency_reports_ux/hooks.py @@ -0,0 +1,17 @@ +############################################################################## +# For copyright and license notices, see __manifest__.py file in module root +# directory +############################################################################## +from odoo.addons.account.report.account_invoice_report import AccountInvoiceReport + +def _revert_method(cls, name): + """ Revert the original method called ``name`` in the given class. + See :meth:`~._patch_method`. + """ + method = getattr(cls, name) + setattr(cls, name, method.origin) + + +def uninstall_hook(cr, registry): + _revert_method(AccountInvoiceReport, '_select') + _revert_method(AccountInvoiceReport, '_from') diff --git a/account_currency_reports_ux/report/account_invoice_report.py b/account_currency_reports_ux/monkey_patches.py similarity index 85% rename from account_currency_reports_ux/report/account_invoice_report.py rename to account_currency_reports_ux/monkey_patches.py index 24d25659..36bd5aee 100644 --- a/account_currency_reports_ux/report/account_invoice_report.py +++ b/account_currency_reports_ux/monkey_patches.py @@ -1,10 +1,11 @@ -from odoo import models, api +from odoo import api +from odoo.addons.account.report.account_invoice_report import AccountInvoiceReport -class AccountInvoiceReport(models.Model): - _inherit = "account.invoice.report" +def monkey_patches(): + # monkey patch @api.model - def _select(self): + def _select_patch(self): return ''' WITH currency_rate AS MATERIALIZED ( SELECT @@ -66,7 +67,7 @@ def _select(self): ''' % self.env.company.id @api.model - def _from(self): + def _from_patch(self): return ''' FROM account_move_line line LEFT JOIN res_partner partner ON partner.id = line.partner_id @@ -78,9 +79,19 @@ def _from(self): INNER JOIN account_move move ON move.id = line.move_id LEFT JOIN res_partner commercial_partner ON commercial_partner.id = move.commercial_partner_id lEFT JOIN currency_rate currency_table on - (currency_table.company_id = line.company_id and - currency_table.currency_id = line.currency_id and + (currency_table.currency_id = line.currency_id and currency_table.date_start <= COALESCE(line.date, NOW()) and (currency_table.date_end IS NULL OR currency_table.date_end > COALESCE(line.date, NOW()))) - LEFT JOIN res_company rc on rc.id=line.company_id + LEFT JOIN res_company rc on rc.id=currency_table.company_id ''' + + def _patch_method(cls, name, method): + origin = getattr(cls, name) + method.origin = origin + # propagate decorators from origin to method, and apply api decorator + wrapped = api.propagate(origin, method) + wrapped.origin = origin + setattr(cls, name, wrapped) + + _patch_method(AccountInvoiceReport, '_select', _select_patch) + _patch_method(AccountInvoiceReport, '_from', _from_patch) diff --git a/account_currency_reports_ux/report/__init__.py b/account_currency_reports_ux/report/__init__.py deleted file mode 100644 index a04d063d..00000000 --- a/account_currency_reports_ux/report/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from . import account_invoice_report