[enhance] Add Issue Type and Opportunity Type masters (#11598)

* [enhance] added & linked Issue Type & Opportunity Type with opportunity

* [patch] create issue and opportunity type from the custom field if available

* [minor] issue_type and opportunity type should be mandatory

* [patches] removed try catch from the patch

* [fix] patch

* [refactor] cleanup issue/opportunity type
This commit is contained in:
Rushabh Mehta
2017-11-16 17:03:52 +05:30
committed by GitHub
parent 46be9896a9
commit a5ebebd09c
27 changed files with 522 additions and 81 deletions

View File

View File

@@ -0,0 +1,34 @@
# Copyright (c) 2017, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
from frappe import _
def execute():
# delete custom field if exists
for fieldname in ('issue_type', 'opportunity_type'):
custom_field = frappe.db.get_value("Custom Field", {"fieldname": fieldname})
if custom_field:
frappe.delete_doc("Custom Field", custom_field, ignore_permissions=True)
frappe.reload_doc('support', 'doctype', 'issue_type')
frappe.reload_doc('support', 'doctype', 'issue')
frappe.reload_doc('crm', 'doctype', 'opportunity_type')
frappe.reload_doc('crm', 'doctype', 'opportunity')
# rename enquiry_type -> opportunity_type
from frappe.model.utils.rename_field import rename_field
rename_field('Opportunity', 'enquiry_type', 'opportunity_type')
# create values if already set
for opts in (('Issue', 'issue_type', 'Issue Type'),
('Opportunity', 'opportunity_type', 'Opportunity Type')):
for d in frappe.db.sql('select distinct {0} from `tab{1}`'.format(opts[1], opts[0])):
if not frappe.db.exists(opts[2], d[0]):
frappe.get_doc(dict(doctype = opts[2], name=d[0])).insert()
# fixtures
for name in ('Hub', _('Sales'), _('Support'), _('Maintenance')):
if not frappe.db.exists('Opportunity', name):
frappe.get_doc(dict(doctype = 'Opportunity Type', name=name)).insert()