@@ -95,7 +95,7 @@ def create_lead(self, user: FFAdminUser, organisation: Organisation) -> None:
9595 hubspot_contact_id = self ._get_or_create_user_hubspot_id (user )
9696 if not hubspot_contact_id :
9797 return
98- hubspot_org_id = self ._get_or_create_organisation_hubspot_id (user , organisation )
98+ hubspot_org_id = self ._get_organisation_hubspot_id (user , organisation )
9999 if not hubspot_org_id :
100100 return
101101
@@ -134,7 +134,7 @@ def _get_or_create_user_hubspot_id(self, user: FFAdminUser) -> str | None:
134134
135135 return hubspot_contact_id
136136
137- def _get_or_create_organisation_hubspot_id (
137+ def _get_organisation_hubspot_id (
138138 self ,
139139 user : FFAdminUser ,
140140 organisation : Organisation ,
@@ -154,10 +154,12 @@ def _get_or_create_organisation_hubspot_id(
154154 company_kwargs ["organisation_id" ] = organisation .id
155155 company_kwargs ["active_subscription" ] = organisation .subscription .plan
156156
157- # As Hubspot creates/associates companies based on contact domain
157+ # As Hubspot creates/associates companies automatically based on contact domain
158158 # we need to get the hubspot id when this user creates the company for the first time
159159 # and update the company name
160- company = self ._get_or_create_hubspot_company (** company_kwargs )
160+ company = self ._get_hubspot_company_by_domain (domain )
161+ if not company :
162+ return None
161163 org_hubspot_id : str = company ["id" ]
162164
163165 properties = company .get ("properties" , {})
@@ -177,21 +179,11 @@ def _get_or_create_organisation_hubspot_id(
177179
178180 return org_hubspot_id
179181
180- def _get_or_create_hubspot_company (
182+ def _get_hubspot_company_by_domain (
181183 self ,
182184 domain : str ,
183- organisation_id : int ,
184- name : str ,
185- active_subscription : str | None = None ,
186185 ) -> dict [str , Any ]:
187186 company = self .client .get_company_by_domain (domain )
188- if not company :
189- company = self .client .create_company (
190- name = name ,
191- domain = domain ,
192- organisation_id = organisation_id ,
193- active_subscription = active_subscription ,
194- )
195187
196188 return company # type: ignore[no-any-return]
197189
0 commit comments