Odooのメソッドを変更する必要があります。問題は、メソッドを含むクラスが通常どおりに宣言されていない(Odoo APIを使用していない)ため_inherit
、OdooAPIのパラメーターをエミュレートする方法がわからないことです。
これは、メソッドを含むクラスです(モジュールはaccount_financial_report_webkit
、OCAからのものです)。
...
from openerp.addons.account.report.common_report_header \
import common_report_header
class CommonReportHeaderWebkit(common_report_header):
...
そして、私が変更したいメソッドはこれです(CommonReportHeaderWebkit
クラス内にあります):
def is_initial_balance_enabled(self, main_filter):
if main_filter not in ('filter_no', 'filter_year', 'filter_period'):
return False
return True
それを上書きするために、カスタムモジュールでモンキーパッチを適用しました。
from openerp.addons.account_financial_report_webkit.report.common_reports \
import CommonReportHeaderWebkit
def is_initial_balance_enabled(self, main_filter):
if main_filter not in ('filter_no', 'filter_date', 'filter_period'):
return False
return True
CommonReportHeaderWebkit.is_initial_balance_enabled = is_initial_balance_enabled
これは正常に機能していますが、問題はこの方法でsuper
メソッド全体を上書きしていることです。他のメソッドでも同じことを行う必要があり、コード全体を上書きできないため、を使用したいと思います。
誰かがこれを正しい方法で行う方法を知っていますか?
私はPythonの専門家ではありませんが、私が知っていることから、メソッドをオブジェクトとして使用できるので、これでうまくいくと思います。
from openerp.addons.account_financial_report_webkit.report.common_reports \
import CommonReportHeaderWebkit
# first keep reference to the original method before you lose it.
_super_is_initial_balance_enabled = CommonReportHeaderWebkit.is_initial_balance_enabled
def is_initial_balance_enabled(self, main_filter):
# execute it like super
return _super_is_initial_balance_enabled(self, main_filter)
CommonReportHeaderWebkit.is_initial_balance_enabled = is_initial_balance_enabled
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加