Skip to content

Conversation

@mihir-kandoi
Copy link
Contributor

@mihir-kandoi mihir-kandoi commented Jan 1, 2026

This PR does two things:

  1. Introduces a new naming rule variable TFY (truncated fiscal year). This will enable users to use truncated fiscal year names (25-26 instead of the full 2025-2026).
  2. Document naming rule will now use the posting date of the document and not creation date

Limitations:
When the posting date/time is edited manually, the name will not update.

frappe/frappe#35586 has to be merged before this is merged

Note: This is a breaking change, merge carefully
no-docs

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 1, 2026

📝 Walkthrough

Walkthrough

Adds TFY support and truncation for fiscal-year naming: parse_naming_series_variable now recognizes "TFY" and calls get_fiscal_year(..., truncate=True). get_fiscal_year gains a truncate parameter and can return a truncated year tuple when requested (or False if not found). Imports determine_consecutive_week_number and now_datetime to enable resolution/formatting of date-based naming variables (YY, YYYY, MM, DD, JJJ). In hooks, naming_series_variables_list is introduced and naming_series_variables is built via a dict comprehension mapping each listed variable to erpnext.accounts.utils.parse_naming_series_variable.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title mentions using 'posting date' but the code changes primarily add TFY variable support and enhance naming series variable resolution; posting date usage is not evident in the provided code changes. Clarify whether the title should focus on the TFY variable feature or verify that posting date changes are implemented elsewhere in the PR.
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The description accurately reflects the changes including the new TFY variable and mentions posting date usage, aligning with the stated objectives.
✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
erpnext/hooks.py (1)

405-409: LGTM: Clean refactor of naming series variables.

The refactor from a hardcoded dictionary to a list combined with dict comprehension makes it easier to maintain and extend the supported naming series variables. All variables now consistently map to erpnext.accounts.utils.parse_naming_series_variable, which handles each variable type appropriately.

If you anticipate frequently adding new variables, consider adding a docstring or comment documenting what each variable represents:

# Variables for document naming series:
# FY: Full fiscal year (e.g., "2025-2026")
# TFY: Truncated fiscal year (e.g., "25-26")
# ABBR: Company abbreviation
# YY, YYYY, MM, DD, JJJ: Date format codes
# WW: Week number
naming_series_variables_list = ["FY", "TFY", "ABBR", "MM", "DD", "YY", "YYYY", "JJJ", "WW"]
📜 Review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f79e7dd and f272066.

📒 Files selected for processing (2)
  • erpnext/accounts/utils.py
  • erpnext/hooks.py
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-12-16T05:33:58.723Z
Learnt from: Abdeali099
Repo: frappe/erpnext PR: 51078
File: erpnext/accounts/doctype/financial_report_template/financial_report_engine.py:486-491
Timestamp: 2025-12-16T05:33:58.723Z
Learning: In ERPNext/Frappe codebase, query.run(as_dict=True) returns frappe._dict objects that support both dict-style access (obj["key"]) and attribute-style access (obj.key). Therefore, attribute access on query results is valid and will not raise AttributeError. When reviewing Python code, prefer attribute access (obj.key) for readability where the key is known to exist, but ensure existence checks or fallback handling if there is any doubt about missing keys.

Applied to files:

  • erpnext/accounts/utils.py
  • erpnext/hooks.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Python Unit Tests (4)
  • GitHub Check: Python Unit Tests (1)
  • GitHub Check: Python Unit Tests (2)
  • GitHub Check: Python Unit Tests (3)
  • GitHub Check: Patch Test
  • GitHub Check: Summary
🔇 Additional comments (2)
erpnext/accounts/utils.py (2)

1513-1520: LGTM: TFY variable support added correctly.

The function now handles both "FY" and "TFY" variables, passing the appropriate truncate parameter to get_fiscal_year. The truncation logic will format fiscal years like "2025-2026" as "25-26".


86-92: No changes needed. The function behavior is safe and maintains backward compatibility.

The return value of False on line 92 only occurs when raise_on_missing=False is explicitly passed. All three callers in the codebase that use this flag already have defensive checks (if not fiscal_year: or if fiscal_year and ...) that handle both empty lists and False identically. The default behavior (raise_on_missing=True) continues to raise FiscalYearError as before, so the 40+ callers using direct indexing are unaffected.

@mihir-kandoi mihir-kandoi changed the title feat: document naming rule will now use posting date of the document feat!: document naming rule will now use posting date of the document Jan 1, 2026
@mihir-kandoi mihir-kandoi added needs-tests This PR needs automated unit-tests. Breaking Changes and removed needs-tests This PR needs automated unit-tests. accounts labels Jan 1, 2026
@mihir-kandoi mihir-kandoi force-pushed the naming-rule-based-on-posting-date branch from f272066 to e9b6145 Compare January 1, 2026 10:02
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
erpnext/accounts/utils.py (1)

1530-1536: Address fallback behavior and variable naming issues (previously flagged).

This segment has multiple issues that were identified in a previous review:

  1. Line 1536: Falls back to determine_consecutive_week_number for ANY unknown variable, which masks errors for misspelled/unsupported variables.
  2. Lines 1532-1534: Inconsistent fallback - uses now_datetime() here but the FY/TFY branch uses getdate().
  3. Line 1534: Variable named date but assigned a datetime object, should be renamed to dt or datetime_obj.

The previous review suggested:

  • Use consistent fallback approach (prefer getdate())
  • Rename the variable for clarity
  • Raise an explicit error for unknown variables instead of silently calling determine_consecutive_week_number
  • Only call determine_consecutive_week_number for the "WW" variable explicitly
🧹 Nitpick comments (1)
erpnext/accounts/utils.py (1)

85-92: Add validation for fiscal year format when truncating.

The truncation logic assumes the fiscal year name follows a "YYYY-YYYY" format with a hyphen separator. If the format differs, the code could fail silently or produce incorrect results.

Consider adding validation:

🔎 Proposed validation
 	if fiscal_years:
 		fiscal_year = fiscal_years[0]
 		if truncate:
-			return ("-".join(y[-2:] for y in fiscal_year[0].split("-")), fiscal_year[1], fiscal_year[2])
+			year_parts = fiscal_year[0].split("-")
+			if len(year_parts) != 2:
+				frappe.throw(_("Fiscal year name must be in 'YYYY-YYYY' format for truncation"))
+			truncated_year = "-".join(part[-2:] for part in year_parts)
+			return (truncated_year, fiscal_year[1], fiscal_year[2])
 		return fiscal_year
 
 	return False
📜 Review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f272066 and e9b6145.

📒 Files selected for processing (2)
  • erpnext/accounts/utils.py
  • erpnext/hooks.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • erpnext/hooks.py
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-12-16T05:33:58.723Z
Learnt from: Abdeali099
Repo: frappe/erpnext PR: 51078
File: erpnext/accounts/doctype/financial_report_template/financial_report_engine.py:486-491
Timestamp: 2025-12-16T05:33:58.723Z
Learning: In ERPNext/Frappe codebase, query.run(as_dict=True) returns frappe._dict objects that support both dict-style access (obj["key"]) and attribute-style access (obj.key). Therefore, attribute access on query results is valid and will not raise AttributeError. When reviewing Python code, prefer attribute access (obj.key) for readability where the key is known to exist, but ensure existence checks or fallback handling if there is any doubt about missing keys.

Applied to files:

  • erpnext/accounts/utils.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Python Unit Tests (3)
  • GitHub Check: Patch Test
  • GitHub Check: Python Unit Tests (1)
  • GitHub Check: Python Unit Tests (2)
  • GitHub Check: Python Unit Tests (4)
  • GitHub Check: Summary
🔇 Additional comments (2)
erpnext/accounts/utils.py (2)

14-14: LGTM! Imports support new naming functionality.

The imports for determine_consecutive_week_number and now_datetime are necessary for the date-based naming series variables implementation.

Also applies to: 29-29


1512-1520: LGTM! TFY variable support is correctly implemented.

The logic properly handles both FY and TFY variables, using posting_date as the primary date source (aligning with PR objectives), and correctly passes the truncate parameter to get_fiscal_year.

@codecov
Copy link

codecov bot commented Jan 1, 2026

Codecov Report

❌ Patch coverage is 69.23077% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.04%. Comparing base (349db6c) to head (e9b6145).
⚠️ Report is 12 commits behind head on develop.

Files with missing lines Patch % Lines
erpnext/accounts/utils.py 66.66% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #51433      +/-   ##
===========================================
- Coverage    79.05%   79.04%   -0.01%     
===========================================
  Files         1179     1179              
  Lines       121306   121327      +21     
===========================================
+ Hits         95897    95908      +11     
- Misses       25409    25419      +10     
Files with missing lines Coverage Δ
erpnext/hooks.py 100.00% <100.00%> (ø)
erpnext/accounts/utils.py 75.46% <66.66%> (-0.17%) ⬇️

... and 15 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ankush
Copy link
Member

ankush commented Jan 1, 2026

This can be made non-breakinh easily by making it configurable.

@mihir-kandoi mihir-kandoi marked this pull request as draft January 2, 2026 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Breaking Changes needs-tests This PR needs automated unit-tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants