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
  • Loading branch information
venkat102 committed Sep 14, 2024
1 parent 4b125ea commit 2b66842
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 2b66842

Please sign in to comment.