6
6
from frappe import _
7
7
from frappe .utils import (flt , getdate , get_first_day , get_last_day , date_diff ,
8
8
add_months , add_days , formatdate , cint )
9
+ from erpnext .accounts .utils import get_fiscal_year
9
10
10
- def get_period_list (from_fiscal_year , to_fiscal_year , periodicity , accumulated_values = False , company = None ):
11
+
12
+ def get_period_list (from_fiscal_year , to_fiscal_year , periodicity , accumulated_values = False ,
13
+ company = None , reset_period_on_fy_change = True ):
11
14
"""Get a list of dict {"from_date": from_date, "to_date": to_date, "key": key, "label": label}
12
15
Periodicity can be (Yearly, Quarterly, Monthly)"""
13
16
@@ -49,7 +52,8 @@ def get_period_list(from_fiscal_year, to_fiscal_year, periodicity, accumulated_v
49
52
# if a fiscal year ends before a 12 month period
50
53
period .to_date = year_end_date
51
54
52
- period .to_date_fiscal_year = get_date_fiscal_year (period .to_date , company )
55
+ period .to_date_fiscal_year = get_fiscal_year (period .to_date , company = company )[0 ]
56
+ period .from_date_fiscal_year_start_date = get_fiscal_year (period .from_date , company = company )[1 ]
53
57
54
58
period_list .append (period )
55
59
@@ -65,7 +69,10 @@ def get_period_list(from_fiscal_year, to_fiscal_year, periodicity, accumulated_v
65
69
if not accumulated_values :
66
70
label = get_label (periodicity , opts ["from_date" ], opts ["to_date" ])
67
71
else :
68
- label = get_label (periodicity , period_list [0 ]["from_date" ], opts ["to_date" ])
72
+ if reset_period_on_fy_change :
73
+ label = get_label (periodicity , opts .from_date_fiscal_year_start_date , opts ["to_date" ])
74
+ else :
75
+ label = get_label (periodicity , period_list [0 ].from_date , opts ["to_date" ])
69
76
70
77
opts .update ({
71
78
"key" : key .replace (" " , "_" ).replace ("-" , "_" ),
@@ -150,10 +157,6 @@ def calculate_values(accounts_by_name, gl_entries_by_account, period_list, accum
150
157
if entry .posting_date < period_list [0 ].year_start_date :
151
158
d ["opening_balance" ] = d .get ("opening_balance" , 0.0 ) + flt (entry .debit ) - flt (entry .credit )
152
159
153
- def get_date_fiscal_year (date , company ):
154
- from erpnext .accounts .utils import get_fiscal_year
155
- return get_fiscal_year (date , company = company )[0 ]
156
-
157
160
def accumulate_values_into_parents (accounts , accounts_by_name , period_list , accumulated_values ):
158
161
"""accumulate children's values in parent accounts"""
159
162
for d in reversed (accounts ):
0 commit comments