From c5c3860c5c05edfe2d2fb7edc3899f9453bd948c Mon Sep 17 00:00:00 2001 From: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> Date: Tue, 17 Sep 2019 12:50:28 +0530 Subject: [PATCH] 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 --- .../accounting_dimension.py | 2 +- erpnext/assets/doctype/asset/depreciation.py | 26 ++++++++++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py index 59d7557b2ad..af51fc5d8e5 100644 --- a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py +++ b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py @@ -174,7 +174,7 @@ def get_accounting_dimensions(as_list=True): 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 a9d3a48a18f..e911e809c22 100644 --- a/erpnext/assets/doctype/asset/depreciation.py +++ b/erpnext/assets/doctype/asset/depreciation.py @@ -6,6 +6,7 @@ from __future__ import unicode_literals 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 @@ def make_depreciation_entry(asset_name, date=None): 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 @@ def make_depreciation_entry(asset_name, date=None): 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()