@@ -774,6 +774,7 @@ def _get_centralized_ml(self, account, date_to, grouped_by):
774
774
list_centralized_ml += list (centralized_ml [jnl_id ].values ())
775
775
return list_centralized_ml
776
776
777
+ # flake8: noqa: C901
777
778
def _get_report_values (self , docids , data ):
778
779
wizard_id = data ["wizard_id" ]
779
780
wizard = self .env ["general.ledger.report.wizard" ].browse (wizard_id )
@@ -852,6 +853,59 @@ def _get_report_values(self, docids, data):
852
853
account [grouped_by ] = False
853
854
del account ["list_grouped" ]
854
855
general_ledger = sorted (general_ledger , key = lambda k : k ["code" ])
856
+ # Set the bal_curr of the initial balance to 0 if it does not correspond
857
+ # (reducing the corresponding of the bal_curr of the initial balance).
858
+ for gl_item in general_ledger :
859
+ if (
860
+ not gl_item ["currency_id" ]
861
+ or gl_item ["currency_id" ] != company .currency_id
862
+ ):
863
+ gl_item ["fin_bal" ]["bal_curr" ] -= gl_item ["init_bal" ]["bal_curr" ]
864
+ gl_item ["init_bal" ]["bal_curr" ] = 0
865
+ if "list_grouped" in gl_item :
866
+ for lg_item in gl_item ["list_grouped" ]:
867
+ lg_item ["fin_bal" ]["bal_curr" ] -= lg_item ["init_bal" ][
868
+ "bal_curr"
869
+ ]
870
+ lg_item ["init_bal" ]["bal_curr" ] = 0
871
+ # Set the fin_bal_currency_id value if the account does not have it set
872
+ # and there are move lines in a currency different from that of
873
+ # the company (USD for example).
874
+ for gl_item in general_ledger :
875
+ fin_bal_currency_ids = []
876
+ fin_bal_currency_id = gl_item ["currency_id" ]
877
+ if gl_item ["currency_id" ]:
878
+ continue
879
+ gl_item ["fin_bal" ]["bal_curr" ] = gl_item ["init_bal" ]["bal_curr" ]
880
+ if "move_lines" in gl_item :
881
+ for ml in gl_item ["move_lines" ]:
882
+ ml_currency_id = (
883
+ ml ["currency_id" ][0 ] if ml ["currency_id" ] else False
884
+ )
885
+ if ml_currency_id and ml_currency_id != company .currency_id .id :
886
+ gl_item ["fin_bal" ]["bal_curr" ] += ml ["bal_curr" ]
887
+ if ml_currency_id not in fin_bal_currency_ids :
888
+ fin_bal_currency_ids .append (ml_currency_id )
889
+ elif "list_grouped" in gl_item :
890
+ fin_bal_currency_ids = []
891
+ for lg_item in gl_item ["list_grouped" ]:
892
+ lg_item ["fin_bal" ]["bal_curr" ] = lg_item ["init_bal" ]["bal_curr" ]
893
+ for ml in lg_item ["move_lines" ]:
894
+ ml_currency_id = (
895
+ ml ["currency_id" ][0 ] if ml ["currency_id" ] else False
896
+ )
897
+ if ml_currency_id and ml_currency_id != company .currency_id .id :
898
+ lg_item ["fin_bal" ]["bal_curr" ] += ml ["bal_curr" ]
899
+ gl_item ["fin_bal" ]["bal_curr" ] += ml ["bal_curr" ]
900
+ if ml_currency_id not in fin_bal_currency_ids :
901
+ fin_bal_currency_ids .append (ml_currency_id )
902
+ # If there is only 1 currency, we set that one as fin_bal_currency_id
903
+ # The use of different move lines with different currencies (EUR + GBP)
904
+ # will be excluded. We use a different field to avoid showing the initial
905
+ # balance and/or distorting data.
906
+ if not gl_item ["currency_id" ] and len (fin_bal_currency_ids ) == 1 :
907
+ fin_bal_currency_id = fin_bal_currency_ids [0 ]
908
+ gl_item ["fin_bal_currency_id" ] = fin_bal_currency_id
855
909
return {
856
910
"doc_ids" : [wizard_id ],
857
911
"doc_model" : "general.ledger.report.wizard" ,
0 commit comments