
    siG                     8   d Z ddlmZ ddlmZ ddlmZ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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)reversereverse_lazy)format_html)gettext_lazy)HorillaCompanyManager)Company)Employee)HorillaModelupload_pathrender_templatec                       e Zd ZdZ ej
                  dd ed            Z ej                  d ed            Z	 ej                         Z ej                  ed ed      	      Z ed
      Z G d d      Zd Zy)AssetCategoryz>
    Represents a category for different types of assets.
       TName)
max_lengthuniqueverbose_nameDescriptionr   r   r
   blankr   
company_idc                   0    e Zd ZdZ ed      Z ed      Zy)AssetCategory.Meta6
        Meta class to add additional options
        Asset CategoryzAsset CategoriesN)__name__
__module____qualname____doc___r   verbose_name_plural     0/var/www/python-projects/worksol/asset/models.pyMetar   $   s     	 )* 23r'   r)   c                     | j                    S N)asset_category_nameselfs    r(   __str__zAssetCategory.__str__,   s    **+,r'   N)r    r!   r"   r#   r   	CharFieldr$   r,   	TextFieldasset_category_descriptionManagerobjectsManyToManyFieldr
   r   r	   r)   r/   r&   r'   r(   r   r      s     +&**t!F) "2!1!1Q}%5" fnnG'''t!I,WJ#L1G4 4-r'   r   c            	          e Zd ZdZ ej
                  dddd ed            Z ej                  ddd ed      	      Z	 ej                  ed ed
            Z e       Z G d d      Zd Zd Zd Zd Zd Zd Zd Zy)AssetLotzB
    Represents a lot associated with a collection of assets.
       FTzBatch Number)r   nullr   r   r   r   r   r9   r   r   r   r
   r   c                   6    e Zd ZdZdgZ ed      Z ed      Zy)AssetLot.Metar   -created_atzAsset BatchzAsset BatchesNr    r!   r"   r#   orderingr$   r   r%   r&   r'   r(   r)   r<   B   s%    	 "?'0r'   r)   c                     | j                    S r+   )
lot_numberr-   s    r(   r/   zAssetLot.__str__K   s    //"#r'   c                      t        dd| i      S )?
        This method for get custom column for action.
        zcbv/asset_batch_no/actions.htmlinstancepathcontextr   r-   s    r(   actionszAssetLot.actionsN   s    
 2&
 	
r'   c                 8    t        dd| j                  i      }|S )
        detail view
        zasset-batch-detail-viewpkkwargsr   rK   r.   urls     r(   asset_batch_detailzAssetLot.asset_batch_detailX   s    
 /twwH
r'   c                      t        dd| i      S )rC   z"cbv/asset_batch_no/assets_col.htmlrD   rE   r   r-   s    r(   assets_columnzAssetLot.assets_columna   s    
 5&
 	
r'   c                      t        dd| i      S )Nz&cbv/asset_batch_no/detail_actions.htmlrD   rE   r   r-   s    r(   detail_actionszAssetLot.detail_actionsk   s    9&
 	
r'   c                 8    t        dd| j                  i      }|S )/
        This method to get update url
        zasset-batch-updaterK   rL   r   rK   rO   s     r(   get_update_urlzAssetLot.get_update_urlq   s     /twwH
r'   c                 8    t        dd| j                  i      }|S )/
        This method to get delete url
        zasset-batch-number-deletebatch_idrL   rX   rO   s     r(   get_delete_urlzAssetLot.get_delete_urlx   s     6
DGG?TU
r'   N)r    r!   r"   r#   r   r0   r$   rA   r1   lot_descriptionr5   r
   r   r	   r4   r)   r/   rH   rQ   rS   rU   rY   r]   r&   r'   r(   r7   r7   0   s     "!!~&J 'f&&#Am<LO (''t!I,WJ#%G1 1$


r'   r7   c            	       :    e Zd ZdZd ed      fd ed      fd ed      fgZ ej                  d ed            Z ej                  e
ej                  d	d	 ed
            Z ej                  d	d	d ed            Z ej                  ddd	 ed            Z ej                    ed            Z ej$                  dd ed            Z ej                  eej                   ed            Z ej                  edd ed            Z ej                  eej                  d	d	 ed            Z ej                   d	d	 ed            Z ej4                  d d	 ed!      "      Z ed#      Z G d$ d%      Zd& Zd' Z d( Z!d) Z"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   z
Asset Namer   TzCurrent User)	on_deleter9   r   r   r   r:   r8   FzTracking Id)r   r9   r   r   zPurchase Date)r   
      Cost)
max_digitsdecimal_placesr   Categoryrb   r   (   Status)choicesdefaultr   r   zBatch NozExpiry Dater9   r   r      zNotify Before (days))rm   r9   r   asset_category_id__company_idc                   2    e Zd ZdgZ ed      Z ed      Zy)
Asset.Metar=   r`   AssetsN)r    r!   r"   r?   r$   r   r%   r&   r'   r(   r)   rr      s    !?zkr'   r)   c                 8    | j                    d| j                   S )N-)
asset_nameasset_tracking_idr-   s    r(   r/   zAsset.__str__   s    //"!D$:$:#;<<r'   c                      t        dd| i      S )z)
        Action column for asset
        zasset/action_column.htmlrD   rE   r   r-   s    r(   action_columnzAsset.action_column   s     +j$5G
 	
r'   c                      t        dd| i      S )7
        This method for get custome coloumn .
        zcbv/asset/detail_action.htmlrD   rE   r   r-   s    r(   detail_view_actionzAsset.detail_view_action   s    
 /&
 	
r'   c                 8    t        dd| j                  i      }|S )z!
        detail view url
        zasset-informationrK   rL   rX   rO   s     r(   asset_detailzAsset.asset_detail   s    
 .dggG
r'   c                 8    t        dd| j                  i      }|S )rW   zasset-updaterK   rL   rX   rO   s     r(   rY   zAsset.get_update_url   s     >4/B
r'   c                 8    t        dd| j                  i      }|S )r[   zasset-deleteasset_idrL   rX   rO   s     r(   r]   zAsset.get_delete_url   s     >:tww2GH
r'   c                     t         j                  j                  | j                        j	                  | j
                        }|j                         rt        dt        d      i      t        | )         S )N)rw   )idasset_descriptionz.An asset with this tracking ID already exists.)r`   r4   filterrw   excluderK   existsr   r$   superclean)r.   existing_asset	__class__s     r(   r   zAsset.clean   sy    --"44 . 

'ww  
 	
   "!'H*  w}r'   )'r    r!   r"   r#   r$   ASSET_STATUSr   r0   rv   
ForeignKeyr   PROTECTownerr1   r   rw   	DateFieldasset_purchase_dateDecimalFieldasset_purchase_costr   asset_category_idasset_statusr7   asset_lot_number_idexpiry_dateIntegerFieldnotify_beforer	   r4   r)   r/   ry   r|   r~   rY   r]   r   __classcell__)r   s   @r(   r`   r`      s   
 
1X;	an%	!O,-L
 "!!SqOJF..~&E )((#Am<L )((E$Q}=M +&**/8JK-&--aai *))a
m $6##x[	L ,&++..z] #&""DqGWXK'F''1-C+DM $$CDG* *
=

 r'   r`   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   r9   asset_reportrelated_namerb   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 )titler   r-   s    r(   r/   zAssetReport.__str__  s=     zz }}oS-	
 t}}o.	
r'   N)r    r!   r"   r#   r   r0   r   r   r`   CASCADEr   r/   r&   r'   r(   r   r      sA     F4dCE v  NfnnH

r'   r   c                       e Zd ZdZ ej
                  ddej                        Z ej                  e	dd      Z
 ej                         Z G d d      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).
    r   	documentsr   T	upload_tor   r9   c                   ,    e Zd Z ed      Z ed      Zy)AssetDocuments.MetazAsset DocumentzAsset DocumentsN)r    r!   r"   r$   r   r%   r&   r'   r(   r)   r     s    )* 12r'   r)   c                      d| j                    S )Nzdocument for )r   r-   s    r(   r/   zAssetDocuments.__str__"  s    t00122r'   N)r    r!   r"   r#   r   r   r   r   	FileFieldr   filer3   r4   r)   r/   r&   r'   r(   r   r     s[     %6$$K6>>L 6kDIDfnnG3 33r'   r   c                   :    e Zd ZdZ ej
                  edd      Zy)ReturnImagesz
    Model representing images associated with a returned asset.

    Attributes:
    - image: A FileField for uploading the image file (optional).
    Tr   N)r    r!   r"   r#   r   r   r   imager&   r'   r(   r   r   &  s     F{$TJEr'   r   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                   ed            Z
 ej                  eej                  d ed      	      Z ej                  d
      Z ej                  eej                  d ed      	      Z ej                  d
d
 ed            Z ej"                  d
d
d ed            Z ej&                  edd
d
 ed            Z ej*                  d      Z ed      Z ej2                  ed
d      Z ej2                  ed
d ed            Z ed      Z G d d       Zd! Zd" Zd# Z d$ Z!d% Z"d& Z#d' Z$d( Z%d) Z&d* Z'd+ Zd, Z(d- Z)d. Z*d/ Z+d0 Z,d1 Z-d2 Z.y3)4AssetAssignmentzO
    Represents the allocation and return of assets to and from employees.
    zMinor damagezMajor damageHealthyr`   ri   allocated_employeezAssigned To)rb   r   r   Tauto_now_addassigned_byzAssigned ByzReturn Datern   r   zReturn Conditionr:   r8   zReturn Status)rl   r   r9   r   r   F)rm   )asset_id__asset_lot_number_id__company_idreturn_images)r   r   assign_imageszAssign Condition Images)r   r   r   7assigned_to_employee_id__employee_work_info__company_idc                   6    e Zd ZdZdgZ ed      Z ed      Zy)AssetAssignment.Metaz$Meta class for AssetAssignment model-idzAsset AllocationzAsset AllocationsNr>   r&   r'   r(   r)   r   e  s#    27+, 34r'   r)   c                 R    | j                    d| j                   d| j                   S )Nz --- )assigned_to_employee_idr   return_statusr-   s    r(   r/   zAssetAssignment.__str__l  s+    ../uT]]O5I[I[H\]]r'   c                 &    d| j                    d}|S )zV
        Method will retun the api to the avatar or path to the profile image
        !https://ui-avatars.com/api/?name=&background=random)r   rO   s     r(   
get_avatarzAssetAssignment.get_avataro  s     2$--@RS
r'   c                 8    t        dd| j                  i      }|S )z)
        for detail view of page
        zasset-history-detail-viewrK   rL   rN   rO   s     r(   asset_detail_viewz!AssetAssignment.asset_detail_viewv       14/J
r'   c                      t        dd| i      S )r{   z'cbv/asset_history/assign_condition.htmlrD   rE   r   r-   s    r(   assign_condition_imgz$AssetAssignment.assign_condition_img}      
 :&
 	
r'   c                      t        dd| i      S )r{   z'cbv/asset_history/return_condition.htmlrD   rE   r   r-   s    r(   return_condition_imgz$AssetAssignment.return_condition_img  r   r'   c                      t        dd| i      S )zI
        This method for get custom column for asset tab action.
        z-cbv/request_and_allocation/asset_actions.htmlrD   rE   r   r-   s    r(   asset_actionzAssetAssignment.asset_action      
 @&
 	
r'   c                      t        dd| i      S )zD
        This method for get custom column for return date.
        z-cbv/request_and_allocation/return_status.htmlrD   rE   r   r-   s    r(   return_status_colz!AssetAssignment.return_status_col  r   r'   c                      t        dd| i      S )zU
        This method for get custom column for asset allocation tab actions.
        z7cbv/request_and_allocation/asset_allocation_action.htmlrD   rE   r   r-   s    r(   allocation_actionz!AssetAssignment.allocation_action  s    
 J&
 	
r'   c                      t        dd| i      S )N
        This method for get custom column for asset detail  actions.
        z3cbv/request_and_allocation/asset_detail_action.htmlrD   rE   r   r-   s    r(   asset_detail_actionz#AssetAssignment.asset_detail_action  s    
 F&
 	
r'   c                      t        dd| i      S )r   z>cbv/request_and_allocation/detail_action_asset_allocation.htmlrD   rE   r   r-   s    r(   asset_allocation_detail_actionz.AssetAssignment.asset_allocation_detail_action  s    
 Q&
 	
r'   c                 :    d| j                   j                   d}|S )zZ
        Method will retun the api to the avatar or path to the question template
        r   r   )r   rv   rO   s     r(   r   zAssetAssignment.get_avatar  s#     2$--2J2J1KK]^
r'   c                 8    t        dd| j                  i      }|S )rJ   zasset-detail-viewrK   rL   rN   rO   s     r(   detail_view_assetz!AssetAssignment.detail_view_asset  s    
 )4/B
r'   c                 8    t        dd| j                  i      }|S )rJ   zasset-allocation-detail-viewrK   rL   rN   rO   s     r(   detail_view_asset_allocationz,AssetAssignment.detail_view_asset_allocation  s    
 4dDGG_M
r'   c                 "    | j                   rdS dS )z)
        Asset tab detail status
        5<span class="link-primary">Requested to return</span>z2<span style = "color : yellowgreen;">In use</span>)return_requestr-   s    r(   asset_detail_statusz#AssetAssignment.asset_detail_status  s#     "" D	
 F	
r'   c                 J    | j                   rd}|S | j                  rd}|S d}|S )z5
        Asset allocation  tab detail status
        z-<span style = "color : red;" >Returned</span>r   z6<span style = "color : yellowgreen;" >Allocated</span>)return_dater   )r.   statuss     r(   detail_statuszAssetAssignment.detail_status  s=     DF
 	   LF  NFr'   c                     | j                   j                  j                   d| j                   j                  j                   S zZ
        Return subtitle containing both department and job position information.
        z / )r   employee_work_infodepartment_idjob_position_idr-   s    r(    asset_allocation_detail_subtitlez0AssetAssignment.asset_allocation_detail_subtitle  sW     ..AAOOPPSTXTpTp  UD  UD  UT  UT  TU  V  	Vr'   c                 N    | j                   j                  }d}t        d||      S )Nzoh-dot--warningzu<span class="oh-dot oh-dot--small me-1 oh-dot--color {color_class}"></span><span class="link-warning">{status}</span>)color_classr   )r   r   r   )r.   r   r   s      r(   status_displayzAssetAssignment.status_display  s.    ++'9#	
 	
r'   c                 :    | j                   }d}t        d||      S )Noh-dot--successz<span class="oh-dot oh-dot--small me-1 oh-dot--color {color_class}"></span><span class="link-success dateformat_changer">{date_col}</span>)r   date_col)assigned_dater   )r.   r   r   s      r(   assigned_date_displayz%AssetAssignment.assigned_date_display  s+    %%'N#	
 	
r'   N)/r    r!   r"   r#   r$   STATUSr   r   r`   r   r   r   r   r   r   assigned_by_employee_idr   r1   return_conditionr0   r   BooleanFieldr   r	   r4   r5   r   r   r   r)   r/   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r&   r'   r(   r   r   1  s   
 
>*+	>*+	AiL!F
 !v  ajH 0f//..)}%	 %F$$$7M/f//.."}%	 #&""DqGWXK'v''#A>P<Q %F$$'M )V((7N#$OPG*F**DM +F**$01	M $AG5 5^






	

V

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                  eej                  ddd ed            Z
 ej                  eej                   ed	      
      Z ej                  d      Z ej                  ddd ed            Z ej"                  deddd      Z ed      Z G d d      Zd Zd Zd Zd Zd Zd Zy)AssetRequestz<
    Represents a request for assets made by employees.
    	RequestedApprovedRejectedrequested_employeeFzRequesting User)rb   r   r9   r   r   r   ri   Tr   r   r   r:   r8   )r   rl   rm   r9   r   5requested_employee_id__employee_work_info__company_idc                   6    e Zd ZdZdgZ ed      Z ed      Zy)AssetRequest.Metaz!Meta class for AssetRequest modelr   zAsset RequestzAsset RequestsNr>   r&   r'   r(   r)   r   ,  s"    /7) 01r'   r)   c                      t        dd| i      S )z@
        This method for get custom coloumn for status.
        z&cbv/request_and_allocation/status.htmlrD   rE   r   r-   s    r(   
status_colzAssetRequest.status_col3  s    
 9&
 	
r'   c                      t        dd| i      S )z@
        This method for get custom coloumn for action.
        z4cbv/request_and_allocation/asset_request_action.htmlrD   rE   r   r-   s    r(   
action_colzAssetRequest.action_col=  s    
 G&
 	
r'   c                      t        dd| i      S )zG
        This method for get custom coloumn for detail action.
        z;cbv/request_and_allocation/asset_request_detail_action.htmlrD   rE   r   r-   s    r(   detail_action_colzAssetRequest.detail_action_colG  s    
 N&
 	
r'   c                     | j                   j                  j                   d| j                   j                  j                   S r   )requested_employee_idr   r   r   r-   s    r(   asset_request_detail_subtitlez*AssetRequest.asset_request_detail_subtitleQ  sN     ,,??MMNcRVRlRlRR  SP  SP  RQ  R  	Rr'   c                 8    t        dd| j                  i      }|S )rJ   zasset-request-detail-viewrK   rL   rN   rO   s     r(   detail_view_asset_requestz&AssetRequest.detail_view_asset_requestW  r   r'   c                 x    dddd}dddd}| j                   }|j                  |      |j                  |      dS )	Nr   z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_CLASSr   s       r(   status_html_classzAssetRequest.status_html_class^  sS    )'(
 '$%


 ** __V,NN6*
 	
r'   N)r    r!   r"   r#   r$   r   r   r   r   r   r  r   r   r   asset_request_dater1   descriptionr0   r  r	   r4   r)   r  r  r  r	  r  r  r&   r'   r(   r   r     s   
 
an%	Qz]#	Qz]#F
 .F--..)() *))a@P>Q *))t<"&""#Am<LK ,6++v{T $?G2 2


R
r'   r   N) r#   django.core.exceptionsr   	django.dbr   django.urlsr   r   django.utils.htmlr   django.utils.translationr   r$   base.horilla_company_managerr	   base.modelsr
   employee.modelsr   horilla.modelsr   r   horilla_views.cbv_methodsr   r   r7   r`   r   r   r   r   r   r&   r'   r(   <module>r      s    3  - ) 6 >  $ 4 5-L -6M| M`pL pf
, 
63\ 30K< KX
l X
vb
< b
r'   