@@ -14,8 +14,8 @@ def execute(filters=None):
1414 if cint (frappe .db .get_single_value ('Accounts Settings' , 'use_custom_cash_flow' )):
1515 from erpnext .accounts .report .cash_flow .custom_cash_flow import execute as execute_custom
1616 return execute_custom (filters = filters )
17-
18- period_list = get_period_list (filters .from_fiscal_year , filters .to_fiscal_year ,
17+
18+ period_list = get_period_list (filters .from_fiscal_year , filters .to_fiscal_year ,
1919 filters .periodicity , filters .accumulated_values , filters .company )
2020
2121 cash_flow_accounts = get_cash_flow_accounts ()
@@ -25,45 +25,45 @@ def execute(filters=None):
2525 accumulated_values = filters .accumulated_values , ignore_closing_entries = True , ignore_accumulated_values_for_fy = True )
2626 expense = get_data (filters .company , "Expense" , "Debit" , period_list , filters = filters ,
2727 accumulated_values = filters .accumulated_values , ignore_closing_entries = True , ignore_accumulated_values_for_fy = True )
28-
28+
2929 net_profit_loss = get_net_profit_loss (income , expense , period_list , filters .company )
3030
3131 data = []
3232 company_currency = frappe .get_cached_value ('Company' , filters .company , "default_currency" )
33-
33+
3434 for cash_flow_account in cash_flow_accounts :
3535 section_data = []
3636 data .append ({
37- "account_name" : cash_flow_account ['section_header' ],
37+ "account_name" : cash_flow_account ['section_header' ],
3838 "parent_account" : None ,
39- "indent" : 0.0 ,
39+ "indent" : 0.0 ,
4040 "account" : cash_flow_account ['section_header' ]
4141 })
4242
4343 if len (data ) == 1 :
4444 # add first net income in operations section
4545 if net_profit_loss :
4646 net_profit_loss .update ({
47- "indent" : 1 ,
47+ "indent" : 1 ,
4848 "parent_account" : cash_flow_accounts [0 ]['section_header' ]
4949 })
5050 data .append (net_profit_loss )
5151 section_data .append (net_profit_loss )
5252
5353 for account in cash_flow_account ['account_types' ]:
54- account_data = get_account_type_based_data (filters .company ,
55- account ['account_type' ], period_list , filters .accumulated_values )
54+ account_data = get_account_type_based_data (filters .company ,
55+ account ['account_type' ], period_list , filters .accumulated_values , filters )
5656 account_data .update ({
5757 "account_name" : account ['label' ],
58- "account" : account ['label' ],
58+ "account" : account ['label' ],
5959 "indent" : 1 ,
6060 "parent_account" : cash_flow_account ['section_header' ],
6161 "currency" : company_currency
6262 })
6363 data .append (account_data )
6464 section_data .append (account_data )
6565
66- add_total_row_account (data , section_data , cash_flow_account ['section_footer' ],
66+ add_total_row_account (data , section_data , cash_flow_account ['section_footer' ],
6767 period_list , company_currency )
6868
6969 add_total_row_account (data , data , _ ("Net Change in Cash" ), period_list , company_currency )
@@ -105,13 +105,15 @@ def get_cash_flow_accounts():
105105 # combine all cash flow accounts for iteration
106106 return [operation_accounts , investing_accounts , financing_accounts ]
107107
108- def get_account_type_based_data (company , account_type , period_list , accumulated_values ):
108+ def get_account_type_based_data (company , account_type , period_list , accumulated_values , filters ):
109109 data = {}
110110 total = 0
111111 for period in period_list :
112112 start_date = get_start_date (period , accumulated_values , company )
113113
114- amount = get_account_type_based_gl_data (company , start_date , period ['to_date' ], account_type )
114+ amount = get_account_type_based_gl_data (company , start_date ,
115+ period ['to_date' ], account_type , filters )
116+
115117 if amount and account_type == "Depreciation" :
116118 amount *= - 1
117119
@@ -121,14 +123,24 @@ def get_account_type_based_data(company, account_type, period_list, accumulated_
121123 data ["total" ] = total
122124 return data
123125
124- def get_account_type_based_gl_data (company , start_date , end_date , account_type ):
126+ def get_account_type_based_gl_data (company , start_date , end_date , account_type , filters ):
127+ cond = ""
128+
129+ if filters .finance_book :
130+ cond = " and finance_book = '%s'" % (frappe .db .escape (filters .finance_book ))
131+ if filters .include_default_book_entries :
132+ company_fb = frappe .db .get_value ("Company" , company , 'default_finance_book' )
133+
134+ cond = """ and finance_book in ('%s', '%s')
135+ """ % (frappe .db .escape (filters .finance_book ), frappe .db .escape (company_fb ))
136+
125137 gl_sum = frappe .db .sql_list ("""
126138 select sum(credit) - sum(debit)
127139 from `tabGL Entry`
128140 where company=%s and posting_date >= %s and posting_date <= %s
129141 and voucher_type != 'Period Closing Voucher'
130- and account in ( SELECT name FROM tabAccount WHERE account_type = %s)
131- """ , (company , start_date , end_date , account_type ))
142+ and account in ( SELECT name FROM tabAccount WHERE account_type = %s) {cond}
143+ """ . format ( cond = cond ) , (company , start_date , end_date , account_type ))
132144
133145 return gl_sum [0 ] if gl_sum and gl_sum [0 ] else 0
134146
@@ -154,7 +166,7 @@ def add_total_row_account(out, data, label, period_list, currency, consolidated
154166 key = period if consolidated else period ['key' ]
155167 total_row .setdefault (key , 0.0 )
156168 total_row [key ] += row .get (key , 0.0 )
157-
169+
158170 total_row .setdefault ("total" , 0.0 )
159171 total_row ["total" ] += row ["total" ]
160172
0 commit comments