fix: Add dimension section in subcontracting doctypes (#31849)
diff --git a/erpnext/hooks.py b/erpnext/hooks.py
index c4f0c59..a08feb4 100644
--- a/erpnext/hooks.py
+++ b/erpnext/hooks.py
@@ -520,6 +520,10 @@
"Purchase Order",
"Purchase Receipt",
"Sales Order",
+ "Subcontracting Order",
+ "Subcontracting Order Item",
+ "Subcontracting Receipt",
+ "Subcontracting Receipt Item",
]
# get matching queries for Bank Reconciliation
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index e5beacd..d92353a 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -310,4 +310,5 @@
erpnext.patches.v14_0.remove_india_localisation # 14-07-2022
erpnext.patches.v13_0.fix_number_and_frequency_for_monthly_depreciation
erpnext.patches.v14_0.remove_hr_and_payroll_modules # 20-07-2022
-erpnext.patches.v14_0.fix_crm_no_of_employees
\ No newline at end of file
+erpnext.patches.v14_0.fix_crm_no_of_employees
+erpnext.patches.v14_0.create_accounting_dimensions_in_subcontracting_doctypes
\ No newline at end of file
diff --git a/erpnext/patches/v14_0/create_accounting_dimensions_in_subcontracting_doctypes.py b/erpnext/patches/v14_0/create_accounting_dimensions_in_subcontracting_doctypes.py
new file mode 100644
index 0000000..b349c07
--- /dev/null
+++ b/erpnext/patches/v14_0/create_accounting_dimensions_in_subcontracting_doctypes.py
@@ -0,0 +1,47 @@
+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
+
+ count = 1
+ for d in accounting_dimensions:
+
+ if count % 2 == 0:
+ insert_after_field = "dimension_col_break"
+ else:
+ insert_after_field = "accounting_dimensions_section"
+
+ for doctype in [
+ "Subcontracting Order",
+ "Subcontracting Order Item",
+ "Subcontracting Receipt",
+ "Subcontracting Receipt Item",
+ ]:
+
+ 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": insert_after_field,
+ }
+
+ try:
+ create_custom_field(doctype, df, ignore_validate=True)
+ frappe.clear_cache(doctype=doctype)
+ except Exception:
+ pass
+
+ count += 1
diff --git a/erpnext/subcontracting/doctype/subcontracting_order/subcontracting_order.json b/erpnext/subcontracting/doctype/subcontracting_order/subcontracting_order.json
index c6e76c7..f98f559 100644
--- a/erpnext/subcontracting/doctype/subcontracting_order/subcontracting_order.json
+++ b/erpnext/subcontracting/doctype/subcontracting_order/subcontracting_order.json
@@ -19,6 +19,10 @@
"transaction_date",
"schedule_date",
"amended_from",
+ "accounting_dimensions_section",
+ "cost_center",
+ "dimension_col_break",
+ "project",
"address_and_contact_section",
"supplier_address",
"address_display",
@@ -422,12 +426,34 @@
"fieldtype": "Select",
"label": "Distribute Additional Costs Based On ",
"options": "Qty\nAmount"
+ },
+ {
+ "collapsible": 1,
+ "fieldname": "accounting_dimensions_section",
+ "fieldtype": "Section Break",
+ "label": "Accounting Dimensions"
+ },
+ {
+ "fieldname": "cost_center",
+ "fieldtype": "Link",
+ "label": "Cost Center",
+ "options": "Cost Center"
+ },
+ {
+ "fieldname": "dimension_col_break",
+ "fieldtype": "Column Break"
+ },
+ {
+ "fieldname": "project",
+ "fieldtype": "Link",
+ "label": "Project",
+ "options": "Project"
}
],
"icon": "fa fa-file-text",
"is_submittable": 1,
"links": [],
- "modified": "2022-04-11 21:02:44.097841",
+ "modified": "2022-08-15 14:08:49.204218",
"modified_by": "Administrator",
"module": "Subcontracting",
"name": "Subcontracting Order",
diff --git a/erpnext/subcontracting/doctype/subcontracting_order_item/subcontracting_order_item.json b/erpnext/subcontracting/doctype/subcontracting_order_item/subcontracting_order_item.json
index 291f47a..3675a4e 100644
--- a/erpnext/subcontracting/doctype/subcontracting_order_item/subcontracting_order_item.json
+++ b/erpnext/subcontracting/doctype/subcontracting_order_item/subcontracting_order_item.json
@@ -40,6 +40,10 @@
"manufacture_section",
"manufacturer",
"manufacturer_part_no",
+ "accounting_dimensions_section",
+ "cost_center",
+ "dimension_col_break",
+ "project",
"section_break_34",
"page_break"
],
@@ -304,13 +308,35 @@
"no_copy": 1,
"print_hide": 1,
"read_only": 1
+ },
+ {
+ "collapsible": 1,
+ "fieldname": "accounting_dimensions_section",
+ "fieldtype": "Section Break",
+ "label": "Accounting Dimensions"
+ },
+ {
+ "fieldname": "cost_center",
+ "fieldtype": "Link",
+ "label": "Cost Center",
+ "options": "Cost Center"
+ },
+ {
+ "fieldname": "dimension_col_break",
+ "fieldtype": "Column Break"
+ },
+ {
+ "fieldname": "project",
+ "fieldtype": "Link",
+ "label": "Project",
+ "options": "Project"
}
],
"idx": 1,
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
- "modified": "2022-04-11 21:28:06.585338",
+ "modified": "2022-08-15 14:25:45.177703",
"modified_by": "Administrator",
"module": "Subcontracting",
"name": "Subcontracting Order Item",
diff --git a/erpnext/subcontracting/doctype/subcontracting_receipt/subcontracting_receipt.json b/erpnext/subcontracting/doctype/subcontracting_receipt/subcontracting_receipt.json
index e963814..9430486 100644
--- a/erpnext/subcontracting/doctype/subcontracting_receipt/subcontracting_receipt.json
+++ b/erpnext/subcontracting/doctype/subcontracting_receipt/subcontracting_receipt.json
@@ -17,6 +17,10 @@
"posting_time",
"is_return",
"return_against",
+ "accounting_dimensions_section",
+ "cost_center",
+ "dimension_col_break",
+ "project",
"section_addresses",
"supplier_address",
"contact_person",
@@ -569,11 +573,33 @@
{
"fieldname": "section_break_47",
"fieldtype": "Section Break"
+ },
+ {
+ "collapsible": 1,
+ "fieldname": "accounting_dimensions_section",
+ "fieldtype": "Section Break",
+ "label": "Accounting Dimensions "
+ },
+ {
+ "fieldname": "cost_center",
+ "fieldtype": "Link",
+ "label": "Cost Center",
+ "options": "Cost Center"
+ },
+ {
+ "fieldname": "dimension_col_break",
+ "fieldtype": "Column Break"
+ },
+ {
+ "fieldname": "project",
+ "fieldtype": "Link",
+ "label": "Project",
+ "options": "Project"
}
],
"is_submittable": 1,
"links": [],
- "modified": "2022-04-18 13:15:12.011682",
+ "modified": "2022-08-15 14:30:29.447307",
"modified_by": "Administrator",
"module": "Subcontracting",
"name": "Subcontracting Receipt",
diff --git a/erpnext/subcontracting/doctype/subcontracting_receipt_item/subcontracting_receipt_item.json b/erpnext/subcontracting/doctype/subcontracting_receipt_item/subcontracting_receipt_item.json
index bf15f0f..437fc41 100644
--- a/erpnext/subcontracting/doctype/subcontracting_receipt_item/subcontracting_receipt_item.json
+++ b/erpnext/subcontracting/doctype/subcontracting_receipt_item/subcontracting_receipt_item.json
@@ -56,9 +56,9 @@
"accounting_details_section",
"expense_account",
"accounting_dimensions_section",
- "project",
- "dimension_col_break",
"cost_center",
+ "dimension_col_break",
+ "project",
"section_break_80",
"page_break"
],
@@ -465,7 +465,7 @@
"idx": 1,
"istable": 1,
"links": [],
- "modified": "2022-08-15 11:34:00.970042",
+ "modified": "2022-08-15 14:51:10.613347",
"modified_by": "Administrator",
"module": "Subcontracting",
"name": "Subcontracting Receipt Item",