Merge branch 'develop' into editable-journal-entries
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.js b/erpnext/accounts/doctype/journal_entry/journal_entry.js
index 07fb5e8..72469ea 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.js
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.js
@@ -14,6 +14,25 @@
refresh: function(frm) {
erpnext.toggle_naming_series();
+ if (frm.doc.repost_required && frm.doc.docstatus===1) {
+ frm.set_intro(__("Accounting entries for this Journal Entry need to be reposted. Please click on 'Repost' button to update."));
+ frm.add_custom_button(__('Repost Accounting Entries'),
+ () => {
+ frm.call({
+ doc: frm.doc,
+ method: 'repost_accounting_entries',
+ freeze: true,
+ freeze_message: __('Reposting...'),
+ callback: (r) => {
+ if (!r.exc) {
+ frappe.msgprint(__('Accounting Entries are reposted.'));
+ frm.refresh();
+ }
+ }
+ });
+ }).removeClass('btn-default').addClass('btn-warning');
+ }
+
if(frm.doc.docstatus > 0) {
frm.add_custom_button(__('Ledger'), function() {
frappe.route_options = {
@@ -184,7 +203,6 @@
$.each(r, function(i, d) {
var row = frappe.model.add_child(doc, "Journal Entry Account", "accounts");
frappe.model.set_value(row.doctype, row.name, "account", d.account)
- frappe.model.set_value(row.doctype, row.name, "balance", d.balance)
});
refresh_field("accounts");
}
@@ -193,7 +211,6 @@
onload() {
this.load_defaults();
this.setup_queries();
- this.setup_balance_formatter();
erpnext.accounts.dimensions.setup_dimension_filters(this.frm, this.frm.doctype);
}
@@ -292,19 +309,6 @@
}
- setup_balance_formatter() {
- const formatter = function(value, df, options, doc) {
- var currency = frappe.meta.get_field_currency(df, doc);
- var dr_or_cr = value ? ('<label>' + (value > 0.0 ? __("Dr") : __("Cr")) + '</label>') : "";
- return "<div style='text-align: right'>"
- + ((value==null || value==="") ? "" : format_currency(Math.abs(value), currency))
- + " " + dr_or_cr
- + "</div>";
- };
- this.frm.fields_dict.accounts.grid.update_docfield_property('balance', 'formatter', formatter);
- this.frm.fields_dict.accounts.grid.update_docfield_property('party_balance', 'formatter', formatter);
- }
-
reference_name(doc, cdt, cdn) {
var d = frappe.get_doc(cdt, cdn);
@@ -400,23 +404,22 @@
if(!d.account && d.party_type && d.party) {
if(!frm.doc.company) frappe.throw(__("Please select Company"));
return frm.call({
- method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_party_account_and_balance",
+ method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_party_account_and_currency",
child: d,
args: {
company: frm.doc.company,
party_type: d.party_type,
party: d.party,
- cost_center: d.cost_center
}
});
}
},
cost_center: function(frm, dt, dn) {
- erpnext.journal_entry.set_account_balance(frm, dt, dn);
+ erpnext.journal_entry.set_account_details(frm, dt, dn);
},
account: function(frm, dt, dn) {
- erpnext.journal_entry.set_account_balance(frm, dt, dn);
+ erpnext.journal_entry.set_account_details(frm, dt, dn);
},
debit_in_account_currency: function(frm, cdt, cdn) {
@@ -600,14 +603,14 @@
});
$.extend(erpnext.journal_entry, {
- set_account_balance: function(frm, dt, dn) {
+ set_account_details: function(frm, dt, dn) {
var d = locals[dt][dn];
if(d.account) {
if(!frm.doc.company) frappe.throw(__("Please select Company first"));
if(!frm.doc.posting_date) frappe.throw(__("Please select Posting Date first"));
return frappe.call({
- method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_account_balance_and_party_type",
+ method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_account_details_and_party_type",
args: {
account: d.account,
date: frm.doc.posting_date,
@@ -615,7 +618,6 @@
debit: flt(d.debit_in_account_currency),
credit: flt(d.credit_in_account_currency),
exchange_rate: d.exchange_rate,
- cost_center: d.cost_center
},
callback: function(r) {
if(r.message) {
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.json b/erpnext/accounts/doctype/journal_entry/journal_entry.json
index 906760e..a0fcaf9 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.json
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.json
@@ -64,7 +64,8 @@
"stock_entry",
"subscription_section",
"auto_repeat",
- "amended_from"
+ "amended_from",
+ "repost_required"
],
"fields": [
{
@@ -543,6 +544,15 @@
"label": "Is System Generated",
"no_copy": 1,
"read_only": 1
+ },
+ {
+ "default": "0",
+ "fieldname": "repost_required",
+ "fieldtype": "Check",
+ "hidden": 1,
+ "label": "Repost Required",
+ "print_hide": 1,
+ "read_only": 1
}
],
"icon": "fa fa-file-text",
@@ -558,6 +568,7 @@
}
],
"modified": "2023-11-23 12:11:04.128015",
+
"modified_by": "Administrator",
"module": "Accounts",
"name": "Journal Entry",
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py
index 7bf5324..c0dfaff 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py
@@ -140,7 +140,6 @@
self.set_print_format_fields()
self.validate_credit_debit_note()
self.validate_empty_accounts_table()
- self.set_account_and_party_balance()
self.validate_inter_company_accounts()
self.validate_depr_entry_voucher_type()
@@ -150,6 +149,13 @@
if not self.title:
self.title = self.get_title()
+ def validate_for_repost(self):
+ self.validate_party()
+ self.validate_multi_currency()
+ if not frappe.flags.is_reverse_depr_entry:
+ self.validate_against_jv()
+ self.validate_stock_accounts()
+
def submit(self):
if len(self.accounts) > 100:
msgprint(_("The task has been enqueued as a background job."), alert=True)
@@ -173,6 +179,13 @@
self.update_inter_company_jv()
self.update_invoice_discounting()
+ def on_update_after_submit(self):
+ if hasattr(self, "repost_required"):
+ child_tables = {"accounts": ("account", "account_type", "bank_account")}
+ self.needs_repost = self.check_if_fields_updated([], child_tables)
+ self.validate_for_repost()
+ self.db_set("repost_required", self.needs_repost)
+
def on_cancel(self):
# References for this Journal are removed on the `on_cancel` event in accounts_controller
super(JournalEntry, self).on_cancel()
@@ -1152,21 +1165,6 @@
if not self.get("accounts"):
frappe.throw(_("Accounts table cannot be blank."))
- def set_account_and_party_balance(self):
- account_balance = {}
- party_balance = {}
- for d in self.get("accounts"):
- if d.account not in account_balance:
- account_balance[d.account] = get_balance_on(account=d.account, date=self.posting_date)
-
- if (d.party_type, d.party) not in party_balance:
- party_balance[(d.party_type, d.party)] = get_balance_on(
- party_type=d.party_type, party=d.party, date=self.posting_date, company=self.company
- )
-
- d.account_balance = account_balance[d.account]
- d.party_balance = party_balance[(d.party_type, d.party)]
-
@frappe.whitelist()
def get_default_bank_cash_account(company, account_type=None, mode_of_payment=None, account=None):
@@ -1332,8 +1330,6 @@
"account_type": frappe.get_cached_value("Account", args.get("party_account"), "account_type"),
"account_currency": args.get("party_account_currency")
or get_account_currency(args.get("party_account")),
- "balance": get_balance_on(args.get("party_account")),
- "party_balance": get_balance_on(party=args.get("party"), party_type=args.get("party_type")),
"exchange_rate": exchange_rate,
args.get("amount_field_party"): args.get("amount"),
"is_advance": args.get("is_advance"),
@@ -1481,30 +1477,23 @@
@frappe.whitelist()
-def get_party_account_and_balance(company, party_type, party, cost_center=None):
+def get_party_account_and_currency(company, party_type, party):
if not frappe.has_permission("Account"):
frappe.msgprint(_("No Permission"), raise_exception=1)
account = get_party_account(party_type, party, company)
- account_balance = get_balance_on(account=account, cost_center=cost_center)
- party_balance = get_balance_on(
- party_type=party_type, party=party, company=company, cost_center=cost_center
- )
-
return {
"account": account,
- "balance": account_balance,
- "party_balance": party_balance,
"account_currency": frappe.get_cached_value("Account", account, "account_currency"),
}
@frappe.whitelist()
-def get_account_balance_and_party_type(
- account, date, company, debit=None, credit=None, exchange_rate=None, cost_center=None
+def get_account_details_and_party_type(
+ account, date, company, debit=None, credit=None, exchange_rate=None
):
- """Returns dict of account balance and party type to be set in Journal Entry on selection of account."""
+ """Returns dict of account details and party type to be set in Journal Entry on selection of account."""
if not frappe.has_permission("Account"):
frappe.msgprint(_("No Permission"), raise_exception=1)
@@ -1524,7 +1513,6 @@
party_type = ""
grid_values = {
- "balance": get_balance_on(account, date, cost_center=cost_center),
"party_type": party_type,
"account_type": account_details.account_type,
"account_currency": account_details.account_currency or company_currency,
diff --git a/erpnext/accounts/doctype/journal_entry/test_journal_entry.py b/erpnext/accounts/doctype/journal_entry/test_journal_entry.py
index a6e920b..7106d9a 100644
--- a/erpnext/accounts/doctype/journal_entry/test_journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/test_journal_entry.py
@@ -166,43 +166,37 @@
jv.get("accounts")[1].credit_in_account_currency = 5000
jv.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""",
- jv.name,
- as_dict=1,
- )
+ self.voucher_no = jv.name
- self.assertTrue(gl_entries)
+ self.fields = [
+ "account",
+ "account_currency",
+ "debit",
+ "debit_in_account_currency",
+ "credit",
+ "credit_in_account_currency",
+ ]
- expected_values = {
- "_Test Bank USD - _TC": {
- "account_currency": "USD",
- "debit": 5000,
- "debit_in_account_currency": 100,
- "credit": 0,
- "credit_in_account_currency": 0,
- },
- "_Test Bank - _TC": {
+ self.expected_gle = [
+ {
+ "account": "_Test Bank - _TC",
"account_currency": "INR",
"debit": 0,
"debit_in_account_currency": 0,
"credit": 5000,
"credit_in_account_currency": 5000,
},
- }
+ {
+ "account": "_Test Bank USD - _TC",
+ "account_currency": "USD",
+ "debit": 5000,
+ "debit_in_account_currency": 100,
+ "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])
+ self.check_gl_entries()
# cancel
jv.cancel()
@@ -228,43 +222,37 @@
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.voucher_no = rjv.name
- self.assertTrue(gl_entries)
+ self.fields = [
+ "account",
+ "account_currency",
+ "debit",
+ "credit",
+ "debit_in_account_currency",
+ "credit_in_account_currency",
+ ]
- expected_values = {
- "_Test Bank USD - _TC": {
+ self.expected_gle = [
+ {
+ "account": "_Test Bank USD - _TC",
"account_currency": "USD",
"debit": 0,
"debit_in_account_currency": 0,
"credit": 5000,
"credit_in_account_currency": 100,
},
- "Sales - _TC": {
+ {
+ "account": "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])
+ self.check_gl_entries()
def test_disallow_change_in_account_currency_for_a_party(self):
# create jv in USD
@@ -344,23 +332,25 @@
jv.insert()
jv.submit()
- expected_values = {
- "_Test Cash - _TC": {"cost_center": cost_center},
- "_Test Bank - _TC": {"cost_center": cost_center},
- }
+ self.voucher_no = jv.name
- gl_entries = frappe.db.sql(
- """select account, cost_center, debit, credit
- from `tabGL Entry` where voucher_type='Journal Entry' and voucher_no=%s
- order by account asc""",
- jv.name,
- as_dict=1,
- )
+ self.fields = [
+ "account",
+ "cost_center",
+ ]
- self.assertTrue(gl_entries)
+ self.expected_gle = [
+ {
+ "account": "_Test Bank - _TC",
+ "cost_center": cost_center,
+ },
+ {
+ "account": "_Test Cash - _TC",
+ "cost_center": cost_center,
+ },
+ ]
- for gle in gl_entries:
- self.assertEqual(expected_values[gle.account]["cost_center"], gle.cost_center)
+ self.check_gl_entries()
def test_jv_with_project(self):
from erpnext.projects.doctype.project.test_project import make_project
@@ -387,23 +377,22 @@
jv.insert()
jv.submit()
- expected_values = {
- "_Test Cash - _TC": {"project": project_name},
- "_Test Bank - _TC": {"project": project_name},
- }
+ self.voucher_no = jv.name
- gl_entries = frappe.db.sql(
- """select account, project, debit, credit
- from `tabGL Entry` where voucher_type='Journal Entry' and voucher_no=%s
- order by account asc""",
- jv.name,
- as_dict=1,
- )
+ self.fields = ["account", "project"]
- self.assertTrue(gl_entries)
+ self.expected_gle = [
+ {
+ "account": "_Test Bank - _TC",
+ "project": project_name,
+ },
+ {
+ "account": "_Test Cash - _TC",
+ "project": project_name,
+ },
+ ]
- for gle in gl_entries:
- self.assertEqual(expected_values[gle.account]["project"], gle.project)
+ self.check_gl_entries()
def test_jv_account_and_party_balance_with_cost_centre(self):
from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center
@@ -426,6 +415,86 @@
account_balance = get_balance_on(account="_Test Bank - _TC", cost_center=cost_center)
self.assertEqual(expected_account_balance, account_balance)
+ def test_repost_accounting_entries(self):
+ from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center
+
+ jv = make_journal_entry("_Test Cash - _TC", "_Test Bank - _TC", 100, save=False)
+ jv.multi_currency = 0
+ jv.submit()
+
+ self.voucher_no = jv.name
+
+ self.fields = [
+ "account",
+ "debit_in_account_currency",
+ "credit_in_account_currency",
+ "cost_center",
+ ]
+
+ self.expected_gle = [
+ {
+ "account": "_Test Bank - _TC",
+ "debit_in_account_currency": 0,
+ "credit_in_account_currency": 100,
+ "cost_center": "_Test Cost Center - _TC",
+ },
+ {
+ "account": "_Test Cash - _TC",
+ "debit_in_account_currency": 100,
+ "credit_in_account_currency": 0,
+ "cost_center": "_Test Cost Center - _TC",
+ },
+ ]
+
+ self.check_gl_entries()
+
+ cost_center = "_Test Cost Center for BS Account - _TC"
+ create_cost_center(cost_center_name="_Test Cost Center for BS Account", company="_Test Company")
+
+ jv.accounts[0].account = "_Test Bank - _TC"
+ jv.accounts[0].cost_center = "_Test Cost Center for BS Account - _TC"
+ jv.accounts[1].account = "_Test Cash - _TC"
+
+ jv.save()
+ jv.load_from_db()
+ self.assertTrue(jv.repost_required)
+ jv.repost_accounting_entries()
+
+ self.expected_gle = [
+ {
+ "account": "_Test Bank - _TC",
+ "debit_in_account_currency": 100,
+ "credit_in_account_currency": 0,
+ "cost_center": "_Test Cost Center for BS Account - _TC",
+ },
+ {
+ "account": "_Test Cash - _TC",
+ "debit_in_account_currency": 0,
+ "credit_in_account_currency": 100,
+ "cost_center": "_Test Cost Center - _TC",
+ },
+ ]
+
+ self.check_gl_entries()
+
+ def check_gl_entries(self):
+ gl = frappe.qb.DocType("GL Entry")
+ query = frappe.qb.from_(gl)
+ for field in self.fields:
+ query = query.select(gl[field])
+
+ query = query.where(
+ (gl.voucher_type == "Journal Entry")
+ & (gl.voucher_no == self.voucher_no)
+ & (gl.is_cancelled == 0)
+ ).orderby(gl.account)
+
+ gl_entries = query.run(as_dict=True)
+
+ for i in range(len(self.expected_gle)):
+ for field in self.fields:
+ self.assertEqual(self.expected_gle[i][field], gl_entries[i][field])
+
def make_journal_entry(
account1,
diff --git a/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json b/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json
index 99e66e6..6aee486 100644
--- a/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json
+++ b/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json
@@ -9,12 +9,10 @@
"field_order": [
"account",
"account_type",
- "balance",
"col_break1",
"bank_account",
"party_type",
"party",
- "party_balance",
"accounting_dimensions_section",
"cost_center",
"dimension_col_break",
@@ -41,6 +39,7 @@
],
"fields": [
{
+ "allow_on_submit": 1,
"bold": 1,
"columns": 2,
"fieldname": "account",
@@ -57,6 +56,7 @@
"width": "250px"
},
{
+ "allow_on_submit": 1,
"fieldname": "account_type",
"fieldtype": "Data",
"hidden": 1,
@@ -64,17 +64,7 @@
"print_hide": 1
},
{
- "fieldname": "balance",
- "fieldtype": "Currency",
- "label": "Account Balance",
- "no_copy": 1,
- "oldfieldname": "balance",
- "oldfieldtype": "Data",
- "options": "account_currency",
- "print_hide": 1,
- "read_only": 1
- },
- {
+ "allow_on_submit": 1,
"default": ":Company",
"description": "If Income or Expense",
"fieldname": "cost_center",
@@ -108,14 +98,6 @@
"options": "party_type"
},
{
- "fieldname": "party_balance",
- "fieldtype": "Currency",
- "label": "Party Balance",
- "options": "account_currency",
- "print_hide": 1,
- "read_only": 1
- },
- {
"fieldname": "currency_section",
"fieldtype": "Section Break",
"label": "Currency"
@@ -223,6 +205,7 @@
"no_copy": 1
},
{
+ "allow_on_submit": 1,
"fieldname": "project",
"fieldtype": "Link",
"label": "Project",
@@ -270,6 +253,7 @@
"fieldtype": "Column Break"
},
{
+ "allow_on_submit": 1,
"fieldname": "bank_account",
"fieldtype": "Link",
"label": "Bank Account",
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index c4e09b4..01821fc 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -723,6 +723,7 @@
"cash_bank_account",
"write_off_account",
"unrealized_profit_loss_account",
+ "is_opening",
]
child_tables = {"items": ("expense_account",), "taxes": ("account_head",)}
self.needs_repost = self.check_if_fields_updated(fields_to_check, child_tables)
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index c381b8a..7ce6fd0 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -722,6 +722,7 @@
"write_off_account",
"loyalty_redemption_account",
"unrealized_profit_loss_account",
+ "is_opening",
]
child_tables = {
"items": ("income_account", "expense_account", "discount_account"),
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index a0569ec..678b293 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -2414,27 +2414,20 @@
doc_before_update = self.get_doc_before_save()
accounting_dimensions = get_accounting_dimensions() + ["cost_center", "project"]
- # Check if opening entry check updated
- needs_repost = doc_before_update.get("is_opening") != self.is_opening
+ # Parent Level Accounts excluding party account
+ fields_to_check += accounting_dimensions
+ for field in fields_to_check:
+ if doc_before_update.get(field) != self.get(field):
+ return True
- if not needs_repost:
- # Parent Level Accounts excluding party account
- fields_to_check += accounting_dimensions
- for field in fields_to_check:
- if doc_before_update.get(field) != self.get(field):
- needs_repost = 1
- break
+ # Check for child tables
+ for table in child_tables:
+ if check_if_child_table_updated(
+ doc_before_update.get(table), self.get(table), child_tables[table]
+ ):
+ return True
- if not needs_repost:
- # Check for child tables
- for table in child_tables:
- needs_repost = check_if_child_table_updated(
- doc_before_update.get(table), self.get(table), child_tables[table]
- )
- if needs_repost:
- break
-
- return needs_repost
+ return False
@frappe.whitelist()
def repost_accounting_entries(self):
@@ -3463,15 +3456,12 @@
def check_if_child_table_updated(
child_table_before_update, child_table_after_update, fields_to_check
):
- accounting_dimensions = get_accounting_dimensions() + ["cost_center", "project"]
- # Check if any field affecting accounting entry is altered
- for index, item in enumerate(child_table_after_update):
- for field in fields_to_check:
- if child_table_before_update[index].get(field) != item.get(field):
- return True
+ fields_to_check = list(fields_to_check) + get_accounting_dimensions() + ["cost_center", "project"]
- for dimension in accounting_dimensions:
- if child_table_before_update[index].get(dimension) != item.get(dimension):
+ # Check if any field affecting accounting entry is altered
+ for index, item in enumerate(child_table_before_update):
+ for field in fields_to_check:
+ if child_table_after_update[index].get(field) != item.get(field):
return True
return False