Add validate_fields to ModelStorage

issue11303
review386191002
This commit is contained in:
Cédric Krier committed 2022-04-11 23:24:20 +02:00
1 parent 523011891b
commit 962580548e
1 file changed
+14 -11
+14 -11
View File
@@ -322,18 +322,21 @@ class Payment(StripeCustomerMethodMixin, CheckoutMixin, metaclass=PoolMeta):
]
@classmethod
def validate(cls, payments):
super(Payment, cls).validate(payments)
for payment in payments:
payment.check_stripe_journal()
def validate_fields(cls, payments, field_names):
super().validate_fields(payments, field_names)
cls.check_stripe_journal(payments, field_names)
def check_stripe_journal(self):
if (self.kind != 'receivable'
and self.journal.process_method == 'stripe'):
raise PaymentValidationError(
gettext('account_payment_stripe.msg_stripe_receivable',
journal=self.journal.rec_name,
payment=self.rec_name))
@classmethod
def check_stripe_journal(cls, payments, field_names=None):
if field_names and not (field_names & {'kind', 'journal'}):
return
for payment in payments:
if (payment.kind != 'receivable'
and payment.journal.process_method == 'stripe'):
raise PaymentValidationError(
gettext('account_payment_stripe.msg_stripe_receivable',
journal=payment.journal.rec_name,
payment=payment.rec_name))
@classmethod
def create(cls, vlist):