
from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.model.document import Document
import googlemaps
import datetime

class GoogleMapsSettings(Document):
	def validate(self):
		if self.enabled:
			if not self.client_key:
				frappe.throw(_("Client key is required"))
			if not self.home_address:
				frappe.throw(_("Home Address is required"))

	def get_client(self):
		try:
			client = googlemaps.Client(key=self.client_key)
		except Exception as e:
			frappe.throw(e.message)

		return client


from __future__ import unicode_literals

import googlemaps

import frappe
from frappe import _
from frappe.model.document import Document


class GoogleMapsSettings(Document):
	def validate(self):
		if self.enabled:
			if not self.client_key:
				frappe.throw(_("Client key is required"))
			if not self.home_address:
				frappe.throw(_("Home Address is required"))

	def get_client(self):
		if not self.enabled:
			frappe.throw(_("Google Maps integration is not enabled"))

		try:
			client = googlemaps.Client(key=self.client_key)
		except Exception as e:
			frappe.throw(e.message)

		return client

Check if Google Maps is enabled when trying to get the client
Check if Google Maps is enabled when trying to get the client

  
  from __future__ import unicode_literals
+ 
+ import googlemaps
+ 
  import frappe
  from frappe import _
  from frappe.model.document import Document
+ 
- import googlemaps
- import datetime
  
  class GoogleMapsSettings(Document):
  	def validate(self):
  		if self.enabled:
  			if not self.client_key:
  				frappe.throw(_("Client key is required"))
  			if not self.home_address:
  				frappe.throw(_("Home Address is required"))
  
  	def get_client(self):
+ 		if not self.enabled:
+ 			frappe.throw(_("Google Maps integration is not enabled"))
+ 
  		try:
  			client = googlemaps.Client(key=self.client_key)
  		except Exception as e:
  			frappe.throw(e.message)
  
  		return client
  
Check if Google Maps is enabled when trying to get the client
## Code Before:

from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.model.document import Document
import googlemaps
import datetime

class GoogleMapsSettings(Document):
	def validate(self):
		if self.enabled:
			if not self.client_key:
				frappe.throw(_("Client key is required"))
			if not self.home_address:
				frappe.throw(_("Home Address is required"))

	def get_client(self):
		try:
			client = googlemaps.Client(key=self.client_key)
		except Exception as e:
			frappe.throw(e.message)

		return client

## Instruction:
Check if Google Maps is enabled when trying to get the client
## Code After:

from __future__ import unicode_literals

import googlemaps

import frappe
from frappe import _
from frappe.model.document import Document


class GoogleMapsSettings(Document):
	def validate(self):
		if self.enabled:
			if not self.client_key:
				frappe.throw(_("Client key is required"))
			if not self.home_address:
				frappe.throw(_("Home Address is required"))

	def get_client(self):
		if not self.enabled:
			frappe.throw(_("Google Maps integration is not enabled"))

		try:
			client = googlemaps.Client(key=self.client_key)
		except Exception as e:
			frappe.throw(e.message)

		return client
