From fe891aa4889edc131f2622d1400339576d6b5575 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 30 Sep 2022 15:55:41 +0530 Subject: [PATCH] fix: Create accounting dimension fields in asset capitalization --- erpnext/hooks.py | 1 + erpnext/patches.txt | 1 + ...ing_dimensions_for_asset_capitalization.py | 31 +++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 erpnext/patches/v14_0/create_accounting_dimensions_for_asset_capitalization.py diff --git a/erpnext/hooks.py b/erpnext/hooks.py index 6ef77f3f5b..b8f51f839c 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -508,6 +508,7 @@ accounting_dimension_doctypes = [ "Landed Cost Item", "Asset Value Adjustment", "Asset Repair", + "Asset Capitalization", "Loyalty Program", "Stock Reconciliation", "POS Profile", diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 2a0ca8c496..fc63f124e1 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -315,3 +315,4 @@ erpnext.patches.v14_0.fix_crm_no_of_employees erpnext.patches.v14_0.create_accounting_dimensions_in_subcontracting_doctypes erpnext.patches.v14_0.fix_subcontracting_receipt_gl_entries erpnext.patches.v14_0.migrate_remarks_from_gl_to_payment_ledger +erpnext.patches.v14_0.create_accounting_dimensions_for_asset_capitalization diff --git a/erpnext/patches/v14_0/create_accounting_dimensions_for_asset_capitalization.py b/erpnext/patches/v14_0/create_accounting_dimensions_for_asset_capitalization.py new file mode 100644 index 0000000000..09e20a9d79 --- /dev/null +++ b/erpnext/patches/v14_0/create_accounting_dimensions_for_asset_capitalization.py @@ -0,0 +1,31 @@ +import frappe +from frappe.custom.doctype.custom_field.custom_field import create_custom_field + + +def execute(): + accounting_dimensions = frappe.db.get_all( + "Accounting Dimension", fields=["fieldname", "label", "document_type", "disabled"] + ) + + if not accounting_dimensions: + return + + doctype = "Asset Capitalization" + + for d in accounting_dimensions: + field = frappe.db.get_value("Custom Field", {"dt": doctype, "fieldname": d.fieldname}) + + if field: + continue + + df = { + "fieldname": d.fieldname, + "label": d.label, + "fieldtype": "Link", + "options": d.document_type, + "insert_after": "accounting_dimensions_section", + } + + create_custom_field(doctype, df, ignore_validate=True) + + frappe.clear_cache(doctype=doctype)