fix: force move synchronization in action_post and propagate skip_expense_lock in synchronization methods
This commit is contained in:
parent
98e06420bc
commit
14145e9fca
@ -11,9 +11,17 @@ class AccountPayment(models.Model):
|
|||||||
|
|
||||||
def action_post(self):
|
def action_post(self):
|
||||||
"""
|
"""
|
||||||
Confirmation bypass. Calls standard post with skip flag.
|
Confirmation bypass. Calls standard post with skip flag and FORCES a sync
|
||||||
|
to ensure deductions are applied to the Journal Entry.
|
||||||
"""
|
"""
|
||||||
# Propagate the flag to all internal calls
|
# 1. Force a synchronization of the moves right before posting.
|
||||||
|
# We pass 'amount' and 'deduction_line_ids' to trigger vendor_payment_diff_amount.
|
||||||
|
self_bypass = self.with_context(skip_expense_lock=True)
|
||||||
|
for payment in self_bypass:
|
||||||
|
if payment.state == 'draft':
|
||||||
|
payment._synchronize_to_moves({'amount', 'deduction_line_ids', 'amount_substract'})
|
||||||
|
|
||||||
|
# 2. Standard confirmation logic with bypass flag for internal writes
|
||||||
return super(AccountPayment, self.with_context(skip_expense_lock=True)).action_post()
|
return super(AccountPayment, self.with_context(skip_expense_lock=True)).action_post()
|
||||||
|
|
||||||
def _synchronize_to_moves(self, changed_fields):
|
def _synchronize_to_moves(self, changed_fields):
|
||||||
@ -25,15 +33,14 @@ class AccountPayment(models.Model):
|
|||||||
# SURGICAL JUMPER: If we have the bypass flag, we jump over the hr_expense method.
|
# SURGICAL JUMPER: If we have the bypass flag, we jump over the hr_expense method.
|
||||||
if self._context.get('skip_expense_lock'):
|
if self._context.get('skip_expense_lock'):
|
||||||
mro = type(self).mro()
|
mro = type(self).mro()
|
||||||
# Find the class that belongs to the hr_expense module
|
|
||||||
hr_expense_class = next((c for c in mro if c.__module__.startswith('odoo.addons.hr_expense')), None)
|
hr_expense_class = next((c for c in mro if c.__module__.startswith('odoo.addons.hr_expense')), None)
|
||||||
if hr_expense_class:
|
if hr_expense_class:
|
||||||
# Standard Python jumping syntax: calls the method of the parent of hr_expense_class
|
|
||||||
return super(hr_expense_class, self)._synchronize_to_moves(changed_fields)
|
return super(hr_expense_class, self)._synchronize_to_moves(changed_fields)
|
||||||
|
|
||||||
return super()._synchronize_to_moves(changed_fields)
|
return super()._synchronize_to_moves(changed_fields)
|
||||||
|
|
||||||
def _synchronize_from_moves(self, changed_fields):
|
def _synchronize_from_moves(self, changed_fields):
|
||||||
|
# Same jumper for synchronization back from moves
|
||||||
if self._context.get('skip_expense_lock'):
|
if self._context.get('skip_expense_lock'):
|
||||||
mro = type(self).mro()
|
mro = type(self).mro()
|
||||||
hr_expense_class = next((c for c in mro if c.__module__.startswith('odoo.addons.hr_expense')), None)
|
hr_expense_class = next((c for c in mro if c.__module__.startswith('odoo.addons.hr_expense')), None)
|
||||||
@ -43,7 +50,7 @@ class AccountPayment(models.Model):
|
|||||||
return super()._synchronize_from_moves(changed_fields)
|
return super()._synchronize_from_moves(changed_fields)
|
||||||
|
|
||||||
def write(self, vals):
|
def write(self, vals):
|
||||||
# Propagate bypass flag during writes to avoid checks on draft payments
|
# Propagate bypass flag during writes to avoid locked checks
|
||||||
if self.expense_sheet_id and self.state == 'draft':
|
if self.expense_sheet_id and self.state == 'draft':
|
||||||
return super(AccountPayment, self.with_context(skip_expense_lock=True)).write(vals)
|
return super(AccountPayment, self.with_context(skip_expense_lock=True)).write(vals)
|
||||||
return super().write(vals)
|
return super().write(vals)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user