[FIX] exp_budget_check: call super in create payments

This commit is contained in:
Abdurrahman Saber 2025-10-20 13:46:48 +03:00
parent bf44dc543c
commit e8c6c19cb3
1 changed files with 11 additions and 38 deletions

View File

@ -31,53 +31,26 @@ class AccountPayment(models.Model):
class AccountPaymentRegister(models.TransientModel):
_inherit = 'account.payment.register'
def _post_payments(self, to_process, edit_mode=False):
modified_to_process = [item for item in to_process if item['create_vals']['payment_type'] != 'outbound']
return super()._post_payments(modified_to_process, edit_mode=edit_mode)
def _reconcile_payments(self, to_process, edit_mode=False):
modified_to_process = [item for item in to_process if item['create_vals']['payment_type'] != 'outbound']
return super()._reconcile_payments(modified_to_process, edit_mode=edit_mode)
def _create_payments(self):
self.ensure_one()
active_ids = self.env.context.get('active_ids')
if active_ids:
# invoice_payment = self.env['account.payment'].search(
# [('invoice_rec_id', '=', active_id),
# ('state', '=', 'draft')])
invoice_payment = self.env['account.payment'].search([('state', '=', 'draft')]).filtered(
lambda r: set(active_ids) & set(r.invoice_rec_ids.ids))
if invoice_payment:
raise UserError(
_('You can not create payment for this invoice because there is a draft payment for it'))
batches = self._get_batches()
edit_mode = self.can_edit_wizard and (len(batches[0]['lines']) == 1 or self.group_payment)
to_process = []
if edit_mode:
payment_vals = self._create_payment_vals_from_wizard()
to_process.append({
'create_vals': payment_vals,
'to_reconcile': batches[0]['lines'],
'batch': batches[0],
})
else:
# Don't group payments: Create one batch per move.
if not self.group_payment:
new_batches = []
for batch_result in batches:
for line in batch_result['lines']:
new_batches.append({
**batch_result,
'lines': line,
})
batches = new_batches
for batch_result in batches:
to_process.append({
'create_vals': self._create_payment_vals_from_batch(batch_result),
'to_reconcile': batch_result['lines'],
'batch': batch_result,
})
payments = self._init_payments(to_process, edit_mode=edit_mode)
process_final = [item for item in to_process if item['create_vals']['payment_type'] != 'outbound']
self._post_payments(process_final, edit_mode=edit_mode)
self._reconcile_payments(process_final, edit_mode=edit_mode)
payments = super()._create_payments()
for payment in payments:
if payment.payment_type == 'outbound':
payment.invoice_rec_ids = [(4, active_id) for active_id in active_ids]