@@ -21,7 +21,7 @@ def setUp(self):
2121 def tearDown (self ):
2222 frappe .db .rollback ()
2323
24- def create_sales_invoice (self , no_payment_schedule = False , do_not_submit = False ):
24+ def create_sales_invoice (self , no_payment_schedule = False , do_not_submit = False , ** args ):
2525 frappe .set_user ("Administrator" )
2626 si = create_sales_invoice (
2727 item = self .item ,
@@ -34,6 +34,7 @@ def create_sales_invoice(self, no_payment_schedule=False, do_not_submit=False):
3434 rate = 100 ,
3535 price_list_rate = 100 ,
3636 do_not_save = 1 ,
37+ ** args ,
3738 )
3839 if not no_payment_schedule :
3940 si .append (
@@ -111,7 +112,7 @@ def test_pos_receivable(self):
111112 self .assertEqual (expected_data [0 ], [row .invoiced , row .paid , row .credit_note ])
112113 pos_inv .cancel ()
113114
114- def test_accounts_receivable (self ):
115+ def test_accounts_receivable_with_payment (self ):
115116 filters = {
116117 "company" : self .company ,
117118 "based_on_payment_terms" : 1 ,
@@ -151,11 +152,15 @@ def test_accounts_receivable(self):
151152 cr_note = self .create_credit_note (si .name , do_not_submit = True )
152153 cr_note .update_outstanding_for_self = False
153154 cr_note .save ().submit ()
155+
156+ # as the invoice partially paid and returning the full amount so the outstanding amount should be True
157+ self .assertEqual (cr_note .update_outstanding_for_self , True )
158+
154159 report = execute (filters )
155160
156- expected_data_after_credit_note = [100 , 0 , 0 , 40 , - 40 , self .debit_to ]
161+ expected_data_after_credit_note = [0 , 0 , 100 , 0 , - 100 , self .debit_to ]
157162
158- row = report [1 ][0 ]
163+ row = report [1 ][- 1 ]
159164 self .assertEqual (
160165 expected_data_after_credit_note ,
161166 [
@@ -168,6 +173,105 @@ def test_accounts_receivable(self):
168173 ],
169174 )
170175
176+ def test_accounts_receivable_without_payment (self ):
177+ filters = {
178+ "company" : self .company ,
179+ "based_on_payment_terms" : 1 ,
180+ "report_date" : today (),
181+ "range1" : 30 ,
182+ "range2" : 60 ,
183+ "range3" : 90 ,
184+ "range4" : 120 ,
185+ "show_remarks" : True ,
186+ }
187+
188+ # check invoice grand total and invoiced column's value for 3 payment terms
189+ si = self .create_sales_invoice ()
190+
191+ report = execute (filters )
192+
193+ expected_data = [[100 , 30 , "No Remarks" ], [100 , 50 , "No Remarks" ], [100 , 20 , "No Remarks" ]]
194+
195+ for i in range (3 ):
196+ row = report [1 ][i - 1 ]
197+ self .assertEqual (expected_data [i - 1 ], [row .invoice_grand_total , row .invoiced , row .remarks ])
198+
199+ # check invoice grand total, invoiced, paid and outstanding column's value after credit note
200+ cr_note = self .create_credit_note (si .name , do_not_submit = True )
201+ cr_note .update_outstanding_for_self = False
202+ cr_note .save ().submit ()
203+
204+ self .assertEqual (cr_note .update_outstanding_for_self , False )
205+
206+ report = execute (filters )
207+
208+ row = report [1 ]
209+ self .assertTrue (len (row ) == 0 )
210+
211+ def test_accounts_receivable_with_partial_payment (self ):
212+ filters = {
213+ "company" : self .company ,
214+ "based_on_payment_terms" : 1 ,
215+ "report_date" : today (),
216+ "range1" : 30 ,
217+ "range2" : 60 ,
218+ "range3" : 90 ,
219+ "range4" : 120 ,
220+ "show_remarks" : True ,
221+ }
222+
223+ # check invoice grand total and invoiced column's value for 3 payment terms
224+ si = self .create_sales_invoice (qty = 2 )
225+
226+ report = execute (filters )
227+
228+ expected_data = [[200 , 60 , "No Remarks" ], [200 , 100 , "No Remarks" ], [200 , 40 , "No Remarks" ]]
229+
230+ for i in range (3 ):
231+ row = report [1 ][i - 1 ]
232+ self .assertEqual (expected_data [i - 1 ], [row .invoice_grand_total , row .invoiced , row .remarks ])
233+
234+ # check invoice grand total, invoiced, paid and outstanding column's value after payment
235+ self .create_payment_entry (si .name )
236+ report = execute (filters )
237+
238+ expected_data_after_payment = [[200 , 60 , 40 , 20 ], [200 , 100 , 0 , 100 ], [200 , 40 , 0 , 40 ]]
239+
240+ for i in range (3 ):
241+ row = report [1 ][i - 1 ]
242+ self .assertEqual (
243+ expected_data_after_payment [i - 1 ],
244+ [row .invoice_grand_total , row .invoiced , row .paid , row .outstanding ],
245+ )
246+
247+ # check invoice grand total, invoiced, paid and outstanding column's value after credit note
248+ cr_note = self .create_credit_note (si .name , do_not_submit = True )
249+ cr_note .update_outstanding_for_self = False
250+ cr_note .save ().submit ()
251+
252+ self .assertFalse (cr_note .update_outstanding_for_self )
253+
254+ report = execute (filters )
255+
256+ expected_data_after_credit_note = [
257+ [200 , 100 , 0 , 80 , 20 , self .debit_to ],
258+ [200 , 40 , 0 , 0 , 40 , self .debit_to ],
259+ ]
260+
261+ for i in range (2 ):
262+ row = report [1 ][i - 1 ]
263+ self .assertEqual (
264+ expected_data_after_credit_note [i - 1 ],
265+ [
266+ row .invoice_grand_total ,
267+ row .invoiced ,
268+ row .paid ,
269+ row .credit_note ,
270+ row .outstanding ,
271+ row .party_account ,
272+ ],
273+ )
274+
171275 def test_cr_note_flag_to_update_self (self ):
172276 filters = {
173277 "company" : self .company ,
0 commit comments