
    {i9                     r   d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
mZ  G d dej                        Z G d	 d
ej                        Z G d dej                        Z G d dej                        Z G d dej                        Z G d dej                        Z G d dej                        Zy)    N)	timedelta)timezone)models)User)MaxValueValidatorMinValueValidatorc            	       *   e Zd ZddgZ ej
                  eej                  dd      Z ej                  dd      Z
 ej                  d	d
      Z ej                  d	ddd      Z ej                  ddd      Z ej                  ddd      Z ej                  ddd      Z ej$                  ddd      Z ej                  ddd      Z ej                  deddd      Z ej                  ddd      Z ej                  d      Z ej                  d	dd      Z ej                  ddd      Z ej                  d	dd      Z ej                  ddddd      Z ej                  ddd      Z ej                  ddd      Z ej                  ddd      Z ej>                  dd      Z  ej>                  dd      Z! ejD                  dd dd!      Z# ejH                  d"d#$      Z% ej                  dd%d&'      Z& ej                  dd(d)'      Z' ejD                  dd d e(d       e)d	      gd*+      Z* ejV                  ed,d-d.dd/0      Z, ejZ                  ddd1      Z. ejZ                  ddd2      Z/ G d3 d4      Z0d5 Z1y6)7	Structure)activeActive)inactiveInactiveowned_structureszOwner of the structure	on_deleterelated_name	help_text   zStructure Name)
max_lengthr   d   zInternal property ID / typezInternal Reference CodeT)r   r   blanknulli  )r   r   r   r   )defaultr   r   g           r   )r   choicesr   r   r      )r       A12345z:ISTAT structure identification code for export file naming)r   r   r   r   r   
   2   )r   r         )
max_digitsdecimal_placesr   r   FzEWhen enabled, receipts are automatically maintained for reservations.r   r   RECz,Prefix used for structure receipt numbering.)r   r   r   INVz,Prefix used for structure invoice numbering.zADefault VAT rate applied to accommodation amounts (gross prices).)r#   r$   r   
validatorsr   StructureUser)	structureuseraccessible_structuresz'Users who have access to this structure)throughthrough_fieldsr   r   r   )auto_now_addr   r   )auto_nowr   r   c                       e Zd ZdZy)Structure.Meta
structuresN__name__
__module____qualname__db_table     /backend/structures/models.pyMetar2   ^   s    r:   r<   c                     | j                   S N)nameselfs    r;   __str__zStructure.__str__a   s    yyr:   N)2r5   r6   r7   STATUS_CHOICESr   
ForeignKeyr   CASCADEr+   	CharFieldr?   structure_typeinternal_reference_codeURLField	image_urlIntegerField
base_price	occupancy
FloatFieldratingtotal_unitsstatusstreet_addresszip_codecountrylegal_entity_nametax_id_vat_number
istat_codedefault_currencydefault_language	time_zone	TimeFielddefault_check_in_timedefault_check_out_timeDecimalFielddefault_tax_rateBooleanFieldinvoicing_enabledreceipt_prefixinvoice_prefixr   r   default_vat_rateManyToManyFieldusersDateTimeField
created_at
updated_atr<   rB   r9   r:   r;   r
   r
      s    N 6..'*	D 6s6FGD%V%%"?AN.f..";4d  3dFI$$$QdFJ###ATEIVs$TBF%&%%at$GKVN$UYcklF &V%%DtLNv2.Hf#TEG )((Ct$O(((Ct$O!!!NJ (v''2TM'v''2TM   BdFI,F,,4dC-V--DtD*v**aQU\`a+++Y &V%%@N
 &V%%@N
 +v**%a(*;C*@AU #F"",,;E &%%4t$OJ%%%t4dKJ   r:   r
   c                   f   e Zd Zg dZ ej
                  eej                  d      Z ej
                  e	ej                  d      Z
 ej                  dedd      Z ej                  d	
      Z ej                  d	      Z ej
                  e	ej                   d	d	dd      Z G d d      Zd Zy)r)   ))Adminrk   )Editorrl   )Viewerrm   structure_usersr   r   user_structuresr   rm   zUser's role in this structurer   r   r   r   Tr/   r0   created_structure_usersz)User who added this user to the structurer   r   r   r   r   c                       e Zd ZdZddgZdgZy)StructureUser.Metarn   r*   r+   -created_atNr5   r6   r7   r8   unique_togetherorderingr9   r:   r;   r<   rw      s    $&/!?r:   r<   c                 |    | j                   j                   d| j                  j                   d| j                   dS )Nz - z ())r+   usernamer*   r?   roler@   s    r;   rB   zStructureUser.__str__   s5    ))$$%S)<)<(=R		{!LLr:   N)r5   r6   r7   ROLE_CHOICESr   rD   r
   rE   r*   r   r+   rF   r   rg   rh   ri   SET_NULL
created_byr<   rB   r9   r:   r;   r)   r)   d   s    L "!!..&I
 6..&D
 61	D &%%48J%%%t4J #""//.=J# #
Mr:   r)   c                       e Zd Zg dZ ej
                  dej                  d      Z ej                  d      Z
 ej                  eej                  dddd	      Z ej                  d
ej"                  dd      Z ej&                  ddd      Z ej                  eej                  d      Z ej                  d
ed      Z ej0                         Z ej0                  dd      Z ej                  eej6                  dddd	      Z ej0                  d      Z ej0                  d      Z G d d      Zd Z e!d        Z"e!d        Z#d Z$ fdZ% xZ&S ) 
Invitation))pendingPending)acceptedAccepted)expiredExpired)	cancelled	CancelledTFprimary_keyr   editablezEmail address of the inviteer   invitationsz&Structure to invite user to (optional)ru   r   rm   zRole to assign in structurerq   zPersonal message from inviter)r   r   r   sent_invitationsro   r   r   r   r   r   r   received_invitationsz!User created from this invitationrr   rs   c                       e Zd ZdZdgZy)Invitation.Metar   rx   Nr5   r6   r7   r8   r{   r9   r:   r;   r<   r      s     !?r:   r<   c                 n    | j                   r| j                   j                  nd}d| j                   d| S )NSystemzInvitation to z for )r*   r?   email)rA   structure_names     r;   rB   zInvitation.__str__   s1    04,,H

|50@AAr:   c                 f    t        j                         | j                  kD  xr | j                  dk(  S )Nr   )r   now
expires_atrQ   r@   s    r;   
is_expiredzInvitation.is_expired   s%    ||~/LDKK94LLr:   c                     | j                   dk7  ry| j                  t        j                         z
  }t	        d|j
                        S )Nr   r   )rQ   r   r   r   maxdays)rA   deltas     r;   days_until_expiryzInvitation.days_until_expiry   s6    ;;)#(,,.01ejj!!r:   c                 R    | j                   dk(  rd| _         | j                          yy)zMark invitation as expiredr   r   N)rQ   saver@   s    r;   expirezInvitation.expire   s#    ;;)##DKIIK $r:   c                     | j                   s&t        j                         t        d      z   | _         t	        |   |i | y )N   )r   )r   r   r   r   superr   )rA   argskwargs	__class__s      r;   r   zInvitation.save   s2    &llnyb/AADOd%f%r:   )'r5   r6   r7   rC   r   	UUIDFielduuiduuid4id
EmailFieldr   rD   r
   rE   r*   rF   r)   r   r   	TextFieldmessager   
invited_byrQ   rg   r   accepted_atr   created_userrh   ri   r<   rB   propertyr   r   r   r   __classcell__)r   s   @r;   r   r      s   N 
		dDJJ	OBF(FGE!!!..":I 6**/	D f1G
 #""..'J
 VF
 &%%'J&&&&D=K$6$$//+5L &%%48J%%%t4J# #B M M " "& &r:   r   c                   |   e Zd ZdZddgZ ej                  eej                  dd      Z	 ej                  dedd	
      Z ej                  dd      Z ej                  ddd      Z ej                   edd      Z ej&                  dddd      Z ej&                  dddd      Z ej&                  dddd      Z ej.                  d      Z ej.                  d      Z ej4                  eej8                  ddd      Z ej4                  eej8                  ddd      Z G d d       Zd! Z d" Z!d%d$Z"y#)&ChannelSettingszJChannel settings for a structure including availability and price settings)relativeRelative)absoluteAbsolutechannel_settingsz"Structure these settings belong tor   r   r   z*Default booking type: Relative or Absoluterq      zFDefault booking value (days for relative, specific value for absolute)r%   Tz.Default booking until date (for absolute type))r   r   r   z+Property-specific booking settings override)r   r   r   r!   r"   r   z2% increase from base price for Booking.com (0-100))r#   r$   r   r   z-% increase from base price for Airbnb (0-100)z.% increase from base price for Expedia (0-100)rr   rs   created_channel_settingsr   r   r   r   updated_channel_settingsc                       e Zd ZdZdZdZy)ChannelSettings.Metar   zChannel SettingzChannel SettingsN)r5   r6   r7   r8   verbose_nameverbose_name_pluralr9   r:   r;   r<   r   2  s    %(0r:   r<   c                 4    d| j                   j                   S )NzChannel Settings for r*   r?   r@   s    r;   rB   zChannelSettings.__str__7  s    &t~~':':&;<<r:   c                     t        |      }|| j                  v r| j                  |   S | j                  | j                  | j                  r| j                  j                         dS ddS )z,Get booking settings for a specific propertyNbooking_typebooking_valuebooking_until_date)strindividual_accommodationsdefault_booking_typedefault_booking_valuedefault_booking_until_date	isoformat)rA   property_idproperty_id_strs      r;   get_property_booking_settingsz-ChannelSettings.get_property_booking_settings:  st    k*d<<<11/BB !55!77QUQpQp$"A"A"K"K"M
 	
 w{
 	
r:   Nc                     | j                   si | _         |||r|j                         ndd| j                   t        |      <   | j                          y)z,Set booking settings for a specific propertyNr   )r   r   r   r   )rA   r   r   r   r   s        r;   set_property_booking_settingsz-ChannelSettings.set_property_booking_settingsG  sO    ---/D* )*DV"4">">"@\`<
&&s;'78
 			r:   r>   )#r5   r6   r7   __doc__BOOKING_TYPE_CHOICESr   OneToOneFieldr
   rE   r*   rF   r   PositiveIntegerFieldr   	DateFieldr   	JSONFielddictr   r^   booking_percentageairbnb_percentageexpedia_percentagerg   rh   ri   rD   r   r   r   
updated_byr<   rB   r   r   r9   r:   r;   r   r      s   T 	! 
 %$$..'6	I ,6++$>	 8F77Z "2!1!1B" !1 0 0?! -,,F	 ,++A	 -,,B	 &%%48J%%%t4J"""///J #""///J1 1
=

r:   r   c                      e Zd Z ej                  eej                  d      Z ej                  ddd      Z	 ej                         Z ej                         Z ej                  e      Z ej                  e      Z ej"                  d      Z ej&                  d	      Z ej&                  d
      Z G d d      Zd Zy)StructureCityTaxSettingscity_tax_settingsro   r   r"   z$Default city tax per adult per nightr#   r$   r   r   Trr   rs   c                       e Zd ZdZy)StructureCityTaxSettings.Metastructure_city_tax_settingsNr4   r9   r:   r;   r<   r   m  s    0r:   r<   c                 4    d| j                   j                   S )NzCity Tax Settings - r   r@   s    r;   rB   z StructureCityTaxSettings.__str__p  s    %dnn&9&9%:;;r:   N)r5   r6   r7   r   r   r
   rE   r*   r^   default_rater   max_taxable_nightsminor_age_limitr   listexemption_reasonsplatform_exemptionsr`   	is_activerg   rh   ri   r<   rB   r9   r:   r;   r   r   T  s    $$$..(I '6&&8L 54461f113O(((6*&**48###D1I%%%48J%%%t4J1 1<r:   r   c                   :   e Zd Z ej                  eej                  d      Z ej                  eej                  d      Z	 ej                         Z ej                  d      Z ej                  ddd	      Z ej                  d
      Z G d d      Zd Zy)CityTaxMonthlyRatecity_tax_monthly_ratesro   monthly_ratesz1 = January, 12 = Decemberr   r   r"   zCity tax per adult per nightr   Trr   c                       e Zd ZdZdZddgZy)CityTaxMonthlyRate.Metar   )r*   yearmonthr   r   Nry   r9   r:   r;   r<   r     s    +8G$r:   r<   c                     | j                   j                   d| j                   d| j                   d| j                   S )N | -u    → €)r*   r?   r   r   rater@   s    r;   rB   zCityTaxMonthlyRate.__str__  s6    ..%%&c$))Adjj\$))UUr:   N)r5   r6   r7   r   rD   r
   rE   r*   r   settingsr   r   r   r^   r  rg   rh   r<   rB   r9   r:   r;   r   r   t  s    !!!..-I !v   ..$H '6&&(D'F''2NOE60D &%%48J% %
Vr:   r   c                   `   e Zd ZdgZ ej
                  dej                  d      Z ej                  e
ej                  d      Z ej                  eej                  ddd      Z ej                   ded	
      Z ej$                         Z ej$                         Z ej$                         Z ej,                  e      Z ej2                  dd      Z ej2                  dd      Z ej,                         Z ej                   dd      Z ej<                  d      Z G d d      Z d Z!y)CityTaxReportHistory)finalFinalTFr   city_tax_reportsro   r      r  r   r   r   @   )r   r   rr   c                       e Zd ZdZdgZy)CityTaxReportHistory.Metacity_tax_report_historyrx   Nr   r9   r:   r;   r<   r    s    ,!?r:   r<   c                 h    | j                   j                   d| j                  xs | j                   S )Nr   )r*   r?   labelperiod_yearr@   s    r;   rB   zCityTaxReportHistory.__str__  s.    ..%%&c$***H8H8H)IJJr:   N)"r5   r6   r7   rC   r   r   r   r   r   rD   r
   rE   r*   r   r   r   rF   rQ   PositiveSmallIntegerFieldperiod_from_monthperiod_to_monthr  r   r   ratesr   property_type_idr   preview_snapshotr  rg   rh   r<   rB   r9   r:   r;   r  r    s@   N 
		dDJJ	OB!!!..'I
 #""//'J VF
 988:6f668O2&224KFT*E2v22DI-&--4tDK'v'')F$7E%%%48J# #Kr:   r  )r   datetimer   django.utilsr   	django.dbr   django.contrib.auth.modelsr   django.core.validatorsr   r   Modelr
   r)   r   r   r   r   r  r9   r:   r;   <module>r     s      !  + GZ Zx*MFLL *MXP& P&dofll od<v|| <@V VB&K6<< &Kr:   