@@ -529,7 +529,7 @@ def get_payment_terms(self, row):
529529 select
530530 si.name, si.party_account_currency, si.currency, si.conversion_rate,
531531 si.total_advance, ps.due_date, ps.payment_term, ps.payment_amount, ps.base_payment_amount,
532- ps.description, ps.paid_amount, ps.discounted_amount
532+ ps.description, ps.paid_amount, ps.base_paid_amount, ps. discounted_amount
533533 from `tab{ row .voucher_type } ` si, `tabPayment Schedule` ps
534534 where
535535 si.name = ps.parent and
@@ -552,20 +552,24 @@ def get_payment_terms(self, row):
552552 # Deduct that from paid amount pre allocation
553553 row .paid -= flt (payment_terms_details [0 ].total_advance )
554554
555+ company_currency = frappe .get_value ("Company" , self .filters .get ("company" ), "default_currency" )
556+
555557 # If single payment terms, no need to split the row
556558 if len (payment_terms_details ) == 1 and payment_terms_details [0 ].payment_term :
557- self .append_payment_term (row , payment_terms_details [0 ], original_row )
559+ self .append_payment_term (row , payment_terms_details [0 ], original_row , company_currency )
558560 return
559561
560562 for d in payment_terms_details :
561563 term = frappe ._dict (original_row )
562- self .append_payment_term (row , d , term )
564+ self .append_payment_term (row , d , term , company_currency )
565+
566+ def append_payment_term (self , row , d , term , company_currency ):
567+ invoiced = d .base_payment_amount
568+ paid_amount = d .base_paid_amount
563569
564- def append_payment_term (self , row , d , term ):
565- if d .currency == d .party_account_currency :
570+ if company_currency == d .party_account_currency or self .filters .get ("in_party_currency" ):
566571 invoiced = d .payment_amount
567- else :
568- invoiced = d .base_payment_amount
572+ paid_amount = d .paid_amount
569573
570574 row .payment_terms .append (
571575 term .update (
@@ -574,15 +578,15 @@ def append_payment_term(self, row, d, term):
574578 "invoiced" : invoiced ,
575579 "invoice_grand_total" : row .invoiced ,
576580 "payment_term" : d .description or d .payment_term ,
577- "paid" : d . paid_amount + d .discounted_amount ,
581+ "paid" : paid_amount + d .discounted_amount ,
578582 "credit_note" : 0.0 ,
579- "outstanding" : invoiced - d . paid_amount - d .discounted_amount ,
583+ "outstanding" : invoiced - paid_amount - d .discounted_amount ,
580584 }
581585 )
582586 )
583587
584- if d . paid_amount :
585- row ["paid" ] -= d . paid_amount + d .discounted_amount
588+ if paid_amount :
589+ row ["paid" ] -= paid_amount + d .discounted_amount
586590
587591 def allocate_closing_to_term (self , row , term , key ):
588592 if row [key ]:
0 commit comments