
    MBje                        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mZmZ dd	lmZ d
dlmZmZmZmZmZ  G d de	      Z G d dej                        Z ej8                  eeed
dd      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	      Z# G d de	      Z$y) zd
expense/forms.py
================
Forms for expense request submission and workflow configuration.
    )forms)Group)gettext_lazy)	ModelForm)reload_queryset)
Department)
BudgetHead
BudgetItemBudgetSubHead)Employee   )ExpenseApprovalStageExpenseApprovalWorkflowExpenseDocumentExpenseRequest	KIVRecordc                   d    e Zd ZdZ ej
                  ej                  j                  d       e	d       ej                  ddddd	d
            Z ej
                  ej                  j                          e	d      d ej                  dddddd
            Z G d d      Z fdZ xZS )ExpenseRequestFormz*Form for submitting a new expense request.T	is_activezBudget Headoh-select oh-select-2z/expense/ajax/sub-heads/z#id_budget_sub_headchangez[name='budget_head'])classzhx-getz	hx-targetz
hx-triggerz
hx-includeattrs)querysetlabelwidgetzBudget Sub-HeadFz/expense/ajax/items/z#id_budget_itemz[name='budget_sub_head'])r   r   requiredr   c                       e Zd ZeZg dZ ej                  ddi       ej                  dddd       ej                  ddd       ej                  dd	i      dZy
)ExpenseRequestForm.Meta)titleamountjustificationbudget_itemr   oh-input w-100r   z0.01)r   stepmin   r   rowsr   N)__name__
__module____qualname__r   modelfieldsr   	TextInputNumberInputTextareaSelectwidgets     1/var/www/python-projects/worksol/expense/forms.pyMetar!   6   sn    
 %U__G5E+FG'e''8HRXag.hi+U^^<LVW2XY'5<<w8O.PQ	
r7   r9   c                    |j                  dd       | _        t        |   |i | t	        | j
                         |j                  d      }|r|j                  r|j                  }|j                  j                  | j
                  d   _        t        j                  j                  |j                  j                  d      | j
                  d   _        |j                  | j
                  d   _        t         j                  j                  |j                  d      | j
                  d   _        y t         j                  j                  d	      | j
                  d   _        y )
Nemployeeinstancebudget_headT)headr   budget_sub_head)sub_headr   r%   r   )popr;   super__init__r   r0   getbudget_item_idr%   r@   r>   initialr   objectsfilterr   r
   )selfargskwargsr<   item	__class__s        r8   rC   zExpenseRequestForm.__init__E   s   

:t4$)&)$::j)//''D151C1CDKK&.6C6K6K6R6R]]''4 7S 7DKK)*3 6:]]DKK)*22<2D2D2K2K$ 3L 3DKK&/ 3=2D2D2K2KVZ2K2[DKK&/r7   )r,   r-   r.   __doc__r   ModelChoiceFieldr	   rG   rH   _r4   r=   r   noner?   r9   rC   __classcell__rM   s   @r8   r   r      s    4 )%((##**T*:u||,0."0#
 
K -e,,&&++-!"u||,,*"4#
 	O
 
\ \r7   r   c                   $    e Zd ZdZ G d d      Zy)ExpenseDocumentFormz/Inline form for uploading supporting documents.c                   F    e Zd ZeZdgZd ej                  ddd      iZy)ExpenseDocumentForm.Metafiler&   z.pdf,.jpg,.jpeg,.png,.doc,.docx)r   acceptr   N)	r,   r-   r.   r   r/   r0   r   	FileInputr5   r6   r7   r8   r9   rW   \   s0    OEOO);+ 
r7   r9   N)r,   r-   r.   rN   r9   r6   r7   r8   rU   rU   Y   s    9
 
r7   rU      T)formextramax_num
can_deletec                   n    e Zd ZdZ ej
                  d ej                  ddd       ed            Zy	)
ApproveFormz(Comment form shown in the approve modal.Fr&      r*   r   zComment (optional)r   r   r   N)	r,   r-   r.   rN   r   	CharFieldr3   rP   commentr6   r7   r8   ra   ra   q   s5    2eoou~~.>$JK$%Gr7   ra   c                   h    e Zd Z ej                   ej
                  ddd       ed            Zy)
RejectFormr&   rb   r*   r   zRejection Reason)r   r   N)r,   r-   r.   r   rd   r3   rP   reasonr6   r7   r8   rg   rg   z   s/    U__u~~.>$JK"#Fr7   rg   c                   &    e Zd Z G d d      Zd Zy)KIVFormc                   r    e Zd ZeZddgZ ej                  ddd       ej                  ddd      d	Z	y
)KIVForm.Metarh   revisit_dater&   rb   r*   r   date)r   type)rh   rm   N)
r,   r-   r.   r   r/   r0   r   r3   	DateInputr5   r6   r7   r8   r9   rl      sA    N+$enn5Eq+QR+EOO<LV\2]^
r7   r9   c                     ddl m} | j                  d   }||j                         k  rt	        j
                  t        d            |S )Nr   )rn   rm   z#Revisit date must be in the future.)datetimern   cleaned_datatodayr   ValidationErrorrP   )rI   rn   rds      r8   clean_revisit_datezKIVForm.clean_revisit_date   s?    !~.''*O(PQQ	r7   N)r,   r-   r.   r9   rw   r6   r7   r8   rj   rj      s    
 
r7   rj   c                   j    e Zd Z ej                  d ej
                  ddd       ed            Zy)	ResubmitFormFr&   rb   r*   r   zResubmission Note (optional)rc   N)r,   r-   r.   r   rd   r3   rP   noter6   r7   r8   ry   ry      s2    5??u~~.>$JK./Dr7   ry   c                        e Zd Z G d d      Zy)ExpenseApprovalWorkflowFormc                   p    e Zd ZeZg dZ ej                  ddi       ej                  ddd      dZ	y)	 ExpenseApprovalWorkflowForm.Meta)namedescriptionr   r   r&   r   rb   r*   )r   r   N)
r,   r-   r.   r   r/   r0   r   r1   r3   r5   r6   r7   r8   r9   r~      s<    '5#EOO74D*EF)5>>:JTU0VW
r7   r9   N)r,   r-   r.   r9   r6   r7   r8   r|   r|      s    
 
r7   r|   c                   2     e Zd Z G d d      Z fdZ xZS )ExpenseApprovalStageFormc                       e Zd ZeZg dZ ej                  ddi       ej                  ddi       ej                  ddi       ej                  ddd      dZ
y	)
ExpenseApprovalStageForm.Meta)workflowr   grouporderis_disbursement_stager   r   r   r   r&   1)r   r(   )r   r   r   r   N)r,   r-   r.   r   r/   r0   r   r4   r1   r2   r5   r6   r7   r8   r9   r      sf    $]$G5L+MN#EOO74D*EF!U\\2I(JK&U&&7GPS-TU	
r7   r9   c                 N    t        |   |i | t        | j                         y )N)rB   rC   r   r0   )rI   rJ   rK   rM   s      r8   rC   z!ExpenseApprovalStageForm.__init__   s!    $)&)$r7   )r,   r-   r.   r9   rC   rR   rS   s   @r8   r   r      s    
 
% %r7   r   N)%rN   djangor   django.contrib.auth.modelsr   django.utils.translationr   rP   
base.formsr   base.methodsr   base.modelsr   budget.modelsr	   r
   r   employee.modelsr   modelsr   r   r   r   r   r   rU   inlineformset_factoryExpenseDocumentFormSetFormra   rg   rj   ry   r|   r   r6   r7   r8   <module>r      s     , 6   ( " ? ? $ <\ <\~
%// 
 544	
 %**  eoo "5:: 
) 
%y %r7   