Skip to content

Commit 397f39e

Browse files
diptanilsahamergify[bot]
authored andcommitted
fix(fiscal_year): Fiscal Year auto-generation and notification
(cherry picked from commit 4c76786) # Conflicts: # erpnext/accounts/doctype/fiscal_year/fiscal_year.py # erpnext/accounts/notification/notification_for_new_fiscal_year/notification_for_new_fiscal_year.html # erpnext/accounts/notification/notification_for_new_fiscal_year/notification_for_new_fiscal_year.json
1 parent 2fffc94 commit 397f39e

3 files changed

Lines changed: 83 additions & 7 deletions

File tree

erpnext/accounts/doctype/fiscal_year/fiscal_year.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import frappe
66
from dateutil.relativedelta import relativedelta
7-
from frappe import _
7+
from frappe import _, cint
88
from frappe.model.document import Document
99
from frappe.utils import add_days, add_years, cstr, getdate
1010

@@ -89,6 +89,7 @@ def validate_overlap(self):
8989
)
9090

9191

92+
<<<<<<< HEAD
9293
@frappe.whitelist()
9394
<<<<<<< HEAD
9495
def check_duplicate_fiscal_year(doc):
@@ -110,21 +111,38 @@ def check_duplicate_fiscal_year(doc):
110111
@frappe.whitelist()
111112
=======
112113
>>>>>>> 74ac28fc70 (refactor: `Fiscal Year` DocType cleanup)
114+
=======
115+
>>>>>>> 4c76786ce4 (fix(`fiscal_year`): `Fiscal Year` auto-generation and notification)
113116
def auto_create_fiscal_year():
114-
for d in frappe.db.sql(
115-
"""select name from `tabFiscal Year` where year_end_date = date_add(current_date, interval 3 day)"""
116-
):
117+
fy = frappe.qb.DocType("Fiscal Year")
118+
119+
# Skipped auto-creating Short Year, as it has very rare use case.
120+
# Reference: https://www.irs.gov/businesses/small-businesses-self-employed/tax-years (US)
121+
follow_up_date = add_days(getdate(), days=3)
122+
fiscal_year = (
123+
frappe.qb.from_(fy)
124+
.select(fy.name)
125+
.where((fy.year_end_date == follow_up_date) & (fy.is_short_year == 0))
126+
.run()
127+
)
128+
129+
for d in fiscal_year:
117130
try:
118131
current_fy = frappe.get_doc("Fiscal Year", d[0])
119132

120-
new_fy = frappe.copy_doc(current_fy, ignore_no_copy=False)
133+
new_fy = frappe.new_doc("Fiscal Year")
134+
new_fy.disabled = cint(current_fy.disabled)
121135

122136
new_fy.year_start_date = add_days(current_fy.year_end_date, 1)
123137
new_fy.year_end_date = add_years(current_fy.year_end_date, 1)
124138

125139
start_year = cstr(new_fy.year_start_date.year)
126140
end_year = cstr(new_fy.year_end_date.year)
127141
new_fy.year = start_year if start_year == end_year else (start_year + "-" + end_year)
142+
143+
for row in current_fy.companies:
144+
new_fy.append("companies", {"company": row.company})
145+
128146
new_fy.auto_created = 1
129147

130148
new_fy.insert(ignore_permissions=True)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<h4>{{ _("New Fiscal Year - {0}").format(doc.name) }}</h4>
2+
3+
<p>{{ _("A new fiscal year has been automatically created.") }}</p>
4+
5+
<p>{{ _("Fiscal Year Details") }}</p>
6+
7+
<table style="margin-bottom: 1rem; width: 70%">
8+
<tr>
9+
<td style="font-weight:bold; width: 40%">{{ _("Year Name") }}</td>
10+
<td>{{ doc.name }}</td>
11+
</tr>
12+
<tr>
13+
<td style="font-weight:bold; width: 40%">{{ _("Start Date") }}</td>
14+
<td>{{ frappe.format_value(doc.year_start_date) }}</td>
15+
</tr>
16+
<tr>
17+
<td style="font-weight:bold; width: 40%">{{ _("End Date") }}</td>
18+
<td>{{ frappe.format_value(doc.year_end_date) }}</td>
19+
</tr>
20+
{% if doc.companies|length > 0 %}
21+
<tr>
22+
<td style="vertical-align: top; font-weight: bold; width: 40%" rowspan="{{ doc.companies|length }}">
23+
{% if doc.companies|length < 2 %}
24+
{{ _("Company") }}
25+
{% else %}
26+
{{ _("Companies") }}
27+
{% endif %}
28+
</td>
29+
<td>{{ doc.companies[0].company }}</td>
30+
</tr>
31+
{% for idx in range(1, doc.companies|length) %}
32+
<tr>
33+
<td>{{ doc.companies[idx].company }}</td>
34+
</tr>
35+
{% endfor %}
36+
{% endif %}
37+
</table>
38+
39+
{% if doc.disabled %}
40+
<p>{{ _("The fiscal year has been automatically created in a Disabled state to maintain consistency with the previous fiscal year's status.") }}</p>
41+
{% endif %}
42+
43+
<p>{{ _("Please review the {0} configuration and complete any required financial setup activities.").format(frappe.utils.get_link_to_form("Fiscal Year", doc.name, frappe.bold("Fiscal Year"))) }}</p>

erpnext/accounts/notification/notification_for_new_fiscal_year/notification_for_new_fiscal_year.json

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"attach_print": 0,
33
"channel": "Email",
4-
"condition": "doc.auto_created",
4+
"condition": "doc.auto_created == 1",
5+
"condition_type": "Python",
56
"creation": "2018-04-25 14:19:05.440361",
67
"days_in_advance": 0,
78
"docstatus": 0,
@@ -11,8 +12,15 @@
1112
"event": "New",
1213
"idx": 0,
1314
"is_standard": 1,
15+
<<<<<<< HEAD
1416
"message": "<h3>{{_(\"Fiscal Year\")}}</h3>\n\n<p>{{ _(\"New fiscal year created :- \") }} {{ doc.name }}</p>",
1517
"modified": "2018-04-25 14:30:38.588534",
18+
=======
19+
"message": "<h4>{{ _(\"New Fiscal Year - {0}\").format(doc.name) }}</h4>\n\n<p>{{ _(\"A new fiscal year has been automatically created.\") }}</p>\n\n<p>{{ _(\"Fiscal Year Details\") }}</p>\n\n<table style=\"margin-bottom: 1rem; width: 70%\">\n <tr>\n <td style=\"font-weight:bold; width: 40%\">{{ _(\"Year Name\") }}</td>\n <td>{{ doc.name }}</td>\n </tr>\n <tr>\n <td style=\"font-weight:bold; width: 40%\">{{ _(\"Start Date\") }}</td>\n <td>{{ frappe.format_value(doc.year_start_date) }}</td>\n </tr>\n <tr>\n <td style=\"font-weight:bold; width: 40%\">{{ _(\"End Date\") }}</td>\n <td>{{ frappe.format_value(doc.year_end_date) }}</td>\n </tr>\n {% if doc.companies|length > 0 %}\n <tr>\n <td style=\"vertical-align: top; font-weight: bold; width: 40%\" rowspan=\"{{ doc.companies|length }}\">\n {% if doc.companies|length < 2 %}\n {{ _(\"Company\") }}\n {% else %}\n {{ _(\"Companies\") }}\n {% endif %}\n </td>\n <td>{{ doc.companies[0].company }}</td>\n </tr>\n {% for idx in range(1, doc.companies|length) %}\n <tr>\n <td>{{ doc.companies[idx].company }}</td>\n </tr>\n {% endfor %}\n {% endif %}\n</table>\n\n{% if doc.disabled %}\n<p>{{ _(\"The fiscal year has been automatically created in a Disabled state to maintain consistency with the previous fiscal year's status.\") }}</p>\n{% endif %}\n\n<p>{{ _(\"Please review the {0} configuration and complete any required financial setup activities.\").format(frappe.utils.get_link_to_form(\"Fiscal Year\", doc.name, frappe.bold(\"Fiscal Year\"))) }}</p>",
20+
"message_type": "HTML",
21+
"minutes_offset": 0,
22+
"modified": "2026-02-21 12:14:54.736795",
23+
>>>>>>> 4c76786ce4 (fix(`fiscal_year`): `Fiscal Year` auto-generation and notification)
1624
"modified_by": "Administrator",
1725
"module": "Accounts",
1826
"name": "Notification for new fiscal year",
@@ -25,5 +33,12 @@
2533
"email_by_role": "Accounts Manager"
2634
}
2735
],
36+
<<<<<<< HEAD
2837
"subject": "Notification for new fiscal year {{ doc.name }}"
29-
}
38+
}
39+
=======
40+
"send_system_notification": 0,
41+
"send_to_all_assignees": 0,
42+
"subject": "{{ _(\"New Fiscal Year {0} - Review Required\").format(doc.name) }}"
43+
}
44+
>>>>>>> 4c76786ce4 (fix(`fiscal_year`): `Fiscal Year` auto-generation and notification)

0 commit comments

Comments
 (0)