From 3a389788bfa43e0cad34bc3a85d62860fff22e76 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 7 Jul 2014 12:19:43 +0530 Subject: [PATCH] BugFix: Maintenance Visit against Customer Issue + Map Item details from Customer Issue into Maintenance Visit Purpose Table + Map Prev DocType and Prev DocName + Changed prevdoc_doctype and prevdoc_docname into Dynamic Link --- .../customer_issue/customer_issue.json | 3 +- .../doctype/customer_issue/customer_issue.py | 18 ++++++-- .../maintenance_visit_purpose.json | 41 ++++++++++--------- 3 files changed, 39 insertions(+), 23 deletions(-) diff --git a/erpnext/support/doctype/customer_issue/customer_issue.json b/erpnext/support/doctype/customer_issue/customer_issue.json index b755135b73..669ea5dba2 100644 --- a/erpnext/support/doctype/customer_issue/customer_issue.json +++ b/erpnext/support/doctype/customer_issue/customer_issue.json @@ -202,6 +202,7 @@ { "fieldname": "resolved_by", "fieldtype": "Link", + "ignore_user_permissions": 1, "in_filter": 1, "label": "Resolved By", "no_copy": 1, @@ -395,7 +396,7 @@ "icon": "icon-bug", "idx": 1, "is_submittable": 0, - "modified": "2014-06-23 07:55:47.488335", + "modified": "2014-07-07 02:47:56.491906", "modified_by": "Administrator", "module": "Support", "name": "Customer Issue", diff --git a/erpnext/support/doctype/customer_issue/customer_issue.py b/erpnext/support/doctype/customer_issue/customer_issue.py index 290e74e263..d6d65966fe 100644 --- a/erpnext/support/doctype/customer_issue/customer_issue.py +++ b/erpnext/support/doctype/customer_issue/customer_issue.py @@ -38,7 +38,11 @@ class CustomerIssue(TransactionBase): @frappe.whitelist() def make_maintenance_visit(source_name, target_doc=None): - from frappe.model.mapper import get_mapped_doc + from frappe.model.mapper import get_mapped_doc, map_child_doc + + def _update_links(source_doc, target_doc, source_parent): + target_doc.prevdoc_doctype = source_parent.doctype + target_doc.prevdoc_docname = source_parent.name visit = frappe.db.sql("""select t1.name from `tabMaintenance Visit` t1, `tabMaintenance Visit Purpose` t2 @@ -46,7 +50,7 @@ def make_maintenance_visit(source_name, target_doc=None): and t1.docstatus=1 and t1.completion_status='Fully Completed'""", source_name) if not visit: - doclist = get_mapped_doc("Customer Issue", source_name, { + target_doc = get_mapped_doc("Customer Issue", source_name, { "Customer Issue": { "doctype": "Maintenance Visit", "field_map": { @@ -57,4 +61,12 @@ def make_maintenance_visit(source_name, target_doc=None): } }, target_doc) - return doclist + source_doc = frappe.get_doc("Customer Issue", source_name) + if source_doc.get("item_code"): + table_map = { + "doctype": "Maintenance Visit Purpose", + "postprocess": _update_links + } + map_child_doc(source_doc, target_doc, table_map, source_doc) + + return target_doc diff --git a/erpnext/support/doctype/maintenance_visit_purpose/maintenance_visit_purpose.json b/erpnext/support/doctype/maintenance_visit_purpose/maintenance_visit_purpose.json index 32e3769b7c..8e98397bd3 100644 --- a/erpnext/support/doctype/maintenance_visit_purpose/maintenance_visit_purpose.json +++ b/erpnext/support/doctype/maintenance_visit_purpose/maintenance_visit_purpose.json @@ -1,6 +1,6 @@ { "autoname": "MVD.#####", - "creation": "2013-02-22 01:28:06.000000", + "creation": "2013-02-22 01:28:06", "docstatus": 0, "doctype": "DocType", "fields": [ @@ -73,14 +73,31 @@ "permlevel": 0, "reqd": 1 }, + { + "fieldname": "prevdoc_doctype", + "fieldtype": "Link", + "hidden": 0, + "label": "Document Type", + "no_copy": 1, + "oldfieldname": "prevdoc_doctype", + "oldfieldtype": "Data", + "options": "DocType", + "permlevel": 0, + "print_hide": 1, + "print_width": "150px", + "read_only": 1, + "report_hide": 1, + "width": "150px" + }, { "fieldname": "prevdoc_docname", - "fieldtype": "Data", + "fieldtype": "Dynamic Link", "hidden": 0, "label": "Against Document No", "no_copy": 1, "oldfieldname": "prevdoc_docname", "oldfieldtype": "Data", + "options": "prevdoc_doctype", "permlevel": 0, "print_hide": 1, "print_width": "160px", @@ -102,28 +119,14 @@ "read_only": 1, "report_hide": 1, "width": "160px" - }, - { - "fieldname": "prevdoc_doctype", - "fieldtype": "Data", - "hidden": 0, - "label": "Document Type", - "no_copy": 1, - "oldfieldname": "prevdoc_doctype", - "oldfieldtype": "Data", - "permlevel": 0, - "print_hide": 1, - "print_width": "150px", - "read_only": 1, - "report_hide": 1, - "width": "150px" } ], "idx": 1, "istable": 1, - "modified": "2013-12-20 19:23:20.000000", + "modified": "2014-07-07 02:53:48.442249", "modified_by": "Administrator", "module": "Support", "name": "Maintenance Visit Purpose", - "owner": "ashwini@webnotestech.com" + "owner": "ashwini@webnotestech.com", + "permissions": [] } \ No newline at end of file