From 380b005659e92bfd2841c5674bea20d90ed5dd22 Mon Sep 17 00:00:00 2001 From: Jatin3128 <140256508+Jatin3128@users.noreply.github.com> Date: Mon, 15 Jun 2026 18:08:05 +0530 Subject: [PATCH] fix: fiscal year check on validation (#55930) --- erpnext/controllers/accounts_controller.py | 38 +++++++++++++--------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 4dcb6b00b49..ce7745f18f6 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -38,7 +38,7 @@ from erpnext.accounts.party import ( from erpnext.accounts.utils import ( get_advance_payment_doctypes as _get_advance_payment_doctypes, ) -from erpnext.accounts.utils import validate_fiscal_year +from erpnext.accounts.utils import get_fiscal_year, validate_fiscal_year from erpnext.controllers.print_settings import ( set_print_templates_for_item_table, set_print_templates_for_taxes, @@ -640,21 +640,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_due_date(self): if self.get("is_pos") or self.doctype not in ["Sales Invoice", "Purchase Invoice"]: