fix: fiscal year check on validation (backport #55930) (#55938)

fix: fiscal year check on validation (#55930)

(cherry picked from commit 380b005659)

# Conflicts:
#	erpnext/controllers/accounts_controller.py

Co-authored-by: Jatin3128 <140256508+Jatin3128@users.noreply.github.com>
This commit is contained in:
mergify[bot]
2026-06-16 05:23:51 +00:00
committed by GitHub
parent 200e1b6fe4
commit f3e23d4e6f

View File

@@ -51,12 +51,11 @@ from erpnext.accounts.utils import (
create_gain_loss_journal, create_gain_loss_journal,
get_account_currency, get_account_currency,
get_currency_precision, get_currency_precision,
get_fiscal_year,
get_fiscal_years, get_fiscal_years,
validate_fiscal_year, validate_fiscal_year,
) )
from erpnext.accounts.utils import ( from erpnext.accounts.utils import get_advance_payment_doctypes as _get_advance_payment_doctypes
get_advance_payment_doctypes as _get_advance_payment_doctypes,
)
from erpnext.buying.utils import update_last_purchase_rate from erpnext.buying.utils import update_last_purchase_rate
from erpnext.controllers.print_settings import ( from erpnext.controllers.print_settings import (
set_print_templates_for_item_table, set_print_templates_for_item_table,
@@ -749,21 +748,29 @@ class AccountsController(TransactionBase):
self.calculate_contribution() self.calculate_contribution()
def validate_date_with_fiscal_year(self): def validate_date_with_fiscal_year(self):
if self.meta.get_field("fiscal_year"): date_field = None
date_field = None if self.meta.get_field("posting_date"):
if self.meta.get_field("posting_date"): date_field = "posting_date"
date_field = "posting_date" elif self.meta.get_field("transaction_date"):
elif self.meta.get_field("transaction_date"): date_field = "transaction_date"
date_field = "transaction_date"
if date_field and self.get(date_field): if not date_field or not self.get(date_field):
validate_fiscal_year( return
self.get(date_field),
self.fiscal_year, if self.meta.get_field("fiscal_year"):
self.company, validate_fiscal_year(
self.meta.get_label(date_field), self.get(date_field),
self, 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): def validate_party_accounts(self):
if self.doctype not in ("Sales Invoice", "Purchase Invoice"): if self.doctype not in ("Sales Invoice", "Purchase Invoice"):