
    Xj	                     R    d dl mZmZmZmZ d dlmZ  G d dej                        Zy)    )_apifieldsmodels)ValidationErrorc                      e Zd ZdZdZdZ ej                  ddd      Z ej                  dd	d
      Z	 ej                  d      Z ej                         Z ej                  dd      d        Zd Zej$                  d        Zy)XenoAttendanceAutoRulezxeno.attendance.auto.rulezAuto-fill attendance rule, ported from XENHR's AttendanceAutoRule: employees/departments exempt from daily scanning (e.g. remote staff, management) are shown Present instead of Absent on a working day with no scan at all.zdepartment_id, employee_idhr.employeezEmployee (specific)zApplies only to this employee.)stringhelpzhr.department
Departmentz-Applies to every employee in this department.T)defaultemployee_iddepartment_idc                 l    | D ]/  }|j                   r|j                  rt        t        d             y )Nz5Set either an Employee or a Department for this rule.)r   r   r   r   )selfrecs     .xeno_attendance/models/attendance_auto_rule.py_check_targetz$XenoAttendanceAutoRule._check_target   s:     	PC??3+<+<%MNP P	P    c                     g }| D ]]  }|j                   j                  xs |j                  j                  xs d}|j                  |j                  t        d      |z  f       _ |S )N?z%s (auto-fill))r   namer   appendidr   )r   outr   targets       r   name_getzXenoAttendanceAutoRule.name_get   sb     	?C__))JS->->-C-CJsFJJ"2 3f <=>	? 
r   c                    | j                   d   j                         }| j                         j                  dg      }t        |j	                  d      j                  d            }|j	                  d      j                  d      j                  }|r0|t        |j                  dd|fg      j                  d            z  }|j                  d       |S )	a  xeno_employee_code strings currently covered by an active
        auto-fill rule (direct employee match, or via department) --
        XENHR's own 'ignore' rule type is validated in their API but never
        actually processed anywhere in that codebase (confirmed dead code
        in ProcessAttendanceAutoRules/AttendanceAutoRuleController), so
        only the real auto_fill behavior is ported here.
        r
   )active=Tr   zemployee_id.xeno_employee_coder   inxeno_employee_codeF)envsudosearchsetfilteredmappedidsdiscard)r   Employeerulescodesdept_idss        r   get_auto_fill_codesz*XenoAttendanceAutoRule.get_auto_fill_codes&   s     88M*//1		""$9#:;ENN=1889YZ[>>/299/JNNS?D(*K)LM &!568 8Eer   N)__name__
__module____qualname___name_description_orderr   Many2oner   r   Booleanr    Charnoter   
constrainsr   r   modelr0    r   r   r	   r	      s    'E	+  *F!&//3-/K $FOO<>M V^^D)F6;;=DS^^M?3P 4P 	YY r   r	   N)	odoor   r   r   r   odoo.exceptionsr   Modelr	   r=   r   r   <module>rA      s    ' ' +2V\\ 2r   