B
    ÑîbC  ã               @   s„   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 d dlmZ d dlmZ e e¡G d	d
„ d
ejƒƒZdS )é    )Úcache)Úgettext_lazy)Úadmin)Úactions)ÚAccCombinationFormÚAccCombinationEditForm)ÚAdminRuntimeWarning)ÚAccCombination)ÚAreac                   sh   e Zd ZejgZdZdZeZe	Z
dd„ Zddd„Zdd	„ Z‡ fd
d„Z‡ fdd„Zd‡ fdd„	Z‡  ZS )ÚAccCombinationAdmin)ÚidÚcombination_noÚcombination_nameZgroup1Zgroup2Zgroup3Zgroup4Zgroup5)r   r   c             C   s   dS )NF© )ÚselfÚrequestr   r   ú?G:\easytimepro\master/mysite/acc\admin\acc_combination_admin.pyÚhas_add_permission   s    z&AccCombinationAdmin.has_add_permissionNc             C   s   dS )NFr   )r   r   Úobjr   r   r   Úhas_delete_permission   s    z)AccCombinationAdmin.has_delete_permissionc             C   s^   |j  dg ¡}|s&tdjtdƒdƒ‚x2|D ]*}x$|D ]}|jj|krHq6| |¡ q6W q,W d S )NÚareaz{error}Z#employee_actionError_areaIsRequired)Úerror)ZPOSTZgetlistÚ	ExceptionÚformatÚ_r   ÚpkZclone_combination)r   r   ÚobjectsZareasr   r   r   r   r   Úclone_to_area   s    

z!AccCombinationAdmin.clone_to_areac                s<   |j  dd ¡}tjj|d ¡ |_tt| ƒ 	||||¡ d S )Nr   )r   )
ÚdataÚgetr
   r   ÚfilterÚfirstr   Úsuperr   Ú
save_model)r   r   r   ÚformZchangeÚarea_id)Ú	__class__r   r   r#   )   s    zAccCombinationAdmin.save_modelc                sp  t t| ƒ |¡j|jjd}|j d¡}|j 	d¡dkpF|j 	d¡dk}|jj}|rây t
t|ƒ dd¡ dd¡ƒ}W n  tk
r”   ttd	ƒƒ‚Y nX |sàtjj|djd
d d¡}| ¡ rÆ|j}ntjj|d d¡ ¡ j}nHtjj|djd
d d¡}|r|d j}ntjj|d d¡ ¡ j}|r<|j|d}|jjsl|jj}| ¡ rl|j| ¡ d ¡ }|S )N)Z
company_idZ_p1_area__id__inÚtabler   Zexportú[Ú ú]Zacc_incorrect_lookup_parametersé   )r   r   )Zarea__pk)Zarea__in)r"   r   Úget_querysetr    ÚuserÚcurrent_companyÚGETr   ÚpathÚfindÚintÚstrÚreplacer   r   r   r
   r   ZexcludeZorder_byÚexistsr   r!   Zis_superuserZget_auth_areaÚallZdistinct)r   r   Zqsr%   Zis_get_tabler.   Zcurrent_areaZ	auth_area)r&   r   r   r,   .   s4      

z AccCombinationAdmin.get_querysetc                sJ   i }|s*t | jd|j dd¡ƒ | j|d< | |¡ tt| ƒj||f|ŽS )z7
        Use special form during user creation
        Z	area_id_Fr%   Nr$   )ÚsetattrÚadd_formr/   r   Úupdater"   r   Úget_form)r   r   r   ÚkwargsÚdefaults)r&   r   r   r:   R   s    

zAccCombinationAdmin.get_form)N)N)Ú__name__Ú
__module__Ú__qualname__r   ZCloneToAreaZlist_displayZlist_filterr   r8   r   r$   r   r   r   r#   r,   r:   Ú__classcell__r   r   )r&   r   r      s   

$r   N)Zdjango.core.cacher   Zdjango.utils.translationr   r   Úmysiter   Z
mysite.accr   Zmysite.acc.formsr   r   Zmysite.admin.exceptionsr   Zmysite.acc.modelsr	   Zmysite.personnel.modelsr
   ÚregisterZZKModelAdminr   r   r   r   r   Ú<module>   s   