From 423bf98ec151d20cfaabd22286a271620afb72d0 Mon Sep 17 00:00:00 2001 From: Cybrosys Technologies Date: Tue, 15 Apr 2025 11:01:58 +0530 Subject: [PATCH] APR 15: [FIX] Bug fixed 'hubspot_odoo_connector' --- hubspot_odoo_connector/__manifest__.py | 2 +- hubspot_odoo_connector/doc/RELEASE_NOTES.md | 6 +++ .../models/hubspot_connector.py | 38 +++++++++++-------- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/hubspot_odoo_connector/__manifest__.py b/hubspot_odoo_connector/__manifest__.py index b8d466840..26d3c6485 100644 --- a/hubspot_odoo_connector/__manifest__.py +++ b/hubspot_odoo_connector/__manifest__.py @@ -21,7 +21,7 @@ ############################################################################# { 'name': 'HubSpot Odoo Connector', - 'version': '17.0.1.0.0', + 'version': '17.0.1.0.1', 'category': 'Marketing', 'summary': 'Connect Odoo With Hubspot', 'description': """ This module integrates HubSpot with Odoo to sync diff --git a/hubspot_odoo_connector/doc/RELEASE_NOTES.md b/hubspot_odoo_connector/doc/RELEASE_NOTES.md index 8e0ce08b3..9f0f36adc 100644 --- a/hubspot_odoo_connector/doc/RELEASE_NOTES.md +++ b/hubspot_odoo_connector/doc/RELEASE_NOTES.md @@ -5,3 +5,9 @@ #### ADD - Initial commit for HubSpot Odoo Connector + +#### 11.04.2024 +#### Version 17.0.1.0.1 +#### FIX + +- Fixed the connection issue between odoo and hubspot \ No newline at end of file diff --git a/hubspot_odoo_connector/models/hubspot_connector.py b/hubspot_odoo_connector/models/hubspot_connector.py index 8a24df3fe..169af4425 100644 --- a/hubspot_odoo_connector/models/hubspot_connector.py +++ b/hubspot_odoo_connector/models/hubspot_connector.py @@ -26,7 +26,7 @@ from hubspot.crm.deals import BatchInputSimplePublicObjectBatchInput from hubspot.crm.deals import SimplePublicObjectInput import requests from odoo import fields, models, _ -from odoo.exceptions import AccessError +from odoo.exceptions import AccessError, UserError import pytz @@ -179,23 +179,29 @@ class HubspotConnector(models.Model): Method for testing connection; if credentials are correct connects and shows sync options, if connected disconnects. """ - if not self.connection: - owners_endpoint = 'https://api.hubapi.com/owners/v2/owners' - headers = {'Authorization': f'Bearer {self.access_key}'} - try: - response = requests.get(owners_endpoint, headers=headers) - if response.status_code == 200: - data = response.json() - if str(data[0]['ownerId']) == self.owner_id: + if not self.access_key or not self.owner_id: + raise UserError(_("Access key and owner ID are required")) + + owners_endpoint = 'https://api.hubapi.com/crm/v3/owners' + headers = {'Authorization': f'Bearer {self.access_key}'} + + try: + 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.state = "connected" - else: - raise AccessError(_("Error when Fetching account info")) - except requests.exceptions.RequestException: - return None - else: - self.connection = False - self.state = "disconnected" + return + raise UserError(_("Owner ID does not match any HubSpot owner")) + else: + raise UserError(_("Failed to connect to HubSpot: %s") % response.text) + except requests.exceptions.RequestException as e: + raise UserError(_("Network error connecting to HubSpot: %s") % str(e)) def action_contact_sync(self): """