Skip to content

Commit

Permalink
Merge pull request #34694 from ruthra-kumar/recalculate_difference_on…
Browse files Browse the repository at this point in the history
…_allocation_change

fix(ui): recalculate difference amount on allocation change
  • Loading branch information
ruthra-kumar authored Apr 3, 2023
2 parents 4c61ee3 + 32a4ca6 commit 1eefd51
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,32 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo
}
};

frappe.ui.form.on('Payment Reconciliation Allocation', {
allocated_amount: function(frm, cdt, cdn) {
let row = locals[cdt][cdn];
// filter invoice
let invoice = frm.doc.invoices.filter((x) => (x.invoice_number == row.invoice_number));
// filter payment
let payment = frm.doc.payments.filter((x) => (x.reference_name == row.reference_name));

frm.call({
doc: frm.doc,
method: 'calculate_difference_on_allocation_change',
args: {
payment_entry: payment,
invoice: invoice,
allocated_amount: row.allocated_amount
},
callback: (r) => {
if (r.message) {
row.difference_amount = r.message;
frm.refresh();
}
}
});
}
});



extend_cscript(cur_frm.cscript, new erpnext.accounts.PaymentReconciliationController({frm: cur_frm}));
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,15 @@ def get_difference_amount(self, payment_entry, invoice, allocated_amount):

return difference_amount

@frappe.whitelist()
def calculate_difference_on_allocation_change(self, payment_entry, invoice, allocated_amount):
invoice_exchange_map = self.get_invoice_exchange_map(invoice, payment_entry)
invoice[0]["exchange_rate"] = invoice_exchange_map.get(invoice[0].get("invoice_number"))
new_difference_amount = self.get_difference_amount(
payment_entry[0], invoice[0], allocated_amount
)
return new_difference_amount

@frappe.whitelist()
def allocate_entries(self, args):
self.validate_entries()
Expand Down

0 comments on commit 1eefd51

Please sign in to comment.