refactor: remove diagnostic monkey-patch and tighten MRO base class identification for hr_expense overrides

This commit is contained in:
Suherdy Yacob 2026-04-06 14:23:44 +07:00
parent 4778cd3841
commit ba8a9a4928
4 changed files with 4 additions and 26 deletions

View File

@ -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

View File

@ -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

View File

@ -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):

View File

@ -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):
"""