From 5cf3cb1e11c94d3e961b38e9704dacd4cd008113 Mon Sep 17 00:00:00 2001 From: imacat Date: Tue, 7 Feb 2023 11:14:15 +0800 Subject: [PATCH] Added the "is_modified" pseudo property to the Account data model, and applied it to the update_account view, to count the localized titles for modification. --- src/accounting/account/views.py | 2 +- src/accounting/models.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/accounting/account/views.py b/src/accounting/account/views.py index 90a0132..d284264 100644 --- a/src/accounting/account/views.py +++ b/src/accounting/account/views.py @@ -139,7 +139,7 @@ def update_account(account: Account) -> redirect: account=account))) with db.session.no_autoflush: form.populate_obj(account) - if not db.session.is_modified(account): + if not account.is_modified: flash(lazy_gettext("The account was not modified."), "success") return redirect(inherit_next(url_for("accounting.account.detail", account=account))) diff --git a/src/accounting/models.py b/src/accounting/models.py index d6e278b..f32d0f1 100644 --- a/src/accounting/models.py +++ b/src/accounting/models.py @@ -292,6 +292,19 @@ class Account(db.Model): """ return cls.find_by_code(cls.__NET_CHANGE) + @property + def is_modified(self) -> bool: + """Returns whether a product account was modified. + + :return: True if modified, or False otherwise. + """ + if db.session.is_modified(self): + return True + for l10n in self.l10n: + if db.session.is_modified(l10n): + return True + return False + def delete(self) -> None: """Deletes this accounting account.