From 50ad61245350879b564e203276a8c91a062a19bb Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 18 Aug 2022 12:04:07 +0530 Subject: [PATCH] fix: Add dimension section in subcontracting doctypes (backport #31849) (#31877) * fix: Add dimension section in subcontracting doctypes (#31849) (cherry picked from commit 8704ca783d3f3280113d11444baa8acfeb78c2a3) # Conflicts: # erpnext/patches.txt * chore: conflicts Co-authored-by: Sagar Sharma --- erpnext/hooks.py | 4 ++ erpnext/patches.txt | 3 +- ...g_dimensions_in_subcontracting_doctypes.py | 47 +++++++++++++++++++ .../subcontracting_order.json | 28 ++++++++++- .../subcontracting_order_item.json | 28 ++++++++++- .../subcontracting_receipt.json | 28 ++++++++++- .../subcontracting_receipt_item.json | 6 +-- 7 files changed, 137 insertions(+), 7 deletions(-) create mode 100644 erpnext/patches/v14_0/create_accounting_dimensions_in_subcontracting_doctypes.py diff --git a/erpnext/hooks.py b/erpnext/hooks.py index c4f0c59c3869..a08feb44476d 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 c7dc27e2944e..6d1f37a9fafa 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -309,4 +309,5 @@ erpnext.patches.v14_0.migrate_gl_to_payment_ledger erpnext.patches.v14_0.crm_ux_cleanup 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 \ No newline at end of file +erpnext.patches.v14_0.remove_hr_and_payroll_modules # 20-07-2022 +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 000000000000..b349c07f6df2 --- /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 c6e76c76d762..f98f559d5cab 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 291f47a6340c..3675a4ea08a3 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 e9638144a797..94304865603f 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 bf15f0f6882d..437fc41f5e43 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",