Browse Source

APR 15: [FIX] Bug fixed 'hubspot_odoo_connector'

pull/331/merge
Cybrosys Technologies 2 weeks ago
parent
commit
423bf98ec1
  1. 2
      hubspot_odoo_connector/__manifest__.py
  2. 6
      hubspot_odoo_connector/doc/RELEASE_NOTES.md
  3. 38
      hubspot_odoo_connector/models/hubspot_connector.py

2
hubspot_odoo_connector/__manifest__.py

@ -21,7 +21,7 @@
############################################################################# #############################################################################
{ {
'name': 'HubSpot Odoo Connector', 'name': 'HubSpot Odoo Connector',
'version': '17.0.1.0.0', 'version': '17.0.1.0.1',
'category': 'Marketing', 'category': 'Marketing',
'summary': 'Connect Odoo With Hubspot', 'summary': 'Connect Odoo With Hubspot',
'description': """ This module integrates HubSpot with Odoo to sync 'description': """ This module integrates HubSpot with Odoo to sync

6
hubspot_odoo_connector/doc/RELEASE_NOTES.md

@ -5,3 +5,9 @@
#### ADD #### ADD
- Initial commit for HubSpot Odoo Connector - Initial commit for HubSpot Odoo Connector
#### 11.04.2024
#### Version 17.0.1.0.1
#### FIX
- Fixed the connection issue between odoo and hubspot

38
hubspot_odoo_connector/models/hubspot_connector.py

@ -26,7 +26,7 @@ from hubspot.crm.deals import BatchInputSimplePublicObjectBatchInput
from hubspot.crm.deals import SimplePublicObjectInput from hubspot.crm.deals import SimplePublicObjectInput
import requests import requests
from odoo import fields, models, _ from odoo import fields, models, _
from odoo.exceptions import AccessError from odoo.exceptions import AccessError, UserError
import pytz import pytz
@ -179,23 +179,29 @@ class HubspotConnector(models.Model):
Method for testing connection; if credentials are correct connects Method for testing connection; if credentials are correct connects
and shows sync options, if connected disconnects. and shows sync options, if connected disconnects.
""" """
if not self.connection: if not self.access_key or not self.owner_id:
owners_endpoint = 'https://api.hubapi.com/owners/v2/owners' raise UserError(_("Access key and owner ID are required"))
headers = {'Authorization': f'Bearer {self.access_key}'}
try: owners_endpoint = 'https://api.hubapi.com/crm/v3/owners'
response = requests.get(owners_endpoint, headers=headers) headers = {'Authorization': f'Bearer {self.access_key}'}
if response.status_code == 200:
data = response.json() try:
if str(data[0]['ownerId']) == self.owner_id: response = requests.get(owners_endpoint, headers=headers)
if response.status_code == 200:
data = response.json()
owners = data.get('results', [])
if not owners:
raise UserError(_("No owners found in HubSpot account"))
for owner in owners:
if str(owner['id']) == self.owner_id:
self.connection = True self.connection = True
self.state = "connected" self.state = "connected"
else: return
raise AccessError(_("Error when Fetching account info")) raise UserError(_("Owner ID does not match any HubSpot owner"))
except requests.exceptions.RequestException: else:
return None raise UserError(_("Failed to connect to HubSpot: %s") % response.text)
else: except requests.exceptions.RequestException as e:
self.connection = False raise UserError(_("Network error connecting to HubSpot: %s") % str(e))
self.state = "disconnected"
def action_contact_sync(self): def action_contact_sync(self):
""" """

Loading…
Cancel
Save