mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-24 15:39:20 +00:00
fix:reverse journal entry (#23224)
This commit is contained in:
@@ -619,20 +619,12 @@ $.extend(erpnext.journal_entry, {
|
|||||||
return { filters: filters };
|
return { filters: filters };
|
||||||
},
|
},
|
||||||
|
|
||||||
reverse_journal_entry: function(frm) {
|
reverse_journal_entry: function() {
|
||||||
var me = frm.doc;
|
frappe.model.open_mapped_doc({
|
||||||
for(var i=0; i<me.accounts.length; i++) {
|
method: "erpnext.accounts.doctype.journal_entry.journal_entry.make_reverse_journal_entry",
|
||||||
me.accounts[i].credit += me.accounts[i].debit;
|
frm: cur_frm
|
||||||
me.accounts[i].debit = me.accounts[i].credit - me.accounts[i].debit;
|
})
|
||||||
me.accounts[i].credit -= me.accounts[i].debit;
|
},
|
||||||
me.accounts[i].credit_in_account_currency = me.accounts[i].credit;
|
|
||||||
me.accounts[i].debit_in_account_currency = me.accounts[i].debit;
|
|
||||||
me.accounts[i].reference_type = "Journal Entry";
|
|
||||||
me.accounts[i].reference_name = me.name
|
|
||||||
}
|
|
||||||
frm.copy_doc();
|
|
||||||
cur_frm.reload_doc();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$.extend(erpnext.journal_entry, {
|
$.extend(erpnext.journal_entry, {
|
||||||
|
|||||||
@@ -1017,3 +1017,34 @@ def make_inter_company_journal_entry(name, voucher_type, company):
|
|||||||
journal_entry.posting_date = nowdate()
|
journal_entry.posting_date = nowdate()
|
||||||
journal_entry.inter_company_journal_entry_reference = name
|
journal_entry.inter_company_journal_entry_reference = name
|
||||||
return journal_entry.as_dict()
|
return journal_entry.as_dict()
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def make_reverse_journal_entry(source_name, target_doc=None, ignore_permissions=False):
|
||||||
|
from frappe.model.mapper import get_mapped_doc
|
||||||
|
|
||||||
|
def update_accounts(source, target, source_parent):
|
||||||
|
target.reference_type = "Journal Entry"
|
||||||
|
target.reference_name = source_parent.name
|
||||||
|
|
||||||
|
doclist = get_mapped_doc("Journal Entry", source_name, {
|
||||||
|
"Journal Entry": {
|
||||||
|
"doctype": "Journal Entry",
|
||||||
|
"validation": {
|
||||||
|
"docstatus": ["=", 1]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Journal Entry Account": {
|
||||||
|
"doctype": "Journal Entry Account",
|
||||||
|
"field_map": {
|
||||||
|
"account_currency": "account_currency",
|
||||||
|
"exchange_rate": "exchange_rate",
|
||||||
|
"debit_in_account_currency": "credit_in_account_currency",
|
||||||
|
"debit": "credit",
|
||||||
|
"credit_in_account_currency": "debit_in_account_currency",
|
||||||
|
"credit": "debit",
|
||||||
|
},
|
||||||
|
"postprocess": update_accounts,
|
||||||
|
},
|
||||||
|
}, target_doc, ignore_permissions=ignore_permissions)
|
||||||
|
|
||||||
|
return doclist
|
||||||
@@ -139,6 +139,49 @@ class TestJournalEntry(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertFalse(gle)
|
self.assertFalse(gle)
|
||||||
|
|
||||||
|
def test_reverse_journal_entry(self):
|
||||||
|
from erpnext.accounts.doctype.journal_entry.journal_entry import make_reverse_journal_entry
|
||||||
|
jv = make_journal_entry("_Test Bank USD - _TC",
|
||||||
|
"Sales - _TC", 100, exchange_rate=50, save=False)
|
||||||
|
|
||||||
|
jv.get("accounts")[1].credit_in_account_currency = 5000
|
||||||
|
jv.get("accounts")[1].exchange_rate = 1
|
||||||
|
jv.submit()
|
||||||
|
|
||||||
|
rjv = make_reverse_journal_entry(jv.name)
|
||||||
|
rjv.posting_date = nowdate()
|
||||||
|
rjv.submit()
|
||||||
|
|
||||||
|
|
||||||
|
gl_entries = frappe.db.sql("""select account, account_currency, debit, credit,
|
||||||
|
debit_in_account_currency, credit_in_account_currency
|
||||||
|
from `tabGL Entry` where voucher_type='Journal Entry' and voucher_no=%s
|
||||||
|
order by account asc""", rjv.name, as_dict=1)
|
||||||
|
|
||||||
|
self.assertTrue(gl_entries)
|
||||||
|
|
||||||
|
|
||||||
|
expected_values = {
|
||||||
|
"_Test Bank USD - _TC": {
|
||||||
|
"account_currency": "USD",
|
||||||
|
"debit": 0,
|
||||||
|
"debit_in_account_currency": 0,
|
||||||
|
"credit": 5000,
|
||||||
|
"credit_in_account_currency": 100,
|
||||||
|
},
|
||||||
|
"Sales - _TC": {
|
||||||
|
"account_currency": "INR",
|
||||||
|
"debit": 5000,
|
||||||
|
"debit_in_account_currency": 5000,
|
||||||
|
"credit": 0,
|
||||||
|
"credit_in_account_currency": 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for field in ("account_currency", "debit", "debit_in_account_currency", "credit", "credit_in_account_currency"):
|
||||||
|
for i, gle in enumerate(gl_entries):
|
||||||
|
self.assertEqual(expected_values[gle.account][field], gle[field])
|
||||||
|
|
||||||
def test_disallow_change_in_account_currency_for_a_party(self):
|
def test_disallow_change_in_account_currency_for_a_party(self):
|
||||||
# create jv in USD
|
# create jv in USD
|
||||||
jv = make_journal_entry("_Test Bank USD - _TC",
|
jv = make_journal_entry("_Test Bank USD - _TC",
|
||||||
|
|||||||
Reference in New Issue
Block a user