@@ -69,6 +69,10 @@ def set_defaults(self):
69
69
self .previous_party = ''
70
70
self .total_row_map = {}
71
71
self .skip_total_row = 1
72
+ elif self .filters .get ('group_by_family' ):
73
+ self .previous_family = ''
74
+ self .total_family_row_map = {}
75
+ self .skip_total_row = 1
72
76
73
77
def get_data (self ):
74
78
self .get_gl_entries ()
@@ -106,6 +110,8 @@ def init_voucher_balance(self):
106
110
else :
107
111
familia = None
108
112
113
+ if self .filters .get ('group_by_family' ) and not familia :
114
+ continue
109
115
# get the balance object for voucher_type
110
116
key = (gle .voucher_type , gle .voucher_no , gle .party )
111
117
if not key in self .voucher_balance :
@@ -130,9 +136,13 @@ def init_voucher_balance(self):
130
136
131
137
if self .filters .get ('group_by_party' ):
132
138
self .init_subtotal_row (gle .party )
139
+ elif self .filters .get ('group_by_family' ):
140
+ self .init_subtotal_family_row (familia )
133
141
134
142
if self .filters .get ('group_by_party' ):
135
143
self .init_subtotal_row ('Total' )
144
+ elif self .filters .get ('group_by_family' ):
145
+ self .init_subtotal_family_row ('Total' )
136
146
137
147
def get_invoices (self , gle ):
138
148
if gle .voucher_type in ('Sales Invoice' , 'Purchase Invoice' ):
@@ -152,6 +162,16 @@ def init_subtotal_row(self, party):
152
162
153
163
for field in self .get_currency_fields ():
154
164
self .total_row_map [party ][field ] = 0.0
165
+
166
+ def init_subtotal_family_row (self , familia ):
167
+ if not self .total_family_row_map .get (familia ):
168
+ self .total_family_row_map .setdefault (familia , {
169
+ 'familia' : familia ,
170
+ 'bold' : 1
171
+ })
172
+
173
+ for field in self .get_currency_fields ():
174
+ self .total_family_row_map [familia ][field ] = 0.0
155
175
156
176
def get_currency_fields (self ):
157
177
return ['invoiced' , 'paid' , 'credit_note' , 'outstanding' , 'range1' , 'range2' , 'range3' , 'range4' , 'range5' ]
@@ -194,6 +214,12 @@ def update_sub_total_row(self, row, party):
194
214
195
215
for field in self .get_currency_fields ():
196
216
total_row [field ] += row .get (field , 0.0 )
217
+
218
+ def update_sub_total_family_row (self , row , familia ):
219
+ total_row = self .total_family_row_map .get (familia )
220
+
221
+ for field in self .get_currency_fields ():
222
+ total_row [field ] += row .get (field , 0.0 )
197
223
198
224
def append_subtotal_row (self , party ):
199
225
sub_total_row = self .total_row_map .get (party )
@@ -202,6 +228,14 @@ def append_subtotal_row(self, party):
202
228
self .data .append (sub_total_row )
203
229
self .data .append ({})
204
230
self .update_sub_total_row (sub_total_row , 'Total' )
231
+
232
+ def append_subtotal_family_row (self , familia ):
233
+ sub_total_row = self .total_family_row_map .get (familia )
234
+
235
+ if sub_total_row :
236
+ self .data .append (sub_total_row )
237
+ self .data .append ({})
238
+ self .update_sub_total_family_row (sub_total_row , 'Total' )
205
239
206
240
def get_voucher_balance (self , gle ):
207
241
if self .filters .get ("sales_person" ):
@@ -276,6 +310,8 @@ def build_data(self):
276
310
conversion_rate = get_exchange_rate ("USD" , vourcher_data [currency_field ], nowdate (), exchange_type )
277
311
row .outstanding_original_currency = flt ((row .outstanding / conversion_rate ), self .currency_precision )
278
312
313
+ row ['voucher_type' ] = _ (row ['voucher_type' ])
314
+
279
315
if frappe .get_hooks ('accounts_receivable_usd_column' ) and row .outstanding == 0.0 :
280
316
row .outstanding_original_currency = 0
281
317
@@ -306,6 +342,10 @@ def build_data(self):
306
342
self .append_subtotal_row (self .previous_party )
307
343
if self .data :
308
344
self .data .append (self .total_row_map .get ('Total' ))
345
+ elif self .filters .get ('group_by_family' ):
346
+ self .append_subtotal_family_row (self .previous_family )
347
+ if self .data :
348
+ self .data .append (self .total_family_row_map .get ('Total' ))
309
349
310
350
def append_row (self , row ):
311
351
self .allocate_future_payments (row )
@@ -318,6 +358,11 @@ def append_row(self, row):
318
358
if self .previous_party and (self .previous_party != row .party ):
319
359
self .append_subtotal_row (self .previous_party )
320
360
self .previous_party = row .party
361
+ elif self .filters .get ('group_by_family' ):
362
+ self .update_sub_total_family_row (row , row .familia )
363
+ if self .previous_family and (self .previous_family != row .familia ):
364
+ self .append_subtotal_family_row (self .previous_family )
365
+ self .previous_family = row .familia
321
366
322
367
self .data .append (row )
323
368
@@ -652,7 +697,7 @@ def get_gl_entries(self):
652
697
doc_currency_fields = "debit_in_account_currency, credit_in_account_currency"
653
698
654
699
remarks = ", remarks" if self .filters .get ("show_remarks" ) else ""
655
-
700
+
656
701
self .gl_entries = frappe .db .sql ("""
657
702
select
658
703
name, posting_date, account, party_type, party, voucher_type, voucher_no, cost_center,
@@ -712,6 +757,8 @@ def get_cost_center_conditions(self, conditions):
712
757
def get_order_by_condition (self ):
713
758
if self .filters .get ('group_by_party' ):
714
759
return "order by party, posting_date"
760
+ elif self .filters .get ('group_by_family' ):
761
+ return "order by party, posting_date"
715
762
else :
716
763
return "order by posting_date, party"
717
764
0 commit comments