
    vg                         d 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 ddlmZ ddlm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)z
Models for Asset Management System

This module defines Django models to manage assets, their categories, assigning, and requests
within an Asset Management System.
    )ValidationError)models)gettext_lazy)HorillaCompanyManager)Company)Employee)HorillaModelc                       e Zd ZdZ ej
                  dd      Z ej                  d      Z ej                         Z
 ej                  ed ed            Z ed      Z
d	 Zy
)AssetCategoryz>
    Represents a category for different types of assets.
       T)
max_lengthuniquer   r   blankverbose_name
company_idc                     | j                    S N)asset_category_nameselfs     /var/www/horilla/asset/models.py__str__zAssetCategory.__str__   s    **+,    N)__name__
__module____qualname____doc__r   	CharFieldr   	TextFieldasset_category_descriptionManagerobjectsManyToManyFieldr   _r   r   r    r   r   r   r      sh     +&**c$G!1!1!1S!AfnnG'''t!I,WJ#L1G-r   r   c                       e Zd ZdZ ej
                  dddd      Z ej                  ddd      Z ej                  e
d ed      	      Z e       Z G d
 d      Zd Zy)AssetLotzB
    Represents a lot associated with a collection of assets.
       FT)r   nullr   r   r   r+   r   r   r   r   c                   0    e Zd ZdZ ed      Z ed      Zy)AssetLot.Metaz6
        Meta class to add additional options
        zAsset BatchzAsset BatchesN)r   r   r   r   r&   r   verbose_name_pluralr'   r   r   Metar.   +   s    	 '0r   r0   c                     | j                    S r   )
lot_numberr   s    r   r   zAssetLot.__str__3   s    //"#r   N)r   r   r   r   r   r    r2   r!   lot_descriptionr%   r   r&   r   r   r$   r0   r   r'   r   r   r)   r)   !   si     "!!Re5QUVJ&f&&DMO'''t!I,WJ#%G1 1$r   r)   c                       e Zd ZdZd ed      fd ed      fd ed      fgZ ej                  d      Z ej                  e
ej                  dd	      Z ej                  ddd
      Z ej                  ddd      Z ej                          Z ej$                  dd      Z ej                  eej                        Z ej                  edd      Z ej                  eej                  dd	      Z ej                   dd      Z ej4                  dd      Z ed      Z G d d      Zd Z fdZ  xZ!S )Assetz5
    Represents a asset with various attributes.
    zIn usezIn Use	AvailablezNot-Availabler   r   T)	on_deleter+   r   r,   r*   F)r   r+   r   
      )
max_digitsdecimal_places)r7   (   )choicesdefaultr   r+   r      )r>   r+   asset_category_id__company_idc                       e Zd ZdgZy)
Asset.Metaz-created_atN)r   r   r   orderingr'   r   r   r0   rC   R   s	    !?r   r0   c                 8    | j                    d| j                   S )N-)
asset_nameasset_tracking_idr   s    r   r   zAsset.__str__U   s    //"!D$:$:#;<<r   c                     t         j                  j                  | j                        j	                  | j
                        }|j                         rt        dt        d      i      t        | )         S )N)rH   )idasset_descriptionz.An asset with this tracking ID already exists.)r5   r$   filterrH   excludepkexistsr   r&   superclean)r   existing_asset	__class__s     r   rQ   zAsset.cleanX   sy    --"44 . 

'ww  
 	
   "!'H*  w}r   )"r   r   r   r   r&   ASSET_STATUSr   r    rG   
ForeignKeyr   PROTECTownerr!   rK   rH   	DateFieldasset_purchase_dateDecimalFieldasset_purchase_costr   asset_category_idasset_statusr)   asset_lot_number_idexpiry_dateIntegerFieldnotify_beforer   r$   r0   r   rQ   __classcell__)rS   s   @r   r5   r5   7   s]   
 
1X;	an%	!O,-L
 "!!S1JFh&..tSWXE(((d$3O(((BU4P*&**,-&--AN)))-6>>R#6##kbL ,&++FNNT #&""D9K'F''=M#$CDG# #= r   r5   c                   ~    e Zd ZdZ ej
                  ddd      Z ej                  edej                        Z
d Zy)	AssetReportz
    Model representing a report for an asset.

    Attributes:
    - title: A CharField for the title of the report (optional).
    - asset_id: A ForeignKey to the Asset model, linking the report to a specific asset.
    r   T)r   r   r+   asset_reportrelated_namer7   c                 n    | j                   r| j                   d| j                    S d| j                   S )z
        Returns a string representation of the AssetReport instance.
        If a title is present, it returns "asset_id - title".
        Otherwise, it returns "report for asset_id".
        z - zreport for )titleasset_idr   s    r   r   zAssetReport.__str__w   s=     zz }}oS-	
 t}}o.	
r   N)r   r   r   r   r   r    ri   rU   r5   CASCADErj   r   r'   r   r   rd   rd   i   sA     F4dCE v  NfnnH

r   rd   c                       e Zd ZdZ ej
                  ddej                        Z ej                  ddd      Z	 ej                         Zd Zy	)
AssetDocumentsa  
    Model representing documents associated with an asset report.

    Attributes:
    - asset_report: A ForeignKey to the AssetReport model, linking the document to
    a specific asset report.
    - file: A FileField for uploading the document file (optional).
    rd   	documentsrf   zasset/asset_report/documents/T	upload_tor   r+   c                      d| j                    S )Nzdocument for )re   r   s    r   r   zAssetDocuments.__str__   s    t00122r   N)r   r   r   r   r   rU   rk   re   	FileFieldfiler#   r$   r   r'   r   r   rm   rm      sV     %6$$K6>>L 61DD fnnG3r   rm   c                   :    e Zd ZdZ ej
                  ddd      Zy)ReturnImagesz
    Model representing images associated with a returned asset.

    Attributes:
    - image: A FileField for uploading the image file (optional).
    zasset/return_images/Tro   N)r   r   r   r   r   rr   imager'   r   r   ru   ru      s!     F'=TPTUEr   ru   c                   h   e Zd ZdZd ed      fd ed      fd ed      fgZ ej                  eej                   ed            Z
 ej                  eej                  d      Z ej                  d	
      Z ej                  eej                  d      Z ej                  d	d	      Z ej"                  d	d	d      Z ej&                  edd	d	      Z ej*                  d      Z ed      Z ej2                  ed	d      Z ej2                  ed	d      Z ed      Z G d d      Zd Zy)AssetAssignmentzO
    Represents the allocation and return of assets to and from employees.
    zMinor damagezMajor damageHealthyassetr7   r   allocated_employee)r7   rg   Tauto_now_addassigned_byr?   r   r,   r*   )r=   r   r+   r   F)r>   )asset_id__asset_lot_number_id__company_idreturn_images)r   rg   assign_images7assigned_to_employee_id__employee_work_info__company_idc                       e Zd ZdZdgZy)AssetAssignment.Metaz$Meta class for AssetAssignment model-idNr   r   r   r   rD   r'   r   r   r0   r      s    27r   r0   c                 R    | j                    d| j                   d| j                   S )Nz --- )assigned_to_employee_idrj   return_statusr   s    r   r   zAssetAssignment.__str__   s+    ../uT]]O5I[I[H\]]r   N)r   r   r   r   r&   STATUSr   rU   r5   rV   rj   r   r   rX   assigned_dateassigned_by_employee_idreturn_dater!   return_conditionr    r   BooleanFieldreturn_requestr   r$   r%   ru   r   r   r0   r   r'   r   r   rx   rx      sf   
 
>*+	>*+	AiL!F
 !v  ajH 0f//FNN9M %F$$$7M/f//FNN #&""D9K'v''T#N$F$$2DM )V((7N#$OPG*F**DM +F**DM $AG 
^r   rx   c                   ~   e Zd ZdZd ed      fd ed      fd ed      fgZ ej                  eej                  ddd      Z
 ej                  eej                   ed      	      Z ej                  d
      Z ej                  d
d
d      Z ej"                  dedd
d
      Z ed      Z G d d      Zd Zy)AssetRequestz<
    Represents a request for assets made by employees.
    	RequestedApprovedRejectedrequested_employeeF)r7   rg   r+   r   zAsset Categoryr{   Tr}   r   r,   r*   )r   r=   r>   r+   r   5requested_employee_id__employee_work_info__company_idc                       e Zd ZdZdgZy)AssetRequest.Metaz!Meta class for AssetRequest modelr   Nr   r'   r   r   r0   r      s    /7r   r0   c                 x    dddd}dddd}| j                   }|j                  |      |j                  |      dS )	Nzoh-dot--successzoh-dot--infozoh-dot--danger)r   r   r   zlink-successz	link-infozlink-danger)colorlink)asset_request_statusget)r   COLOR_CLASS
LINK_CLASSstatuss       r   status_html_classzAssetRequest.status_html_class   sS    )'(
 '$%


 ** __V,NN6*
 	
r   N)r   r   r   r   r&   r   r   rU   r   rV   requested_employee_idr   r\   rX   asset_request_dater!   descriptionr    r   r   r$   r0   r   r'   r   r   r   r      s    
 
an%	Qz]#	Qz]#F
 .F--..) *))a@P>Q *))t<"&""DSIK+6++v{T $?G 

r   r   N)r   django.core.exceptionsr   	django.dbr   django.utils.translationr   r&   base.horilla_company_managerr   base.modelsr   employee.modelsr   horilla.modelsr	   r   r)   r5   rd   rm   ru   rx   r   r'   r   r   <module>r      s    3  6 >  $ '-L -$| $,/L /d
, 
63\ 3,V< V+^l +^\2
< 2
r   