
    1zj{                         d dl Z d dl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 ddgZdZd	Zd
ZdZdZ ej$                  d      d        Z G d dej(                        Zy)    N)escape)apifieldsmodels)_leave_type_font_color)	file_openzthinzar@xenoptics.comzsusu@xenoptics.comz#EC1D23z#142933z#c00000zJhttps://xenoptics.com/2025/06/xenoptics-at-interop-winner-of-best-of-show/z-https://xenon.com.au/email-disclaimer-notice/   )maxsizec                      t        dd      5 } dt        j                  | j                               j	                         z   cddd       S # 1 sw Y   yxY w)ak  Base64 data URI, not a plain <img src="http://.../static/..."> URL --
    the Odoo server here only has a private LAN address (susu, HR staff
    routinely check this mail off the office network/VPN), so a hosted-URL
    image would just show a broken-image icon for them. Pre-shrunk to
    440x142 (xeno_hr_dashboard/static/src/img/xenoptics_logo.png) so the
    inlined payload stays small -- the original supplied logo was
    2499x806/162KB, way oversized for a ~220px-wide email header. Cached
    (module-level, process-lifetime) since this cron only sends once/day
    and the file never changes at runtime.
    z3xeno_hr_dashboard/static/src/img/xenoptics_logo.pngrbzdata:image/png;base64,N)r   base64	b64encodereaddecode)fs    K/home/susu/odoo-hr-migration/xeno_hr_dashboard/models/hr_dashboard_email.py_xeno_logo_data_urir      sM     
H$	O NST'&*:*:1668*D*K*K*MMN N Ns   4AAc                   D    e Zd ZdZdZej                  d        Zd Zd Z	y)XenoHrDashboardEmailzxeno.hr.dashboard.emailzFDaily email of the HR Dashboard's own Employee Attendance Report tablec           
         t         j                  j                  |       }|j                         dk\  ryt	        | j
                  d   j                         j                  dddd|z  fdd	d
|z  fg            }|ry| j                  |       y)aL  ir.cron is scheduled for 09:30 ICT (nextcall stored as 02:30 UTC,
        this server/container run in UTC); the working-day gate itself
        (skip weekends and company holidays) lives here rather than in the
        cron's own scheduling, same idiom as xeno_attendance's own
        weekend/holiday checks in get_month_report().   Nzresource.calendar.leaves)resource_id=F	date_fromz<=z%s 23:59:59date_toz>=z%s 00:00:00)	r   Datecontext_todayweekdayboolenvsudosearch_count!_xeno_send_daily_attendance_email)selftoday
is_holidays      r   &_cron_xeno_send_daily_attendance_emailz;XenoHrDashboardEmail._cron_xeno_send_daily_attendance_email3   s     ))$/==?a$((#=>CCERR'$ 56me34T
  

 ..u5    c                     | j                   d   j                  t        |            }| j                  ||      }| j                   d   j	                         j                  d|z  |dj                  t              dd      j                          y )Nzxeno.hr.dashboardz	mail.mailz'Update of Today's staff attendance - %s,T)subject	body_htmlemail_toauto_delete)	r    get_leave_attendance_rowsstr_xeno_render_email_htmlr!   createjoin_TEST_RECIPIENTSsend)r$   r%   rowshtmls       r   r#   z6XenoHrDashboardEmail._xeno_send_daily_attendance_emailF   s{    xx+,FFs5zR++E48""$++@5H!12	-
 	
 46r(   c                    |rg }t        |d      D ]  \  }}dj                  d ||d   |d   |d   fD              }t        |d         }|j                  d|d	|d
t	        |d         dt	        |d         dt	        |d         dt	        |d         d        dj                  |      }nd}g d}	dj                  d |	D              }
dt
        t        t               |
|t        t        dz  S )Nr	    c              3   J   K   | ]  }d t        t        |            z    yw)zE<td style="padding:8px 12px;border-bottom:1px solid #edf0f2;">%s</td>N)r   r0   ).0vs     r   	<genexpr>z?XenoHrDashboardEmail._xeno_render_email_html.<locals>.<genexpr>\   s+        \^dehijek^ll s   !#nameposition
department
leave_typez<tr>zB<td style="padding:8px 12px;border-bottom:1px solid #edf0f2;color:z;font-weight:600;">zC</td><td style="padding:8px 12px;border-bottom:1px solid #edf0f2;">total_leave_days
leave_dateback_to_work_datez
</td></tr>z<tr><td colspan="8" style="padding:24px;text-align:center;color:#adb5bd;">No approved or pending leaves for this date.</td></tr>)zNo.NamePositionTeamz
Leave TypezTotal Leave Daysz
Leave DatezBack to Work Datec              3   6   K   | ]  }d t         d|d  yw)z9<th style="padding:8px 12px;text-align:center;background:z;color:#fff;font-size:13px;">z</th>N)_TABLE_HEADER_RED)r;   hs     r   r=   z?XenoHrDashboardEmail._xeno_render_email_html.<locals>.<genexpr>v   s"      
  +<Q@
s   a  
<div style="max-width:900px;margin:0 auto;font-family:Arial,Helvetica,sans-serif;color:%(navy)s;">
  <table style="width:100%%;margin-bottom:20px;"><tr>
    <td style="font-size:14px;line-height:1.6;vertical-align:top;">
      Dear Team,<br/><br/>
      You are kindly requested to review today's staff attendance details:
    </td>
    <td style="text-align:right;white-space:nowrap;vertical-align:top;">
      <img src="%(logo)s" alt="Xenoptics" height="50" style="height:50px;width:auto;"/>
    </td>
  </tr></table>

  <h3 style="color:%(red)s;text-align:center;margin:0 0 14px;font-size:16px;">Employee Attendance Report</h3>

  <div style="overflow-x:auto;">
    <table style="width:100%%;border-collapse:collapse;font-size:13px;text-align:center;">
      <thead><tr>%(head_cells)s</tr></thead>
      <tbody>%(table_body)s</tbody>
    </table>
  </div>

  <div style="margin-top:28px;font-size:12px;color:%(navy)s;">
    <div style="font-weight:700;">Human Resource Department, XENOptics Ltd.</div>
    <div style="margin-top:4px;">
      <span style="color:%(red)s;font-weight:700;">M</span>&#160;+66&#160;52&#160;081406
      &#160;&#160;|&#160;&#160;
      <span style="color:%(red)s;font-weight:700;">E</span>&#160;
      <a href="mailto:hr@xenoptics.com" style="color:#3b7dec;">hr@xenoptics.com</a>
    </div>
    <div style="margin-top:14px;">
      <a href="%(award_url)s" style="color:%(navy)s;text-decoration:none;font-weight:700;">
        Winner Best of Show Award at Interop 2025
      </a>
    </div>
    <div style="margin-top:6px;font-style:italic;font-size:11px;">
      Read more: <a href="%(award_url)s">%(award_url)s</a>
    </div>
    <div style="margin-top:12px;">
      <a href="%(disclaimer_url)s" style="color:#3b7dec;">Email Disclaimer Notice</a>
    </div>
  </div>
</div>
)navyredlogo
head_cells
table_body	award_urldisclaimer_url)
	enumerater3   r   appendr   _BRAND_NAVY
_BRAND_REDr   
_AWARD_URL_DISCLAIMER_URL)r$   r%   r6   	body_rowsircellsleave_type_colorrO   headersrN   s              r   r1   z,XenoHrDashboardEmail._xeno_render_email_htmlP   s$    I!$* 1  6AjM1\?K   $:!L/#J    .q0Ga 234fQ|_6Ma 345	7$ +JI 
JWW 
 
 

*V  ')$$#-
U2
 2	
r(   N)
__name__
__module____qualname___name_descriptionr   modelr'   r#   r1    r(   r   r   r   /   s-    %E[LYY6 6$^
r(   r   )r   	functools
markupsafer   odoor   r   r   )odoo.addons.xeno_leave.models.leave_emailr   
odoo.toolsr   r4   rU   rT   rI   rV   rW   	lru_cacher   AbstractModelr   rd   r(   r   <module>rl      s}       $ $ L   ,-AB 
 

  Y
A QN  N
6// 
r(   