changeset 75ce0ead8565 in modules/analytic_account:default
details:
https://hg.tryton.org/modules/analytic_account?cmd=changeset&node=75ce0ead8565
description:
Add validate_fields to ModelStorage
issue11303
review386191002
diffstat:
account.py | 23 +++++++++++++----------
1 files changed, 13 insertions(+), 10 deletions(-)
diffs (35 lines):
diff -r 4b71c58e8d17 -r 75ce0ead8565 account.py
--- a/account.py Sun Apr 10 19:11:38 2022 +0200
+++ b/account.py Mon Apr 11 23:24:21 2022 +0200
@@ -120,18 +120,21 @@
return 'draft'
@classmethod
- def validate(cls, accounts):
- super(Account, cls).validate(accounts)
- for account in accounts:
- account.check_distribution()
+ def validate_fields(cls, accounts, field_names):
+ super().validate_fields(accounts, field_names)
+ cls.check_distribution(accounts, field_names)
- def check_distribution(self):
- if self.type != 'distribution':
+ @classmethod
+ def check_distribution(cls, accounts, field_names=None):
+ if field_names and not (field_names & {'distributions', 'type'}):
return
- if sum((d.ratio for d in self.distributions)) != 1:
- raise AccountValidationError(
- gettext('analytic_account.msg_invalid_distribution',
- account=self.rec_name))
+ for account in accounts:
+ if account.type != 'distribution':
+ return
+ if sum((d.ratio for d in account.distributions)) != 1:
+ raise AccountValidationError(
+ gettext('analytic_account.msg_invalid_distribution',
+ account=account.rec_name))
@fields.depends('company')
def on_change_with_currency(self, name=None):