From 15633907be146e5cddebbc0b95152e785d12bc1d Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Sat, 29 Jun 2019 14:23:33 +0530 Subject: [PATCH] feat: refactor GMaps --- frappe/config/integrations.py | 4 +- .../doctype/google_maps/google_maps.json | 38 +++++++++++++++---- .../doctype/google_maps/google_maps.py | 15 +++++--- .../google_settings/google_settings.json | 10 ++++- .../v12_0/delete_google_maps_integration.py | 6 +++ 5 files changed, 56 insertions(+), 17 deletions(-) create mode 100644 frappe/patches/v12_0/delete_google_maps_integration.py diff --git a/frappe/config/integrations.py b/frappe/config/integrations.py index ce71051c1d..1472b3ae58 100644 --- a/frappe/config/integrations.py +++ b/frappe/config/integrations.py @@ -94,8 +94,8 @@ def get_data(): }, { "type": "doctype", - "name": "Google Maps Settings", - "description": _("Google Maps integration"), + "name": "Google Maps", + "description": _("Google Maps Integration"), }, { "type": "doctype", diff --git a/frappe/integrations/doctype/google_maps/google_maps.json b/frappe/integrations/doctype/google_maps/google_maps.json index 536dbcd9ba..ef9fd10a0e 100644 --- a/frappe/integrations/doctype/google_maps/google_maps.json +++ b/frappe/integrations/doctype/google_maps/google_maps.json @@ -1,22 +1,46 @@ { - "creation": "2019-06-28 23:49:38.545917", + "autoname": "format:GM-{entity}", + "creation": "2019-06-29 13:03:45.935466", "doctype": "DocType", "editable_grid": 1, "engine": "InnoDB", "field_order": [ - "enable" + "enabled", + "entity_type", + "address", + "cb_00", + "entity" ], "fields": [ { "default": "0", - "description": "Google Maps integration is used to optimize routes.", - "fieldname": "enable", + "fieldname": "enabled", "fieldtype": "Check", - "label": "Enable" + "label": "Enabled" + }, + { + "fieldname": "entity_type", + "fieldtype": "Select", + "label": "Entity Type" + }, + { + "fieldname": "address", + "fieldtype": "Link", + "label": "Address", + "options": "Address" + }, + { + "fieldname": "cb_00", + "fieldtype": "Column Break" + }, + { + "fieldname": "entity", + "fieldtype": "Dynamic Link", + "label": "Entity", + "options": "entity_type" } ], - "issingle": 1, - "modified": "2019-06-28 23:49:38.545917", + "modified": "2019-06-29 13:23:16.714233", "modified_by": "Administrator", "module": "Integrations", "name": "Google Maps", diff --git a/frappe/integrations/doctype/google_maps/google_maps.py b/frappe/integrations/doctype/google_maps/google_maps.py index a29d6062d2..991fdea048 100644 --- a/frappe/integrations/doctype/google_maps/google_maps.py +++ b/frappe/integrations/doctype/google_maps/google_maps.py @@ -8,18 +8,21 @@ from frappe.model.document import Document class GoogleMaps(Document): def validate(self): - if self.enable and not frappe.db.get_single_value("Google Settings", "enable"): - frappe.throw(_("Enable Google API in Google Settings.")) + if self.enabled: + if not frappe.db.get_single_value("Google Settings", "enable"): + frappe.throw(_("Enable Google Settings for Google Maps Integration.")) + + if not frappe.db.get_single_value("Google Settings", "api_key"): + frappe.throw(_("Enter API Key for Google Maps Integration in Google Settings.")) def get_client(self): - if not self.enable: - frappe.throw(_("Google Maps integration is not enabled")) + if not self.enabled: + frappe.throw(_("Google Maps Integration is not enabled.")) import googlemaps try: - client_id = frappe.db.get_single_value("Google Settings", "client_id") - client = googlemaps.Client(key=client_id) + client = googlemaps.Client(key=frappe.db.get_single_value("Google Settings", "api_key")) except Exception as e: frappe.throw(e.message) diff --git a/frappe/integrations/doctype/google_settings/google_settings.json b/frappe/integrations/doctype/google_settings/google_settings.json index c61d6606b5..8a316fd67e 100644 --- a/frappe/integrations/doctype/google_settings/google_settings.json +++ b/frappe/integrations/doctype/google_settings/google_settings.json @@ -6,7 +6,8 @@ "enable", "google_credentials", "client_id", - "client_secret" + "client_secret", + "api_key" ], "fields": [ { @@ -32,10 +33,15 @@ "fieldtype": "Password", "in_list_view": 1, "label": "Client Secret" + }, + { + "fieldname": "api_key", + "fieldtype": "Data", + "label": "API Key" } ], "issingle": 1, - "modified": "2019-06-19 15:28:05.957380", + "modified": "2019-06-29 13:26:33.201060", "modified_by": "Administrator", "module": "Integrations", "name": "Google Settings", diff --git a/frappe/patches/v12_0/delete_google_maps_integration.py b/frappe/patches/v12_0/delete_google_maps_integration.py new file mode 100644 index 0000000000..39e3590477 --- /dev/null +++ b/frappe/patches/v12_0/delete_google_maps_integration.py @@ -0,0 +1,6 @@ +import frappe + +def execute(): + key = frappe.db.get_single_value("Google Maps Settings", "client_key") + frappe.db.set_value("Google Settings", None, "api_key", key) + frappe.db.commit() \ No newline at end of file