Skip to content

Commit

Permalink
[FIX] account_currency_report_ux: approach of using monkey_patches
Browse files Browse the repository at this point in the history
  • Loading branch information
rov-adhoc committed Dec 18, 2024
1 parent 0e6335c commit 5cf82f5
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
3 changes: 2 additions & 1 deletion account_currency_reports_ux/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from . import report
from . import hooks
from . import monkey_patches
2 changes: 2 additions & 0 deletions account_currency_reports_ux/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@
'installable': True,
'auto_install': False,
'application': False,
'post_load': 'monkey_patches',
'uninstall_hook': 'uninstall_hook'
}
17 changes: 17 additions & 0 deletions account_currency_reports_ux/hooks.py
Original file line number Diff line number Diff line change
@@ -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')
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from odoo import models, 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):
return '''
Expand Down Expand Up @@ -84,3 +85,6 @@ def _from(self):
(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
'''

AccountInvoiceReport._select = _select
AccountInvoiceReport._from = _from
4 changes: 0 additions & 4 deletions account_currency_reports_ux/report/__init__.py

This file was deleted.

0 comments on commit 5cf82f5

Please sign in to comment.