
    i9i+                         d dl mZ d dlmZ d dlmZ d dlmZ  e       Z G d de      Z	 G d de      Z
 G d	 d
e      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Zy)    )models)ValidationError)AbstractTimeStampModel)get_user_modelc                       e Zd ZdZddgZ ej                  dej                  d      Z ej                  de      Z
 ej                  d	d
d
d      Z ej                  d
d      Zy)CompanyBotSettingsz0Settings for company-specific bot configurationshazelHazel)mayaMayaCompanybot_settings	on_deleterelated_name2   
max_lengthchoices   TzPhone number of the bot)r   nullblank	help_textz"Whether this bot setting is activedefaultr   N)__name__
__module____qualname____doc__BOT_CHOICESr   
ForeignKeyCASCADEcompany	CharFieldbot_namephone_numberBooleanField	is_active     >/var/www/html/dp2/backend_v2.1/server/apps/companies/models.pyr   r      sq    :K  f	V^^R`aGv2{CH#6##rDTmnL###D<`aIr+   r   c                   |    e Zd ZdZ ej
                  dej                  d      Z ej                  dd      Z	 ej                  ddd	
      Z ej                  d      Z ej                  d      Z ej                  dd      Z ej"                  dddd      Z G d d      Zd Z fdZ fdZd Z xZS )Holidayz+Holiday model for company-specific holidaysr   holidaysr      z#Holiday name (e.g., Christmas, EID)r   r   TzHoliday messager   r   r   zStart date of holiday periodr   zEnd date of holiday periodzWhether this holiday is activer   r   zBots this holiday applies tor   r   r   c                       e Zd Zg dZdgZdZy)Holiday.Meta)r$   name
start_dater8   HolidaysNr   r   r   unique_togetherorderingverbose_name_pluralr*   r+   r,   Metar6   "   s    ; >(r+   r>   c                    | j                   | j                  k(  r3| j                  j                   d| j                   d| j                    dS | j                  j                   d| j                   d| j                    d| j                   dS )N - z ()z to )r8   end_dater$   r7   selfs    r,   __str__zHoliday.__str__'   sw    ??dmm+ll''(DII;b8IKK,,##$C		{"T__4ET$--XYZZr+   c                     t         |           | j                  r2| j                  r%| j                  | j                  kD  rt	        d      yyy)zValidate holiday datesz-End date must be after or equal to start dateN)supercleanr8   rB   r   rD   	__class__s    r,   rH   zHoliday.clean,   sA    ??t}}.%&UVV /  -?r+   c                 D    | j                          t        |   |i | y NrH   rG   saverD   argskwargsrJ   s      r,   rN   zHoliday.save4       

d%f%r+   c                     | j                   r2| j                  r&| j                  | j                   z
  j                  dz   S y)z$Get number of days in holiday period   r   )r8   rB   daysrC   s    r,   get_duration_dayszHoliday.get_duration_days8   s0    ??t}}MMDOO399A==r+   )r   r   r   r    r   r"   r#   r$   r%   r7   	TextFieldmessage	DateFieldr8   rB   r(   r)   ManyToManyFieldbotsr>   rE   rH   rN   rV   __classcell__rJ   s   @r,   r.   r.      s    5f	V^^R\]G6s6[\DfD@QRG!!!,JKJv*FGH###D<\]I!6!!0	D) )
[
W&r+   r.   c                   0    e Zd ZdZg dZ ej                  dej                  d      Z ej                  de      Z
 ej                  dd	
      Z ej                  ddd      Z ej                  ddd      Z G d d      Zd Z fdZ fdZ xZS )OfficeHoursz3Office hours configuration for each day of the week))mondayMonday)tuesdayTuesday)	wednesday	Wednesday)thursdayThursday)fridayFriday)saturdaySaturday)sundaySundayr   office_hoursr   
   r   Fz&Whether the office is open on this dayr   TzOffice opening timer2   zOffice closing timec                       e Zd ZddgZdgZdZy)OfficeHours.Metar$   dayzOffice HoursNr:   r*   r+   r,   r>   rq   Q   s    $e,7,r+   r>   c                     | j                   rC| j                  j                   d| j                          d| j                   d| j
                   S | j                  j                   d| j                          dS )Nr@   : : Closed)is_openr$   r7   get_day_display
start_timeend_timerC   s    r,   rE   zOfficeHours.__str__V   sq    <<ll''(D,@,@,B+C2dooEVVYZ^ZgZgYhii,,##$C(<(<(>'?xHHr+   c                     t         |           | j                  rH| j                  r| j                  st        d      | j                  | j                  k\  rt        d      yy)z#Validate office hours configurationz4Start and end times are required when office is open!End time must be after start timeN)rG   rH   rv   rx   ry   r   rI   s    r,   rH   zOfficeHours.clean[   sR    <<??$--%&\]]$--/%&IJJ 0	 r+   c                 D    | j                          t        |   |i | y rL   rM   rO   s      r,   rN   zOfficeHours.savef   rR   r+   )r   r   r   r    DAY_CHOICESr   r"   r#   r$   r%   rr   r(   rv   	TimeFieldrx   ry   r>   rE   rH   rN   r\   r]   s   @r,   r_   r_   ?   s    =K  f	V^^R`aG
&

b+
>C!f!!%;cdG!!!t4CXYJvTAVWH- -
I
	K& &r+   r_   c                   (    e Zd ZdZdgZ ej                  dej                  d      Z ej                  d      Z
 ej                  d      Z ej                  d	d
      Z ej                  ded      Z G d d      Zd Z fdZ fdZ xZS )SalesTimingz#Sales timing configuration for botsr	   r   sales_timingsr   zSales start timer3   zSales end timeTz#Whether this sales timing is activer   d   z Bot this sales timing applies to)r   r   r   c                       e Zd ZdZddgZy)SalesTiming.MetazSales Timingsr$   rx   Nr   r   r   r=   r<   r*   r+   r,   r>   r   u   s    -|,r+   r>   c                     | j                   j                   d| j                   d| j                   d| j                   S )Nr@   rt   )r$   r7   botrx   ry   rC   s    r,   rE   zSalesTiming.__str__y   s7    ,,##$CzDOO3DCWWr+   c                     t         |           | j                  r| j                  st	        d      | j                  | j                  k\  rt	        d      y)z#Validate sales timing configurationz Start and end times are requiredr{   N)rG   rH   rx   ry   r   rI   s    r,   rH   zSalesTiming.clean|   sF    dmm!"DEE??dmm+!"EFF ,r+   c                 D    | j                          t        |   |i | y rL   rM   rO   s      r,   rN   zSalesTiming.save   rR   r+   )r   r   r   r    r!   r   r"   r#   r$   r~   rx   ry   r(   r)   r%   r   r>   rE   rH   rN   r\   r]   s   @r,   r   r   j   s    -K  f	V^^RabG!!!,>?Jv*:;H###D<abI
&

c;Jl
mC- -XG& &r+   r   c                        e Zd ZdZ ej
                  dej                  d      Z ej                  dd      Z	 G d d	      Z
d
 Z fdZ fdZ xZS )CatchPhrasezCatchphrases for companiesr   catch_phrasesr   r0   zShort catch phraser1   c                       e Zd ZdZddgZy)CatchPhrase.MetazCatch Phrasesr$   phraseNr   r*   r+   r,   r>   r      s    -x(r+   r>   c                 L    | j                   j                   d| j                   S Nr@   )r$   r7   r   rC   s    r,   rE   zCatchPhrase.__str__   s"    ,,##$C}55r+   c                     t         |           | j                  r| j                  j                         st	        d      y)zValidate catchphrasezCatch phrase cannot be emptyN)rG   rH   r   stripr   rI   s    r,   rH   zCatchPhrase.clean   s3    {{$++"3"3"5!"@AA #6r+   c                 D    | j                          t        |   |i | y rL   rM   rO   s      r,   rN   zCatchPhrase.save   rR   r+   )r   r   r   r    r   r"   r#   r$   r%   r   r>   rE   rH   rN   r\   r]   s   @r,   r   r      sU    $f	V^^RabGV8LMF) )6B& &r+   r   c                   J   e Zd ZdZ ej
                  dej                  d      Z ej
                  dej                  d      Z ej                  dd	      Z
 ej                  d
d	      Z ej                  ddd      Z ej                  ddd      Z G d d      Zd Zy)CompanyHistoryz0History tracking for all company-related changesr   historyr   z	core.Usercompany_actionsr   z+Action performed: created, updated, deletedr1   r   z"Name of the model that was changedTzID of the changed objectr2   z*Human readable description of what changed)r   r   r   c                       e Zd ZdZdgZy)CompanyHistory.MetazCompany Historyz-created_atNr   r*   r+   r,   r>   r      s    /!?r+   r>   c           	          | j                   j                   d| j                   d| j                   d| j                   d| j
                  j                   	S )Nr@    z (ID: z) by )r$   r7   action
model_name	object_id
updated_byusernamerC   s    r,   rE   zCompanyHistory.__str__   sM    ,,##$C}Adoo5FfT^^L\\abfbqbqbzbza{||r+   N)r   r   r   r    r   r"   r#   r$   r   r%   r   r   IntegerFieldr   rW   detailsr>   rE   r*   r+   r,   r   r      s    :f	V^^R[\G""";&..WhiJV7deF!!!S<`aJ###TE_`If)U\`hlmG# #}r+   r   c                      e Zd ZdZ ej
                  d      Z ej
                  ddd      Z ej                  dd      Z	 ej
                  ddd      Z
 ej
                  dd	      Z ej                  edd
d      Z ej                  eej                   dddd      Z ej                  dd      Z ej                  dd      Z ej(                  d      Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z  G d d      Z!y)r   zCompany model for multi-tenancyr0   r   r   T)r   r   r   )r   r   UTC)r   r   missing_call_notify_companiesz0Users who will be notified when calls are missedr4   default_transfer_companiesz@Default user to receive calls when no other agents are available)r   r   r   r   r   )r   c                     | j                   S rL   )r7   rC   s    r,   rE   zCompany.__str__   s    yyr+   c                 6    | j                   j                         S )z'Get the number of users in this company)userscountrC   s    r,   get_user_countzCompany.get_user_count   s    zz!!r+   c                 :    | j                   j                  d      S )$Get all active users in this companyTr)   r   filterrC   s    r,   get_active_userszCompany.get_active_users   s    zz  4 00r+   c                 6    | j                   j                         S )r   r   rC   s    r,   get_all_userszCompany.get_all_users   s    zz  ""r+   c                 H    | j                   r| j                   j                  S y)z&Get the name of default transfer staffzNot Set)default_transfer_staffr   rC   s    r,   get_default_transfer_staff_namez'Company.get_default_transfer_staff_name   s     &&..777r+   c                     	 | j                   j                  |j                               S # t        j                  $ r Y yw xY w)z#Get office hours for a specific day)rr   N)rn   getlowerr_   DoesNotExist)rD   day_names     r,   get_office_hours_for_dayz Company.get_office_hours_for_day   s@    	$$((X^^-=(>>'' 		s   ), AAc                    g }dD ]  }| j                  |      }|rH|j                  r<|j                  |j                          d|j                   d|j
                          ^|j                         }|j                  | d        |S )z)Get a summary of office hours for display)r`   rb   rd   rf   rh   rj   rl   rt   r@   ru   )r   rv   appendrw   rx   ry   title)rD   summaryrr   hoursday_displays        r,   get_office_hours_summaryz Company.get_office_hours_summary   s    aC11#6E%"7"7"9!:"U=M=M<NcRWR`R`Qabc "iik+h78 b r+   c                 :    | j                   j                  d      S )z-Get all active sales timings for this companyTr   )r   r   rC   s    r,   get_active_sales_timingsz Company.get_active_sales_timings   s    !!((4(88r+   c                     g }| j                         D ]9  }|j                  |j                   d|j                   d|j                          ; |r|S dgS )z*Get a summary of sales timings for displayrt   r@   zNo active sales timings)r   r   r   rx   ry   )rD   r   timings      r,   get_sales_timings_summaryz!Company.get_sales_timings_summary   sX    335FNNfjj\F,=,=+>c&//ARST 6!wB(A'BBr+   c                 N    t        | j                  j                  dd            S )z-Get list of all catchphrases for this companyr   T)flat)listr   values_listrC   s    r,   get_catch_phrases_listzCompany.get_catch_phrases_list  s#    D&&228$2GHHr+   c                 0    | j                         }|r|S dgS )z)Get a summary of catchphrases for displayzNo catch phrases set)r   )rD   phrasess     r,   get_catch_phrases_summaryz!Company.get_catch_phrases_summary  s!    --/!w?(>'??r+   c                       e Zd ZdZy)Company.Meta	CompaniesN)r   r   r   r=   r*   r+   r,   r>   r   
  s    )r+   r>   N)"r   r   r   r    r   r%   r7   phonerW   office_time
bdc_numbertimezonerZ   Usermissing_call_notify_tor"   SET_NULLr   websitebior(   r)   rE   r   r   r   r   r   r   r   r   r   r   r>   r*   r+   r,   r   r      s5   )6s+DF$TBE"&""D9K!!!Rt$GJv2u=H3V334D	 /V..//1T fT5G
&

D
1C###D1I"1#9CI@
* *r+   r   c                       e Zd Z ej                  eej                  d      Z ej                  d      Z	 ej                  d      Z
 ej                  dd      Z G d d	      Zd
 Zy)
Dealershipdealershipsr   r0   r   r   T)r   uniquec                       e Zd ZdZy)Dealership.Meta)r$   r7   N)r   r   r   r;   r*   r+   r,   r>   r     s    -r+   r>   c                 N    | j                   dz   | j                  j                   z   S r   )r7   r$   rC   s    r,   rE   zDealership.__str__  s     yy5 4<<#4#444r+   N)r   r   r   r   r"   r   r#   r$   r%   r7   contact_person_namecontact_phoner>   rE   r*   r+   r,   r   r     se    f6>>P]^G6s+D*&**c:$F$$4@M. .5r+   r   N)	django.dbr   django.core.exceptionsr   coresite.mixinr   django.contrib.authr   r   r   r.   r_   r   r   r   r   r   r*   r+   r,   <module>r      s     2 1 .	b/ 	b)$ )X)&( )&V&( &@&( &.}+ } Z*$ Z*x
5' 
5r+   