+
    i                     L    ^ RI t ^ RIt^ RIt^ RIHt ]! 4         ! R R4      tR# )    N)load_dotenvc                      a  ] tR t^t o R tR tR tR tR tR t	R t
R tR	 tR
 tR tR tR tR tR tR tR tRtV tR# )BusinessCentralServicec                   \         P                  ! R R4      V n        \         P                  ! RR4      V n        \         P                  ! RR4      V n        RV n        RV P                   R2V n        R	V n        R
V n        RV P                   RV P                   RV P                   R2V n	        RV P                   RV P                   RV P                   R2V n
        RV n        ^ V n        R# )BC_TENANT_IDz$b16d289b-fa4c-4578-accd-b308f19bbeb5BC_CLIENT_IDz$9956717e-890f-4c61-864a-363ae9e025a9BC_CLIENT_SECRETz(yUT8Q~OZSBa5Dl9GJkoksoPAvzwwsfC2vHDQuadtz1https://api.businesscentral.dynamics.com/.defaultz"https://login.microsoftonline.com/z/oauth2/v2.0/tokenz$9eb89615-5f45-f011-be59-000d3a5efc08zIGSA-CRM-SB-Desz.https://api.businesscentral.dynamics.com/v2.0//z%/api/IGSA/integration/v1.0/companies()z(/api/IGSA/Webintegration/v1.0/companies(N)osgetenv	tenant_id	client_idclient_secretscope	token_url
company_idenvironmentbase_api_urlbase_web_api_urlaccess_tokentoken_expiry_time)selfs   &hC:\Users\victor.barrera\Documents\proyectos\elepV3\Elep\src\App\api\services\business_central_Service.py__init__BusinessCentralService.__init__   s    >3YZ>3YZYY'9;efH
=dnn=MM_` A,<T^^<LA  EdooEVVWY 	
 =T^^<LA  HHYYZ\ 	 !!"    c                T   V P                   '       dC   \        P                  ! 4       V P                  ^<,
          8  d   \        R4       V P                   # \        R4       RRRV P                  RV P
                  RV P                  /p\        P                  ! V P                  VR7      pVP                  4        VP                  4       pVP                  R	4      V n         VP                  R
R4      p\        P                  ! 4       V,           V n        \        R4       V P                   # )ua   
Obtiene un token de acceso válido, solicitando uno nuevo si el actual
no existe o ha expirado.
z#INFO: Reutilizando token existente.z=INFO: Token no existe o ha expirado. Solicitando uno nuevo...
grant_typeclient_credentialsr   r   r   )datar   
expires_ini  z(INFO: Nuevo token obtenido exitosamente.)r   timer   printr   r   r   requestspostr   raise_for_statusjsonget)r   payloadresponse
token_dataexpires_in_secondss   &    r   	get_token BusinessCentralService.get_token$   s     t/E/E/J!J78$$$MN.T//TZZ	
 ==g>!!#]]_
 'NN>:'^^L$?!%/A!A89   r   c                   V P                  4       pRRV 2RR/pRV9   d   VP                  VR,          4       VP                  RR4        \        P                  ! W3RV/VB pVP                  4        VP                  '       d   VP                  4       # R#   \        P                  P                   d8   p\        RT 24       \        R	TP                  P                   24       ThRp?ii ; i)
u5   Método genérico para realizar solicitudes a la API.AuthorizationzBearer zContent-Typezapplication/jsonheadersN u!   ERROR: Falló la solicitud HTTP: zERROR: Cuerpo de la respuesta: )r.   updatepopr%   requestr'   contentr(   
exceptions	HTTPErrorr$   r+   text)r   methodurlkwargstokenr2   r+   errs   &&&,    r   _make_request$BusinessCentralService._make_requestC   s     wug..
 NN6),-

9d#
	''OWOOH%%'&.&6&6&68==?>B>"",, 	5cU;<3CLL4E4E3FGHI		s   A
B B C/82C**C/c                D    V P                    R 2pV P                  RV4      # )/customerImportsGETr   r@   r   r<   s   & r   get_customers$BusinessCentralService.get_customers]   )    ""##34!!%--r   c                F    V P                    R 2pV P                  RW!R7      # )rC   POSTr(   rE   r   r!   r<   s   && r   create_customer&BusinessCentralService.create_customera   s,    ""##34!!&#!99r   c                R    V P                    R V R2pV P                  RW2RR/R7      # )/customerImports(r   PATCHIf-Match*)r(   r2   rE   )r   customer_idr!   r<   s   &&& r   modify_customer&BusinessCentralService.modify_customere   s:    ""##4[MC!!'3JPSCT!UUr   c                R    V P                    R V R2pV P                  RVRR/R7      # )rQ   r   DELETErS   rT   r2   rE   )r   rU   r<   s   && r   delete_customer&BusinessCentralService.delete_customeri   s9    ""##4[MC!!(C*c9J!KKr   c                D    V P                    R 2pV P                  RV4      # )/itemImportsrD   rE   rF   s   & r   	get_items BusinessCentralService.get_itemsm   s(    ""#<0!!%--r   c                F    V P                    R 2pV P                  RW!R7      # )r^   rK   rL   rE   rM   s   && r   create_item"BusinessCentralService.create_itemq   s+    ""#<0!!&#!99r   c                D    V P                    R 2pV P                  RV4      # )z/contactsImportsrD   rE   rF   s   & r   get_contacts#BusinessCentralService.get_contactsu   rI   r   c                D    V P                    R 2pV P                  RV4      # )z/salespersonImportsrD   rE   rF   s   & r   get_salespersons'BusinessCentralService.get_salespersonsy   s)    ""##67!!%--r   c                D    V P                    R 2pV P                  RV4      # )/quoteImportsrD   rE   rF   s   & r   get_quote_lines&BusinessCentralService.get_quote_lines}   s(    ""#=1!!%--r   c                F    V P                    R 2pV P                  RW!R7      # )rk   rK   rL   rE   rM   s   && r   create_quote#BusinessCentralService.create_quote   s+    ""#=1!!&#!99r   c                ^    V P                    R V RV RV R2pV P                  RVRR/R7      # )z/quoteImports(z,'z',r   rY   rS   rT   rZ   rE   )r   	system_idquote_noline_nor<   s   &&&& r   delete_quote_line(BusinessCentralService.delete_quote_line   sE    ""#>)Bxj7)STU!!(C*c9J!KKr   c                D    V P                    R 2pV P                  RV4      # )/contactsBufferrD   r   r@   rF   s   & r   get_contact_buffer)BusinessCentralService.get_contact_buffer   s(    &&'7!!%--r   c                F    V P                    R 2pV P                  RW!R7      # )rx   rK   rL   ry   rM   s   && r   create_contact_buffer,BusinessCentralService.create_contact_buffer   s+    &&'7!!&#!99r   c                D    V P                    R 2pV P                  RV4      # )z/opportunitiesrD   rE   rF   s   & r   get_opportunities(BusinessCentralService.get_opportunities   s(    ""#>2!!%--r   )r   r   r   r   r   r   r   r   r   r   r   N)__name__
__module____qualname____firstlineno__r   r.   r@   rG   rN   rV   r[   r_   rb   re   rh   rl   ro   ru   rz   r}   r   __static_attributes____classdictcell__)__classdict__s   @r   r   r      sb     #0!>4.:VL.:...:L.:. .r   r   )r%   r   r#   dotenvr   r    r   r   <module>r      s&     	   H. H.r   