fix: Mandatory accounting dimensions while creating asset depreciation entry (#19073)
* fix: Mandatory accounting dimensions while creating asset depreciation entry
* fix: Consider account types while assigning accounting dimensions
diff --git a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py
index 59d7557..af51fc5 100644
--- a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py
+++ b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py
@@ -174,7 +174,7 @@
return accounting_dimensions
def get_checks_for_pl_and_bs_accounts():
- dimensions = frappe.db.sql("""SELECT p.label, p.disabled, p.fieldname, c.company, c.mandatory_for_pl, c.mandatory_for_bs
+ dimensions = frappe.db.sql("""SELECT p.label, p.disabled, p.fieldname, c.default_dimension, c.company, c.mandatory_for_pl, c.mandatory_for_bs
FROM `tabAccounting Dimension`p ,`tabAccounting Dimension Detail` c
WHERE p.name = c.parent""", as_dict=1)
diff --git a/erpnext/assets/doctype/asset/depreciation.py b/erpnext/assets/doctype/asset/depreciation.py
index a9d3a48..e911e80 100644
--- a/erpnext/assets/doctype/asset/depreciation.py
+++ b/erpnext/assets/doctype/asset/depreciation.py
@@ -6,6 +6,7 @@
import frappe
from frappe import _
from frappe.utils import flt, today, getdate, cint
+from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_checks_for_pl_and_bs_accounts
def post_depreciation_entries(date=None):
# Return if automatic booking of asset depreciation is disabled
@@ -41,6 +42,8 @@
depreciation_cost_center = asset.cost_center or depreciation_cost_center
+ accounting_dimensions = get_checks_for_pl_and_bs_accounts()
+
for d in asset.get("schedules"):
if not d.journal_entry and getdate(d.schedule_date) <= getdate(date):
je = frappe.new_doc("Journal Entry")
@@ -51,20 +54,35 @@
je.finance_book = d.finance_book
je.remark = "Depreciation Entry against {0} worth {1}".format(asset_name, d.depreciation_amount)
- je.append("accounts", {
+ credit_entry = {
"account": accumulated_depreciation_account,
"credit_in_account_currency": d.depreciation_amount,
"reference_type": "Asset",
"reference_name": asset.name
- })
+ }
- je.append("accounts", {
+ debit_entry = {
"account": depreciation_expense_account,
"debit_in_account_currency": d.depreciation_amount,
"reference_type": "Asset",
"reference_name": asset.name,
"cost_center": depreciation_cost_center
- })
+ }
+
+ for dimension in accounting_dimensions:
+ if (asset.get(dimension['fieldname']) or dimension.get('mandatory_for_bs')):
+ credit_entry.update({
+ dimension['fieldname']: asset.get(dimension['fieldname']) or dimension.get('default_dimension')
+ })
+
+ if (asset.get(dimension['fieldname']) or dimension.get('mandatory_for_pl')):
+ debit_entry.update({
+ dimension['fieldname']: asset.get(dimension['fieldname']) or dimension.get('default_dimension')
+ })
+
+ je.append("accounts", credit_entry)
+
+ je.append("accounts", debit_entry)
je.flags.ignore_permissions = True
je.save()