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
This commit is contained in:
parent
6de526ff42
commit
c5c3860c5c
@ -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)
|
||||
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user