@@ -71,6 +71,9 @@ def _get_account_type_domain(self, grouped_by):
7171 ]
7272
7373 def _get_acc_prt_accounts_ids (self , company_id , grouped_by ):
74+ # In non-grouped mode, lines must stay at account level.
75+ if grouped_by == "none" :
76+ return []
7477 accounts_domain = [
7578 ("company_ids" , "in" , [company_id ]),
7679 ] + self ._get_account_type_domain (grouped_by )
@@ -91,7 +94,7 @@ def _get_initial_balances_bs_ml_domain(
9194 domain += [("date" , "<" , date_from )]
9295 accounts = self .env ["account.account" ].search (accounts_domain )
9396 domain += [("account_id" , "in" , accounts .ids )]
94- if acc_prt :
97+ if acc_prt and grouped_by != "none" :
9598 domain += self ._get_account_type_domain (grouped_by )
9699 return domain
97100
@@ -184,15 +187,35 @@ def _get_gl_initial_acc(
184187 initial_domain_pl = self ._get_initial_balances_pl_ml_domain (
185188 account_ids , company_id , date_from , fy_start_date , base_domain
186189 )
187- return self ._get_accounts_initial_balance (initial_domain_bs , initial_domain_pl )
190+ gl_initial_acc = self ._get_accounts_initial_balance (
191+ initial_domain_bs , initial_domain_pl
192+ )
193+ if grouped_by != "none" :
194+ return gl_initial_acc
195+ # If grouped_by none we add balance
196+ domain = list (base_domain ) + [("date" , "<" , date_from )]
197+ if account_ids :
198+ domain += [("account_id" , "in" , account_ids )]
199+ rows = self .env ["account.move.line" ].read_group (
200+ domain = domain ,
201+ fields = ["account_id" , "debit" , "credit" , "balance" , "amount_currency:sum" ],
202+ groupby = ["account_id" ],
203+ )
204+ covered_ids = {
205+ row ["account_id" ][0 ] for row in gl_initial_acc if row .get ("account_id" )
206+ }
207+ for row in rows :
208+ if row .get ("account_id" ) and row ["account_id" ][0 ] not in covered_ids :
209+ gl_initial_acc .append (row )
210+ return gl_initial_acc
188211
189212 def _prepare_gen_ld_data_item (self , gl ):
190213 res = {}
191214 for key_bal in ["init_bal" , "fin_bal" ]:
192215 res [key_bal ] = {}
193216 for key_field in ["credit" , "debit" , "balance" , "bal_curr" ]:
194217 field_name = key_field if key_field != "bal_curr" else "amount_currency"
195- res [key_bal ][key_field ] = gl [ field_name ]
218+ res [key_bal ][key_field ] = gl . get ( field_name , 0.0 )
196219 return res
197220
198221 def _prepare_gen_ld_data (self , gl_initial_acc , domain , grouped_by ):
0 commit comments