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/leads/__pycache__/models.cpython-310.pyc
o

�we�F�@s�ddlmZddlZddlmZmZddlmZddlm	Z	ddl
mZddlm
Z
mZddlmZdd	lmZmZdd
lmZddlmZddlmZdd
lmZGdd�dej�ZGdd�deej�ZGdd�deej�ZdS)�)�OrderedDictN)�or_�and_)�
postgresql)�hybrid_property)�	load_only)�text�select)�UUID)�format_phone_number_bracket�format_phone_number)�EncryptedValue)�
ResourceMixin)�account_client)�dbc@s�eZdZdZejejdd�Zejedd�de	j
dd�Zejeje�d�dd�Z
eje��dd�Zeje��dd�Zejejdd�Zeje��dd	d
�Zejddd�Zejejejd
dddd�ddd�Zedd��Zedd��Zedd��Zedd��ZdS)�	LeadNotes�
lead_notesT��primary_key��as_uuid��unique�default�indexzleads.idF��nullable��r�server_default�User)�backrefzusers.id�lead_notes_user_id_fkey�CASCADE��name�onupdate�ondelete�rrcCs(|}tj�tdi|���tj��dS)zk
        Return whether or not the agent schedule was created successfully.

        :return: bool
        TN�)r�session�addr�commit)�cls�note�leadnoter)r)�C/home/arjun/projects/buyercall/buyercall/blueprints/leads/models.py�create-s
zLeadNotes.createcCsf|rtj�t�j|d��||||d��tj��dStj�t�j|d��|||d��tj��dS)zk
        Return whether or not the agent schedule was updated successfully.

        :return: bool
        )�id)�
updated_onr�
is_enabled�user_id)r3r4r5T)rr*�queryr�	filter_by�updater,)r-�lead_note_id�lead_note_text�lead_note_updated_date�lead_note_user_id�lead_note_enabledr)r)r0r8:s ��
��
zLeadNotes.updatecC�|j�d�S)z. Return the date the note was created
        �%Y-%m-%d %H:%M:%S�r3�strftime��selfr)r)r0�date_editedQ�zLeadNotes.date_editedcCsd�|jj|jj�S)z@ Return the full name of the user that created the note
        �{} {})�format�user�	firstname�lastnamerBr)r)r0�
user_fullnameWszLeadNotes.user_fullnameN)�__name__�
__module__�__qualname__�
__tablename__r�Column�Integerr2r
�uuid�uuid4�sid�
ForeignKey�lead_id�DateTime�
created_onr3�Booleanr4�Textr�relationshiprHr5�classmethodr1r8�propertyrDrKr)r)r)r0rs8��



rc	@s�eZdZegd��Zegd��ZdZejej	dd�Z
ejedd�dej
dd�Zejddd	�Zejd
ddd
dd�Zejej	ejdddd�ddd�Z	eje�d�dd�Zeje�d�ddd�Z	eje�d�dddd�Zejed�dddd�Zejed�dddd�Zejed�dddd�Zejed�dddd�Zejed�dddd�Zeje��ddd�Zeje�d�dd�Zejej	dd�Z eje�!�dd�Z"eje�!�dd�Z#eje�d�dd�Z$eje�d�dddd�Z%eje�d�dddd�Z&eje�d�dddd�Z'eje�d�dddd�Z(ejed �ddd�Z)eje�d�dddd�Z*ejed!�ddd�Z+ejed!�ddd�Z,eje�d"�ddd�Z-eje�d"�ddd�Z.ejed�dddd�Z/e�ejejd#d$dd%d&��Z0ejej	ejd'd(dd%d&�dd)�Z1e�ej	ejd*d+dd%d&��Z2ejej	ejd,d-ddd&�ddd�Z3ejej	dd�Z4eje�5�ddd�Z6eje�	�dd.d�Z7e�e�8��Z9e�e:j;�Z<e=d/d0��Z>e=d1d2��Z?e=d3d4��Z@eAd5d6��ZBeAd7d8��ZCeCjDd9d8��ZCeCjEd:d8��ZCeFd;d<��ZGeFd=d>��ZHeFd?d@��ZIeFdAdB��ZJeAdCdD��ZKeKjEdEdD��ZKeAdFdG��ZLeLjEdHdG��ZLeAdIdJ��ZMeMjEdKdJ��ZMeAdLdM��ZNeFdNdO��ZOeFdPdQ��ZPeFdRdS��ZQe=dTdU��ZRdVS)W�Lead))�ringingr_)�in-progressr`)�	completedzlead has been captured)�missedz2lead was missed, and there will be no more retries)z
retry-pendingz+lead was missed, but we will call them back))znew leadzNew Lead)zgeneral interestzGeneral Interest)zfollow-up requiredzFollow-up Required)zapplication startedzApplication Started)zunder contractzUnder Contract)z$application submitted - credit unionz$Application Submitted - Credit Union)zapplication submitted - autopayzApplication Submitted - AutoPay)z credit union declined no autopayz Credit Union Declined No AutoPay)zautopay declinedzAutoPay Declined)zcredit union contractedzCredit Union Contracted)zautopay contractedzAutoPay Contracted)zprevious customerzPrevious Customer)zservice callzService Call)z
accounts callz
Accounts Call)z
sold customerz
Sold Customer)zcompleted conversationzCompleted Conversation)zdo not contactzDo Not Contact�leadsTrrr�Agent)�back_populatesr�leadzall, delete-orphan�dynamiczdesc(LeadNotes.created_on))r!�cascade�lazy�order_by�partnership_accounts.idr#)r&r'Fr(�r�@z	no status)rrrrr�)r�
�ii��widgets.guid�leads_widget_guid_fkeyzSET NULLr$�phonenumbers.id�leads_inbound_fkey)r�	agents.id�leads_agent_id_fkey�contacts.id�lead_contact_fkey�0cCsH|std�Sd�|�}tttj�|�tj�|�tj�|�tj�|���S)z�
        Search a resource by 1 or more fields.

        :param query: Search query
        :type query: str
        :return: SQLAlchemy filter
        rz%{0}%)	rrGrr^�email�ilikerIrJ�status)r-r6�search_queryr)r)r0�searchs




��zLead.searchcCs�ddlm}m}|j�|j|jk���}|j�|j|jk���}t	|j�}|j
�|j�}	|j
|_
|j|_|j|_|j|_|��|S)Nr)�Partnership�PartnershipAccount)�'buyercall.blueprints.partnership.modelsr�r�r6�filterr2�partnership_account_id�first�partnership_idr�calls�get�call_sidr}�
start_time�	starttime�end_time�endtime�duration�save)r-rfr�r��partner_account�partner�
twilio_client�callr)r)r0�update_lead_twilio s�
zLead.update_lead_twiliocCs^tj�tj|ktj|ktjtjdktjdk��tdd���t	d���
�}|r-|j|jfSdS)z� Returns the last known first and last name for this phone number.

        :param partnership_account_id: the ID of the current buyercall account
        :param number: a US phone number in E.123 format (+1xxxyyyzzzz)
        r�UnknownrIrJzid desc)rr)r^r6r�r��phonenumberrI�optionsrrjrr�rJ)r-r��numberrfr)r)r0�get_last_known_name;s���
zLead.get_last_known_namecCs2ddlm}|j�|j|jk���}|r|jSdS)Nr�rd)�"buyercall.blueprints.agents.modelsrdr6r��agent_assigned_idr2r��	full_name)rCrd�agentsr)r)r0�assigned_full_nameNs
�zLead.assigned_full_namecCsd�|j|j�S)NrF)rGrIrJrBr)r)r0r�UszLead.full_namecCs2d|vr|�dd�\|_|_dS|d|_|_dS)N� �r)�splitrIrJ)rC�valuer)r)r0r�YscCstj�|jd|j�S)Nr�)r�func�concatrIrJ)r-r)r)r0r�`scCs&tj�t��|jtjktj���}|S)z4 Return the number of notes for this number
        )rr6�joinr^r�r�r4�count)rC�count_resultr)r)r0�
note_countds
��zLead.note_countcCs&tj�tj|jktj|jk���}|S)�4 Return the number of calls for this number
        )r^r6r�r�r�r�)rCr�r)r)r0�interaction_countps

��zLead.interaction_countcCr>)r�r?)r�rArBr)r)r0�interaction_time|szLead.interaction_timecC�|jdurdS|jjS�Nr��agentr�rBr)r)r0�
agent_name��
zLead.agent_namecCs |jo|jjp|jo
|jjpdSr�)�widgetr%�inbound�
friendly_namerBr)r)r0�source�s���zLead.sourcecCs,ddlm}ddlm}tj�|j|jd�S)Nr)�Widget��Phoner)	�#buyercall.blueprints.widgets.modelsr��(buyercall.blueprints.phonenumbers.modelsr�rr��coalescer%r�)r-r�r�r)r)r0r��s�cCs|jjpdSr�)r�r�rBr)r)r0�source_name�szLead.source_namecC�8ddlm}t|j�d�g��|j|jk��d��d�S)Nrr�r%r��phone)	r�r�r	r��label�wherer2�
inbound_id�limit)r-r�r)r)r0r���
��cCr�r�r�rBr)r)r0�agent_full_name�r�zLead.agent_full_namecCr�)Nrr�r%r�r�)	r�rdr	r�r�r�r2�agent_idr�)r-rdr)r)r0r��r�cCs |jo|jp|jo
t|j�pdSr�)r��widget_guidr��strr�rBr)r)r0�	source_id�s
���zLead.source_idcCr>)z1 Return the date/time this lead occurred
        r?)rXrArBr)r)r0�created_datetime�rEzLead.created_datetimecCr>)�; Return the date/time this lead record was updated
        r?r@rBr)r)r0�updated_datetime�rEzLead.updated_datetimecCs�t|j�}ddlm}|j�t|j|jk|j|k���	�}|r*|j
r*d�|j
|j�S|j
r;|j
��dkr;d�|j
�}nd}d�t|j�|�S)r�r)�ContactrF�unknownz({})r)rr��$buyercall.blueprints.contacts.modelsr�r6r�rr��
phonenumber_1r�rIrGrJ�	caller_id�lowerr)rC�formatted_numberr��contact�call_idr)r)r0�
contact_match�s
��
zLead.contact_matchcCstj�tj|k���}|S)z=
        Get leads by partnership account id: `paid`
        )r^r6r�r��all)r-�paidrcr)r)r0�get_by_partnership_account�s�zLead.get_by_partnership_accountN)SrLrMrNr�STATUSES�PROGRESSrOrrPrQr2r
rRrSrTr[r�rrUr��String�call_sourcer}�progress_statusr
rIr�rJr{r��my_phone�questionr�rWr�r��	call_typer��transfer_call_id�missed_call_cause�cause_description�
recording_url�recording_id�transcription_text�transcription_text_2�transcription_1_confidence�transcription_2_confidence�originating_numberr�r�r��
contact_idr�rZ�notes�
call_count�Float�response_time_secondsr�JSON�additional_infor\rr�r�rr�r��setter�
expressionr]r�r�r�r�r�r�r�r�r�r�r�r�r)r)r)r0r^^s,���	����������
���	������





















r^c@s�eZdZdZejejdd�Zejejejddd�ddd�Z	eje�
d	�dd
�Zeje�
d�ddd�Zeje�
d	�dd
�Z
ejejdd
�Zeje��dd
�Zeje��dd
�Zeje�
d�dd
�Zeje�
d	�dd
�Zeje�
d	�dd
�Zeje�
d
�dd
�Zeje�
d	�dd
�Zejej
ejddd�ddd�Zejejejddd�ddd�Zejejejddd�ddd�Zejejejddd�ddd�Ze�e���ZdS)�
LeadReporting�leads_reportingTrrk�'lead_reporting_partnership_account_fkey)r%Fr(rlrrmrorprr�lead_reporting_widget_guid_fkey)rrrt�lead_reporting_inbound_id_fkeyrv�lead_reporting_agent_id_fkeyrx�lead_reporting_contact_id_fkeyN)rLrMrNrOrrPrQr2rUr�r�r�r}r�r�rWr�r�r�r�r�r�r�r�r�r�r�r�r�r)r)r)r0r��sP����������r�) �collectionsrrR�
sqlalchemyrr�sqlalchemy.dialectsr�sqlalchemy.ext.hybridr�sqlalchemy.ormr�sqlalchemy.sqlrr	�sqlalchemy.dialects.postgresqlr
�buyercall.blueprints.filtersrr�buyercall.lib.util_cryptor
�buyercall.lib.util_sqlalchemyr�buyercall.lib.util_twilior�buyercall.extensionsr�Modelrr^r�r)r)r)r0�<module>s&M