1414)
1515from erpnext .accounts .report .trial_balance .trial_balance import (
1616 accumulate_values_into_parents ,
17+ calculate_total_row ,
1718 calculate_values ,
1819 get_opening_balances ,
1920 hide_group_accounts ,
@@ -44,7 +45,6 @@ def execute(filters: dict | None = None):
4445
4546def validate_filters (filters ):
4647 validate_companies (filters )
47- filters .show_net_values = True
4848 tb_validate_filters (filters )
4949
5050
@@ -99,16 +99,20 @@ def get_data(filters) -> list[list]:
9999 tb_data = get_company_wise_tb_data (company_filter , reporting_currency , ignore_reporting_currency )
100100 consolidate_trial_balance_data (data , tb_data )
101101
102- for d in data :
103- prepare_opening_closing (d )
104-
105- total_row = calculate_total_row (data , reporting_currency )
106-
107- data .extend ([{}, total_row ])
102+ if filters .get ("show_net_values" ):
103+ prepare_opening_closing_for_ctb (data )
108104
109105 if not filters .get ("show_group_accounts" ):
110106 data = hide_group_accounts (data )
111107
108+ total_row = calculate_total_row (
109+ data , reporting_currency , show_group_accounts = filters .get ("show_group_accounts" )
110+ )
111+
112+ calculate_foreign_currency_translation_reserve (total_row , data , filters = filters )
113+
114+ data .extend ([total_row ])
115+
112116 if filters .get ("presentation_currency" ):
113117 update_to_presentation_currency (
114118 data ,
@@ -207,10 +211,6 @@ def prepare_companywise_tb_data(accounts, filters, parent_children_map, reportin
207211 data = []
208212
209213 for d in accounts :
210- # Prepare opening closing for group account
211- if parent_children_map .get (d .account ) and filters .get ("show_net_values" ):
212- prepare_opening_closing (d )
213-
214214 has_value = False
215215 row = {
216216 "account" : d .name ,
@@ -242,35 +242,9 @@ def prepare_companywise_tb_data(accounts, filters, parent_children_map, reportin
242242 return data
243243
244244
245- def calculate_total_row (data , reporting_currency ):
246- total_row = {
247- "account" : "'" + _ ("Total" ) + "'" ,
248- "account_name" : "'" + _ ("Total" ) + "'" ,
249- "warn_if_negative" : True ,
250- "opening_debit" : 0.0 ,
251- "opening_credit" : 0.0 ,
252- "debit" : 0.0 ,
253- "credit" : 0.0 ,
254- "closing_debit" : 0.0 ,
255- "closing_credit" : 0.0 ,
256- "parent_account" : None ,
257- "indent" : 0 ,
258- "has_value" : True ,
259- "currency" : reporting_currency ,
260- }
261-
262- for d in data :
263- if not d .get ("parent_account" ):
264- for field in value_fields :
265- total_row [field ] += d [field ]
266-
267- if data :
268- calculate_foreign_currency_translation_reserve (total_row , data )
269-
270- return total_row
271-
272-
273- def calculate_foreign_currency_translation_reserve (total_row , data ):
245+ def calculate_foreign_currency_translation_reserve (total_row , data , filters ):
246+ if not data or not total_row :
247+ return
274248 opening_dr_cr_diff = total_row ["opening_debit" ] - total_row ["opening_credit" ]
275249 dr_cr_diff = total_row ["debit" ] - total_row ["credit" ]
276250
@@ -289,15 +263,16 @@ def calculate_foreign_currency_translation_reserve(total_row, data):
289263 "root_type" : data [idx ].get ("root_type" ),
290264 "account_type" : "Equity" ,
291265 "parent_account" : data [idx ].get ("account" ),
292- "indent" : data [idx ].get ("indent" ) + 1 ,
266+ "indent" : data [idx ].get ("indent" ) + 1 if filters . get ( "show_group_accounts" ) else 0 ,
293267 "has_value" : True ,
294268 "currency" : total_row .get ("currency" ),
295269 }
296270
297271 fctr_row ["closing_debit" ] = fctr_row ["opening_debit" ] + fctr_row ["debit" ]
298272 fctr_row ["closing_credit" ] = fctr_row ["opening_credit" ] + fctr_row ["credit" ]
299273
300- prepare_opening_closing (fctr_row )
274+ if filters .get ("show_net_values" ):
275+ prepare_opening_closing (fctr_row )
301276
302277 data .insert (idx + 1 , fctr_row )
303278
@@ -396,6 +371,11 @@ def update_to_presentation_currency(data, from_currency, to_currency, date, igno
396371 d .update (currency = to_currency )
397372
398373
374+ def prepare_opening_closing_for_ctb (data ):
375+ for d in data :
376+ prepare_opening_closing (d )
377+
378+
399379def get_columns ():
400380 return [
401381 {
0 commit comments