Skip to content

Commit

Permalink
fix(ux): set amount on foreign currency when foreign currency account…
Browse files Browse the repository at this point in the history
… is selected on last row of journal

(cherry picked from commit 2b66842)
  • Loading branch information
venkat102 authored and mergify[bot] committed Sep 16, 2024
1 parent 00f144e commit d8d4cd2
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions erpnext/accounts/doctype/journal_entry/journal_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -680,11 +680,34 @@ $.extend(erpnext.journal_entry, {
callback: function (r) {
if (r.message) {
$.extend(d, r.message);
erpnext.journal_entry.set_amount_on_last_row(frm, dt, dn);
erpnext.journal_entry.set_debit_credit_in_company_currency(frm, dt, dn);
refresh_field("accounts");
}
},
});
}
},
set_amount_on_last_row: function (frm, dt, dn) {
let row = locals[dt][dn];
let length = frm.doc.accounts.length;
if (row.idx != length) return;

let difference = frm.doc.accounts.reduce((total, row) => {
if (row.idx == length) return total;

return total + row.debit - row.credit;
}, 0);

if (difference) {
if (difference > 0) {
row.credit_in_account_currency = difference / row.exchange_rate;
row.credit = difference;
} else {
row.debit_in_account_currency = -difference / row.exchange_rate;
row.debit = -difference;
}
}
refresh_field("accounts");
},
});

0 comments on commit d8d4cd2

Please sign in to comment.