Skip to content

Commit 5cf82f5

Browse files
committed
[FIX] account_currency_report_ux: approach of using monkey_patches
1 parent 0e6335c commit 5cf82f5

File tree

5 files changed

+27
-7
lines changed

5 files changed

+27
-7
lines changed
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
22
# Part of Odoo. See LICENSE file for full copyright and licensing details.
33

4-
from . import report
4+
from . import hooks
5+
from . import monkey_patches

account_currency_reports_ux/__manifest__.py

+2
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,6 @@
4040
'installable': True,
4141
'auto_install': False,
4242
'application': False,
43+
'post_load': 'monkey_patches',
44+
'uninstall_hook': 'uninstall_hook'
4345
}

account_currency_reports_ux/hooks.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
##############################################################################
2+
# For copyright and license notices, see __manifest__.py file in module root
3+
# directory
4+
##############################################################################
5+
from odoo.addons.account.report.account_invoice_report import AccountInvoiceReport
6+
7+
def _revert_method(cls, name):
8+
""" Revert the original method called ``name`` in the given class.
9+
See :meth:`~._patch_method`.
10+
"""
11+
method = getattr(cls, name)
12+
setattr(cls, name, method.origin)
13+
14+
15+
def uninstall_hook(cr, registry):
16+
_revert_method(AccountInvoiceReport, '_select')
17+
_revert_method(AccountInvoiceReport, '_from')

account_currency_reports_ux/report/account_invoice_report.py account_currency_reports_ux/monkey_patches.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from odoo import models, api
2+
from odoo.addons.account.report.account_invoice_report import AccountInvoiceReport
23

3-
class AccountInvoiceReport(models.Model):
4-
_inherit = "account.invoice.report"
4+
def monkey_patches():
55

6+
# monkey patch
67
@api.model
78
def _select(self):
89
return '''
@@ -84,3 +85,6 @@ def _from(self):
8485
(currency_table.date_end IS NULL OR currency_table.date_end > COALESCE(line.date, NOW())))
8586
LEFT JOIN res_company rc on rc.id=line.company_id
8687
'''
88+
89+
AccountInvoiceReport._select = _select
90+
AccountInvoiceReport._from = _from

account_currency_reports_ux/report/__init__.py

-4
This file was deleted.

0 commit comments

Comments
 (0)