diff --git a/account_accountant_ux/models/__init__.py b/account_accountant_ux/models/__init__.py index c17867bb..f31e95ab 100644 --- a/account_accountant_ux/models/__init__.py +++ b/account_accountant_ux/models/__init__.py @@ -8,3 +8,4 @@ from . import account_move_line from . import account_move from . import account_journal_dashboard +from . import account_payment diff --git a/account_accountant_ux/models/account_payment.py b/account_accountant_ux/models/account_payment.py new file mode 100644 index 00000000..d52f42b6 --- /dev/null +++ b/account_accountant_ux/models/account_payment.py @@ -0,0 +1,14 @@ +from odoo import models, api +from odoo.exceptions import ValidationError + +class AccountPayment(models.Model): + _inherit = 'account.payment' + + @api.constrains('payment_method_line_id') + def _check_payment_method_line_id(self): + ''' Ensure the 'payment_method_line_id' field is not null. + Can't be done using the regular 'required=True' because the field is a computed editable stored one. + ''' + for pay in self: + if not pay.payment_method_line_id: + raise ValidationError(_("Please define a payment method line on your payment."))