HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/buyercall/buyercall/blueprints/agents/__pycache__/models.cpython-310.pyc
o

we�H�@s6ddlZddlZddlmZddlmZddlZddlmZmZddl	m
Z
ddlmZddl
mZddlmZdd	lmZe�e�Zd
ZGdd�deej�Ze�d
ejdeje�d�dd�ejdeje�d�dd��ZGdd�deej�Ze�de�deje�d��e�deje�d���ZGdd�deej�Z dS)�N)�OrderedDict)�datetime)�or_�and_)�UUID)�hybrid_property)�text)�db)�
ResourceMixinz
US/Easternc@s�eZdZdZejejdd�Zejedd�de	j
dd�Zejeje�d�dd�Z
ejejdd�Zejejddd	�Zeje�d
�ddd�Zeje�d
�dd
d�Zejejejdddd�ddd	�Zdd�Zedd��Zedd��Zedd��Zedd��ZdS)�
AgentSchedule�agent_schedulesT��primary_key��as_uuid��unique�default�index�	agents.idF��nullable�rr�z08:00:00�r�server_defaultz17:00:00�partnership_accounts.id�CASCADE��onupdate�ondeletecCs(||_||_||_||_||_||_dS�N)�day�available_from�available_to�	is_active�partnership_account_id�agent_id)�selfr"r#r$r%r&r'�r)�D/home/arjun/projects/buyercall/buyercall/blueprints/agents/models.py�__init__1s
zAgentSchedule.__init__cGs.|D]
}tj�tdi|���qtj��dS)zk
        Return whether or not the agent schedule was created successfully.

        :return: bool
        TNr))r	�session�addr�commit)�cls�daysr"r)r)r*�create9s
zAgentSchedule.createcCs2tj�t�j|d��||||d��tj��dS)N)�sid)r%r#r$r&)r	r,�queryr�	filter_by�updater.)r/�schedule_idr#r$r%r&r)r)r*r5Fs��zAgentSchedule.updatec
Cs�z5tj�ttj|ktj|k����}|dur3|dur||_|dur$||_|dur+||_	t
j��WdSWdSt
yQ}zt�d�|j��WYd}~dSd}~ww)NTFz(Error updating agent schedule. Error: {})rr3�filterr�idr&�firstr#r$r%r	r,r.�	Exception�log�error�format�message)r/r6r#r$r%r&�schedule�er)r)r*�
api_updatePs.
���
��zAgentSchedule.api_updatecCsptj�t��ttj|ktj|k����}|dur6tj�t	��t	j
|jk���}|D]}d|_q)tj�
�dSdS)NFT)r	r,r3�Agentr7rr8r&r9rr'�allr%r.)r/r'r&�agent_foundr�agent_scheduler)r)r*�
deactivatens��
zAgentSchedule.deactivateN)�__name__�
__module__�__qualname__�
__tablename__r	�Column�Integerr8r�uuid�uuid4r2�
ForeignKeyr'�Booleanr%r"�Stringr#r$r&r+�classmethodr1r5rArFr)r)r)r*rs>����	

	
r�agent_groups�group_idrTr
r'cseZdZegd��ZdZejejdd�Z	eje
dd�dejdd�Z
ejddd	�Zejd
dddd
d�Zejejejdddd�ddd�Zejejejdddd�ddd�Zeje�d�dddd�Zeje�d�ddd�Ze�e�d��Zeje�d�ddd�Zeje�d�ddd�Zeje�d�ddd�Zejejddd�Ze�e�d��Zeje��ddd�Zejejdddd�Zeje� �dd�Z!eje��dddd �Z"ejde#e	e#j$j%ke	e#j$j&kd!d"�Z'eje��de(e(d �Z)ejejddd�Z*e�ej�Z+�fd#d$�Z,e-d%d&��Z.e-d'd(��Z/e-d)d*��Z0e-d+d,��Z1e-d-d.��Z2e-d/d0��Z3e-d1d2��Z4e-d3d4��Z5e6d5d6��Z7e6d7d8��Z8e6d9d:��Z9e6d;d<��Z:e;d=d>��Z<e;d?d@��Z=e=j>dAd@��Z=e;dBdC��Z?e;dDdE��Z@e;dFdG��ZAe=jBdHd@��Z=e=j>dId@��Z=e;dJdK��ZCeCj>dLdK��ZC�ZDS)MrB)	)�none�None)�sales�Sales)zinternet saleszInternet Sales)�bdc�BDC)�service�Service)�
management�
Management)zclient relationshipzClient Relationship)�finance�Finance)�other�Other�agentsTr
rr�Lead�agent)�back_populatesrzall, delete-orphan�dynamiczasc(AgentSchedule.day))�backref�cascade�lazy�order_byzusers.idrrrrF��)rrrr��N�f)rrrr�0)rrr�groups)�	secondary�primaryjoin�
secondaryjoinrhcstt|�j|i|��dSr!)�superrBr+)r(�args�kwargs��	__class__r)r*r+�szAgent.__init__cCs�tj�ttjtktj|k����}|durGtj|	}
||_||_	||_
||_||_||_
||_|
|_|
dur9|
|_|dur@||_tj��dSdS�zD
        Update the agent's details.

        :return: bool
        NTF)rBr3r7rr8r&r9�
DEPARTMENT�	firstname�lastname�title�email�phonenumber�mobile�	extension�	all_hours�
department�timezoner	r,r.)r/r&rr}r~r�r�r�r�r�r�r�re�get_departmentr)r)r*r5�s$"

zAgent.updatec
Csxtj�ttj|ktj|k����}
|
dur:|
|
_||
_||
_	||
_
||
_|	|
_||
_
||
_||
_||
_tj��dSdSr{)rBr3r7rr8r&r9r��descriptionr}r~rr�r�r�r�r�r	r,r.)r/r&r'rr}r~r�r�r�r�r�r�r�rer)r)r*rA�s&��
zAgent.api_updatec
Cs�tj�ttj|ktj|k����}
|
durb|dur||
_|dur#||
_|dur*||
_	|	dur1|	|
_
|
dur8|
|
_|dur?||
_|durF||
_
|durM||
_|durT||
_|dur[||
_tj��dSdSr{)rBr3r7rr8r&r9rr}r~r�r�r�r�r�r�r�r	r,r.)r/r&r'rr}r~r��mobilenumberr�r�r�r�r�rer)r)r*�
api_update_v2s:��
zAgent.api_update_v2c	CsR|std�Sd�|�}tttj�|�tj�|�tj�|�tj�|�tj	�|���S)z�
        Search a resource by 1 or more fields.

        :param query: Search query
        :type query: str
        :return: SQLAlchemy filter
        rmz%{0}%)
rr=rrBr��iliker}r~r�r�)r/r3�search_queryr)r)r*�searchHs	




��zAgent.searchcCs|j�|j�|����Sr!)r3r7r2�in_rC)r/�sidsr)r)r*�
get_from_sids_szAgent.get_from_sidscCs<|}tdi|��}tj�|�tj��|j}tj��|S)zb
        Return whether or not the agent was created successfully.

        :return: bool
        Nr))rBr	r,r-�flushr8r.)r/�params�agent_paramsrer'r)r)r*r1cs

zAgent.createcCs^tj�ttj|ktj|k����}|dur-d|_d|_t	�
�|_tj
��t�|j|j�SdS)zc
        Deactivate agent. The is_active flag will be set to false.

        :return: bool
        NFT)rBr3r7rr8r&r9r��is_deactivatedr�now�deactivated_onr	r,r.rrF)r/r8r&rer)r)r*rFws"

zAgent.deactivatecCsB|j�t|j|k|j|k|j�d�����}|r|j}|Sd}|S)zk
        Lookup and return agent id based on agent full name comparison.

        :return: integer
        FN)	r3r7r�	full_namer&r��is_r9r8)r/r&�
agent_namerer'r)r)r*�reverse_agent_id_lookup�s
���zAgent.reverse_agent_id_lookupcC�|j�d�S)z5 Return the date/time this agent was created
        �%Y-%m-%d %H:%M:%S)�
created_on�strftime�r(r)r)r*�created_datetime��zAgent.created_datetimecCr�)z5 Return the date/time this agent was updated
        r�)�
updated_onr�r�r)r)r*�updated_datetime�r�zAgent.updated_datetimecCs|js	|j�d�SdS)z= Return the date/time this agent was deactivated on.
        r�rm)r�r�r�r)r)r*�deactivated_on_datetime�szAgent.deactivated_on_datetimec	Cs�|jr
tdd�|jD��St�t�}|jpt}zt�|�}Wntjy/t�d|�Ynwt	�
tj�}|�|�
|��}|��dd}d}|�d�}|j��dksW|jr[d	}|S|jD]}|j|kr{|jr{|j|krt|jkr{nq^d	}|Sq^|S)
Ncss�|]}|jVqdSr!)�
available_now)�.0�xr)r)r*�	<genexpr>�s�z&Agent.available_now.<locals>.<genexpr>zInvalid timezone: '%s'��Fz%H:%M:%SrT)�is_group�anyrc�pytzr��DEFAULT_TIMEZONE�UnknownTimeZoneErrorr;r<rr��utc�	normalize�
astimezone�weekdayr��	schedules�countr�r"r%r#r$)	r(r��tz_name�date�
local_dater��foundresult�time�var_dayr)r)r*r��s2

�

��zAgent.available_nowcCsbddlm}ddlm}|j�|j|jk���}|r/|j�|j|j	k���}|j
�dd�}|SdS)Nr)�Endpoint)�Phonez+1rm)�"buyercall.blueprints.mobile.modelsr��(buyercall.blueprints.phonenumbers.modelsr�r3r7r'r8r9�
inbound_idr��replace)r(r�r��sip_endpoint�number�app_phone_numberr)r)r*�
app_number�szAgent.app_numbercCsd�|j|j�S)Nz{} {})r=r}r~r�r)r)r*r��szAgent.full_namecC�tj�|jd|j�S�N� �r	�func�concatr}r~�r/r)r)r*r���cC�6ddlm}|j�t|j|jk|j|jk����}|S)Nr)�Contact)	�$buyercall.blueprints.contacts.modelsr�r3r7rr&�agent_assignedr�rC)r(r��leadsr)r)r*�
contact_leads��
��zAgent.contact_leadscCr�)Nr)rd)	�!buyercall.blueprints.leads.modelsrdr3r7rr&r'r8rC)r(rd�callsr)r)r*�outbound_calls�r�zAgent.outbound_callscCr�)Nr)�Message)	�buyercall.blueprints.sms.modelsr�r3r7rr&r'r8rC)r(r��msgsr)r)r*�outbound_messages�r�zAgent.outbound_messagescCs2d|vr|�dd�\|_|_dS|d|_|_dS)Nr�r�rm)�splitr}r~)r(�valuer)r)r*r�scCr�r�r�r�r)r)r*r�	r�cCs|jsdSdS)NrB�Group)r�r�r)r)r*�type
sz
Agent.typecCstj|jdkdfgdd�S)N�tr�rB)�else_)r	�caser�r�r)r)r*r�s)ErGrHrIrr|rJr	rKrLr8rrMrNr2�relationshipr�r�rO�user_idr&rQr}r~rr�r�r�r�r�r�rPr��DateTimer�r��agent_groups_table�crTr'rcr�r��
contact_countr�r+rRr5rAr�r�r�r1rFr��propertyr�r�r�r�rr�r��
expressionr�r�r��setterr��
__classcell__r)r)ryr*rB�s�
������
��

�
�
 

0








&








rB�agent_team_association�team_idzteam.idc@s�eZdZdZejejdd�Zejedd�de	j
dd�Zeje�d�ddd�Z
eje��ddd�Zejd	ed
d�Zejejdd
�Zejejejdddd�ddd�Zejejejdddd�ddd�Zedd��Zedd��Zedd��ZdS)�Team�teamTr
rr�rmrrB�teams)rsrhFrrrrrzpartnerships.idcC�$|j�|j|k���}dd�|D�S)NcS�g|]}|j�qSr)�rc�r�r�r)r)r*�
<listcomp>4�z.Team.get_agents_by_team_id.<locals>.<listcomp>)r3r7r8rC�r/�tidr�r)r)r*�get_agents_by_team_id1�zTeam.get_agents_by_team_idcCr�)NcSr�r)r�r�r)r)r*r�9r�z/Team.get_agents_by_team_sid.<locals>.<listcomp>)r3r7r2rCr�r)r)r*�get_agents_by_team_sid6r�zTeam.get_agents_by_team_sidcCsH|j�|j|k���}g}|D]
}|�dd�|jD��qdd�|D�S)NcSsg|]}|�qSr)r)�r�rer)r)r*r�@sz3Team.get_agent_sids_by_team_sid.<locals>.<listcomp>cSsg|]}t|j��qSr))�strr2r�r)r)r*r�As)r3r7r2rC�extendrc)r/r�r�rcr�r)r)r*�get_agent_sids_by_team_sid;s
zTeam.get_agent_sids_by_team_sidN)rGrHrIrJr	rKrLr8rrMrNr2rQ�namer�r��agent_team_association_tablercrPr%rOr&�partnership_idrRr�r�rr)r)r)r*r�s0����

r�)!�loggingrM�collectionsrrr��
sqlalchemyrr�sqlalchemy.dialects.postgresqlr�sqlalchemy.ext.hybridr�sqlalchemy.sqlr�buyercall.extensionsr	�buyercall.lib.util_sqlalchemyr
�	getLoggerrGr;r��Modelr�TablerKrLrOr�rBrr�r)r)r)r*�<module>s8
l��