From ba8a9a4928381b69aec9690595bb2dd557a99920 Mon Sep 17 00:00:00 2001 From: Suherdy Yacob Date: Mon, 6 Apr 2026 14:23:44 +0700 Subject: [PATCH] refactor: remove diagnostic monkey-patch and tighten MRO base class identification for hr_expense overrides --- __init__.py | 23 +---------------------- models/account_move.py | 2 +- models/account_move_line.py | 2 +- models/account_payment.py | 3 +-- 4 files changed, 4 insertions(+), 26 deletions(-) diff --git a/__init__.py b/__init__.py index 72d24ea..9a7e03e 100644 --- a/__init__.py +++ b/__init__.py @@ -1,22 +1 @@ -import logging -import traceback -from odoo.exceptions import UserError - -_logger = logging.getLogger(__name__) - -# Diagnostic monkey-patch to find where the UserError is coming from -original_init = UserError.__init__ - -def diagnostic_init(self, *args, **kwargs): - message = args[0] if args else "" - if "linked to an expense report" in str(message): - with open("/tmp/odoo_lock_traceback.txt", "w") as f: - f.write("LOCKED ERROR CAUGHT!\n") - f.write(f"Message: {message}\n") - f.write("TRACEBACK:\n") - traceback.print_stack(file=f) - return original_init(self, *args, **kwargs) - -UserError.__init__ = diagnostic_init - -from . import models +from . import models \ No newline at end of file diff --git a/models/account_move.py b/models/account_move.py index 2e14c06..d10e78b 100644 --- a/models/account_move.py +++ b/models/account_move.py @@ -6,7 +6,7 @@ class AccountMove(models.Model): def _get_hr_expense_base_class(self): """ Returns the hr_expense class in the MRO to jump over it. """ mro = type(self).mro() - return next((c for c in mro if 'hr_expense' in c.__module__), None) + return next((c for c in mro if c.__module__ == 'odoo.addons.hr_expense.models.account_move'), None) def write(self, vals): # Surgical Jumper to bypass hr_expense's account.move lock diff --git a/models/account_move_line.py b/models/account_move_line.py index 5c0b4a7..9af8423 100644 --- a/models/account_move_line.py +++ b/models/account_move_line.py @@ -7,7 +7,7 @@ class AccountMoveLine(models.Model): def _get_hr_expense_base_class(self): """ Returns the hr_expense class in the MRO to jump over it. """ mro = type(self).mro() - return next((c for c in mro if 'hr_expense' in c.__module__), None) + return next((c for c in mro if c.__module__ == 'odoo.addons.hr_expense.models.account_move_line'), None) @api.model_create_multi def create(self, vals_list): diff --git a/models/account_payment.py b/models/account_payment.py index 40a0e77..1ce854a 100644 --- a/models/account_payment.py +++ b/models/account_payment.py @@ -12,8 +12,7 @@ class AccountPayment(models.Model): def _get_hr_expense_base_class(self): """ Returns the hr_expense class in the MRO to jump over it. """ mro = type(self).mro() - # The module for Odoo's hr_expense override is usually 'odoo.addons.hr_expense' - return next((c for c in mro if c.__module__.startswith('odoo.addons.hr_expense')), None) + return next((c for c in mro if c.__module__ == 'odoo.addons.hr_expense.models.account_payment'), None) def action_post(self): """