auto validate when creating payments from batch payments

This commit is contained in:
admin.suherdy 2025-11-19 10:52:41 +07:00
parent 261821dd80
commit 26524fbab9
8 changed files with 11 additions and 0 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,7 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import logging
from odoo import models, fields, api, _ from odoo import models, fields, api, _
from odoo.exceptions import ValidationError from odoo.exceptions import ValidationError
_logger = logging.getLogger(__name__)
class AccountBatchPayment(models.Model): class AccountBatchPayment(models.Model):
_inherit = "account.batch.payment" _inherit = "account.batch.payment"
@ -94,6 +97,14 @@ class AccountBatchPayment(models.Model):
self.write({ self.write({
'payment_ids': [(4, payment_id) for payment_id in payment_ids] 'payment_ids': [(4, payment_id) for payment_id in payment_ids]
}) })
# Automatically validate the batch payment after generating payments
if self.state == 'draft':
try:
self.validate_batch()
except Exception as e:
# If validation fails, log the error but don't prevent payment creation
_logger.warning(f"Failed to automatically validate batch payment {self.id}: {str(e)}")
class AccountBatchPaymentLine(models.Model): class AccountBatchPaymentLine(models.Model):