diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index df827360e6e..e7a85dfde36 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -51,12 +51,11 @@ from erpnext.accounts.utils import ( create_gain_loss_journal, get_account_currency, get_currency_precision, + get_fiscal_year, get_fiscal_years, validate_fiscal_year, ) -from erpnext.accounts.utils import ( - get_advance_payment_doctypes as _get_advance_payment_doctypes, -) +from erpnext.accounts.utils import get_advance_payment_doctypes as _get_advance_payment_doctypes from erpnext.buying.utils import update_last_purchase_rate from erpnext.controllers.print_settings import ( set_print_templates_for_item_table, @@ -749,21 +748,29 @@ class AccountsController(TransactionBase): self.calculate_contribution() def validate_date_with_fiscal_year(self): - if self.meta.get_field("fiscal_year"): - date_field = None - if self.meta.get_field("posting_date"): - date_field = "posting_date" - elif self.meta.get_field("transaction_date"): - date_field = "transaction_date" + date_field = None + if self.meta.get_field("posting_date"): + date_field = "posting_date" + elif self.meta.get_field("transaction_date"): + date_field = "transaction_date" - if date_field and self.get(date_field): - validate_fiscal_year( - self.get(date_field), - self.fiscal_year, - self.company, - self.meta.get_label(date_field), - self, - ) + if not date_field or not self.get(date_field): + return + + if self.meta.get_field("fiscal_year"): + validate_fiscal_year( + self.get(date_field), + self.fiscal_year, + self.company, + self.meta.get_label(date_field), + self, + ) + else: + get_fiscal_year( + self.get(date_field), + company=self.company, + label=self.meta.get_label(date_field), + ) def validate_party_accounts(self): if self.doctype not in ("Sales Invoice", "Purchase Invoice"):