refactor: remove diagnostic monkey-patch and tighten MRO base class identification for hr_expense overrides
This commit is contained in:
parent
4778cd3841
commit
ba8a9a4928
21
__init__.py
21
__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
|
||||
@ -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
|
||||
|
||||
@ -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):
|
||||
|
||||
@ -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):
|
||||
"""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user