fix: Multiple fixes in payment entry

This commit is contained in:
Deepesh Garg 2021-07-29 19:46:17 +05:30
parent 035ce304fe
commit a57d13e1e9
2 changed files with 15 additions and 4 deletions

View File

@ -533,8 +533,8 @@ frappe.ui.form.on('Payment Entry', {
source_exchange_rate: function(frm) {
if (frm.doc.paid_amount) {
frm.set_value("base_paid_amount", flt(frm.doc.paid_amount) * flt(frm.doc.source_exchange_rate));
if(!frm.set_paid_amount_based_on_received_amount &&
(frm.doc.paid_from_account_currency == frm.doc.paid_to_account_currency)) {
// target exchange rate should always be same as source if both account currencies is same
if(frm.doc.paid_from_account_currency == frm.doc.paid_to_account_currency) {
frm.set_value("target_exchange_rate", frm.doc.source_exchange_rate);
frm.set_value("base_received_amount", frm.doc.base_paid_amount);
}

View File

@ -55,8 +55,9 @@ class PaymentEntry(AccountsController):
self.validate_mandatory()
self.validate_reference_documents()
self.set_tax_withholding()
self.apply_taxes()
self.set_amounts()
self.validate_amounts()
self.apply_taxes()
self.clear_unallocated_reference_document_rows()
self.validate_payment_against_negative_invoice()
self.validate_transaction_reference()
@ -236,7 +237,9 @@ class PaymentEntry(AccountsController):
self.company_currency, self.posting_date)
def set_target_exchange_rate(self, ref_doc=None):
if self.paid_to and not self.target_exchange_rate:
if self.paid_from_account_currency == self.paid_to_account_currency:
self.target_exchange_rate = self.source_exchange_rate
elif self.paid_to and not self.target_exchange_rate:
if ref_doc:
if self.paid_to_account_currency == ref_doc.currency:
self.target_exchange_rate = ref_doc.get("exchange_rate")
@ -473,6 +476,14 @@ class PaymentEntry(AccountsController):
self.set_unallocated_amount()
self.set_difference_amount()
def validate_amounts(self):
self.validate_received_amount()
def validate_received_amount(self):
if self.paid_from_account_currency == self.paid_to_account_currency:
if self.paid_amount != self.received_amount:
frappe.throw(_("Received Amount cannot be greater than Paid Amount"))
def set_received_amount(self):
self.base_received_amount = self.base_paid_amount