Skip to content

Commit

Permalink
refactor: Exchange rate revaluation to handle accounts with zero acco…
Browse files Browse the repository at this point in the history
…unt balance (#33165)

* refactor: new type for JE - Exchange Gain or Loss

* refactor: skip few validations for Exchanage Gain Or Loss type Jour

* refactor: ERR create 2 journals for handling zero and non-zero compa

1. Additional check box accounts table to identify accounts with zero balance
2. Accounts with zero balance only in either of the 2 currencies will be handled on separate Journal

* refactor: skips few validation for allowing 0 debit/credit

* fix: General Ledger presentaion currency

* test: fix test case in general ledger

* test: fix failing test case in AR report

(cherry picked from commit 914b230)
  • Loading branch information
ruthra-kumar committed Jan 2, 2023
1 parent 45d8feb commit 146733c
Show file tree
Hide file tree
Showing 11 changed files with 552 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ frappe.ui.form.on('Exchange Rate Revaluation', {
doc: frm.doc,
callback: function(r) {
if (r.message) {
frm.add_custom_button(__('Journal Entry'), function() {
frm.add_custom_button(__('Journal Entries'), function() {
return frm.events.make_jv(frm);
}, __('Create'));
}
Expand All @@ -35,10 +35,11 @@ frappe.ui.form.on('Exchange Rate Revaluation', {
}
},

get_entries: function(frm) {
get_entries: function(frm, account) {
frappe.call({
method: "get_accounts_data",
doc: cur_frm.doc,
account: account,
callback: function(r){
frappe.model.clear_table(frm.doc, "accounts");
if(r.message) {
Expand All @@ -57,7 +58,6 @@ frappe.ui.form.on('Exchange Rate Revaluation', {

let total_gain_loss = 0;
frm.doc.accounts.forEach((d) => {
d.gain_loss = flt(d.new_balance_in_base_currency, precision("new_balance_in_base_currency", d)) - flt(d.balance_in_base_currency, precision("balance_in_base_currency", d));
total_gain_loss += flt(d.gain_loss, precision("gain_loss", d));
});

Expand All @@ -66,13 +66,19 @@ frappe.ui.form.on('Exchange Rate Revaluation', {
},

make_jv : function(frm) {
let revaluation_journal = null;
let zero_balance_journal = null;
frappe.call({
method: "make_jv_entry",
method: "make_jv_entries",
doc: frm.doc,
freeze: true,
freeze_message: "Making Journal Entries...",
callback: function(r){
if (r.message) {
var doc = frappe.model.sync(r.message)[0];
frappe.set_route("Form", doc.doctype, doc.name);
let response = r.message;
if(response['revaluation_jv'] || response['zero_balance_jv']) {
frappe.msgprint(__("Journals have been created"));
}
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"get_entries",
"accounts",
"section_break_6",
"gain_loss_unbooked",
"gain_loss_booked",
"column_break_10",
"total_gain_loss",
"amended_from"
],
Expand Down Expand Up @@ -59,13 +62,6 @@
"fieldname": "section_break_6",
"fieldtype": "Section Break"
},
{
"fieldname": "total_gain_loss",
"fieldtype": "Currency",
"label": "Total Gain/Loss",
"options": "Company:company:default_currency",
"read_only": 1
},
{
"fieldname": "amended_from",
"fieldtype": "Link",
Expand All @@ -74,11 +70,37 @@
"options": "Exchange Rate Revaluation",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "gain_loss_unbooked",
"fieldtype": "Currency",
"label": "Gain/Loss from Revaluation",
"options": "Company:company:default_currency",
"read_only": 1
},
{
"description": "Gain/Loss accumulated in foreign currency account. Accounts with '0' balance in either Base or Account currency",
"fieldname": "gain_loss_booked",
"fieldtype": "Currency",
"label": "Gain/Loss already booked",
"options": "Company:company:default_currency",
"read_only": 1
},
{
"fieldname": "total_gain_loss",
"fieldtype": "Currency",
"label": "Total Gain/Loss",
"options": "Company:company:default_currency",
"read_only": 1
},
{
"fieldname": "column_break_10",
"fieldtype": "Column Break"
}
],
"is_submittable": 1,
"links": [],
"modified": "2022-11-17 10:28:03.911554",
"modified": "2022-12-29 19:38:24.416529",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Exchange Rate Revaluation",
Expand Down
Loading

0 comments on commit 146733c

Please sign in to comment.