Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
5246 Vistas

hi ..

Any one please explain what this line mean.,

Attendance Sheet for the month of ${get_month(data['form']['period_id'])} ..

This is a line in .mako file . I don't know what the form actually means in the code ${get_month(data['form']['period_id'])}

Can anyone please help. me..

Avatar
Descartar
Mejor respuesta

'form' is a keyword for the data dictionary.

This dictionary is commonly used when creating a report using a wizard.

Compare this http://help.openerp.com/question/22334/how-to-generate-a-report-from-a-wizard/ (related Question).

Avatar
Descartar
Autor

<th colspan="36" style="text-align: center; font-size: 20px;"> Attendance Sheet for the month of ${get_month(data['form']['period_id'])} </th> KeyError: 'form'

Autor

<th colspan="36" style="text-align: center; font-size: 20px;"> Attendance Sheet for the month of ${get_month(data['form']['period_id'])} </th> KeyError: 'form'

Autor

please explain what this mean KeyError: 'form'

KeyError means that the requested key is not in the dictionary. https://wiki.python.org/moin/KeyError

Autor

how can i add this to the directory.

Autor

I dont know how to add this into the directory please help me. What it actuall mean (form)..

Autor

Here form is an object..

Give more details to your question. What are you trying to do? When does the error occur? Have you edited/created modules or functionality?

Autor

Hi i add my .py file and .mako file please check..

Autor

will u check my py file and .mako file

Which code is actually triggering the report and using the .mako file?

This call statement might use a parameter data or datas,

Autor

the py file and the .mako file...

Autor Mejor respuesta

from openerp.osv import osv import pooler

class employee_attendance_webkit_report(report_sxw.rml_parse):

def __init__(self, cr, uid, name, context):
    super(employee_attendance_webkit_report, self).__init__(cr, uid, name, context=context)
    self.localcontext.update({
        'time': time,
        'cr':cr,
        'uid': uid,
        'get_month' : self.get_month,
        'get_emp_data' : self.get_emp_data,
        'get_days' : self.get_days,
        'get_emp_timesheet' : self.get_emp_timesheet,
    })

def get_emp_data(self, emp_ids):
    res = []
    for employee_rec in self.pool.get('hr.employee').browse(self.cr, self.uid, emp_ids):
        res.append(employee_rec)
    return res

def get_month(self, id):
    acnt_rec = self.pool.get('account.period').browse(self.cr, self.uid, id)
    dt = acnt_rec.name
    dt = datetime.strptime(dt.__str__(),"%m/%Y")
    return datetime.strptime((dt.date().__str__()), "%Y-%m-%d").strftime("%B") + "-" + datetime.strptime((dt.date().__str__()), "%Y-%m-%d").strftime("%Y") 

def get_days(self, id):
    days = []
    acnt_rec = self.pool.get('account.period').browse(self.cr, self.uid, id)
    dt = (acnt_rec.name).__str__()
    month = int(datetime.strptime(dt,"%m/%Y").strftime("%m"))
    year = int(datetime.strptime(dt,"%m/%Y").strftime("%Y"))

    for i in range(1,monthrange(year, month)[1]+1):
        temp_dt = i.__str__() + "/" + dt
        if datetime.strptime(temp_dt,"%d/%m/%Y").strftime("%a") == "Fri":
            days.append("F")
        else:
            days.append(i)
        temp_dt = "" 
    return days

def get_emp_timesheet(self, emp_id, date_id):
    res = {}
    att_type = []
    overtime = []
    hr_analytic_timesheet_obj = self.pool.get('hr.analytic.timesheet')
    acnt_rec = self.pool.get('account.period').browse(self.cr, self.uid, date_id)
    dt = (acnt_rec.name).__str__()
    month = datetime.strptime(dt,"%m/%Y").strftime("%m")
    year = datetime.strptime(dt,"%m/%Y").strftime("%Y")
    self.cr.execute("""select id from hr_analytic_timesheet where employee_id=%s 
                        and to_char(timesheet_date, 'MM')='%s' and to_char(timesheet_date, 'YYYY')='%s'
                        order by timesheet_date"""%(emp_id, month, year))
    for r in self.cr.fetchall():
        rec = hr_analytic_timesheet_obj.browse(self.cr, self.uid, r[0])
        attendance_type = rec.att_type
        overtime_hrs = rec.overtime_hours
        if datetime.strptime(rec.timesheet_date,"%Y-%m-%d").strftime("%a") == "Fri" and overtime_hrs <= 0:
            att_type.append("F")
        elif attendance_type == "present":
            att_type.append("P")
        else:
            att_type.append("A")
        overtime.append(overtime_hrs)
    res.update({'attendance' : att_type, 'overtime': overtime})
    return res

report_sxw.report_sxw('report.webkit.emp_attendance', 'hr.attendance', 'hr_attendance/report/employee_attendance.mako', parser=employee_attendance_webkit_report)

In my .mako file.

<html> <%from datetime import date%>

<head> <style type="text/css"> td{ font-size: 15px; text-align: center; }

th{
    font-size: 15px;
    text-align: center; 
}

</style>

<% setLang('en_US') %>

</head>

<body>

<table border="1" cellspacing="0">

<tr>
    <th colspan="36" style="text-align: center; font-size: 25px;">New Line Group</th>   
</tr>       

<tr>        
    <th colspan="36" style="text-align: center; font-size: 20px;"> Attendance Sheet for the month of ${get_month(data['form']['period_id'])} </th> 
</tr>

<tr>
    <th>S/n.</th>
    <th>Name</th>
    <th>Designation</th>
    <th>Date</th>
    <%cnt = 0%> 
    %for i in get_days(data['form']['period_id']):
        %if i == "F":       
            <th style="background-color:grey;">${i}</th>
        %else:
            <th>${i}</th>           
        %endif
    <%cnt += 1%>
    %endfor
    <th>Total</th>  
</tr>

<%sr_no=0%>
%for emp in get_emp_data(data['form']['employee_ids']):
    <%sr_no+=1%>        
    <tr> 
        <td rowspan="2">${sr_no}</td>           
        <td rowspan="2">${emp.name}</td> 
        <td rowspan="2">${emp.job_id.name}</td>
        <td> Attendance </td>   
        <%res = get_emp_timesheet(emp.id, data['form']['period_id'])%>
        %for att in res['attendance']:              
            <td>${att}</td>
        %endfor
        <td>${cnt}</td> 
    </tr>       
    <tr>        
        <%total = 0.0%>
        <td>Overtime</td>
        %for att in res['overtime']:                
            <%total += att%>                
            <td>${formatLang(att)}</td>
        %endfor
        <td>${total}</td>
    </tr>
%endfor

</table>

</body>

</html>

I need to generate a report for attendance report for employee this .mako file will generate the error.

Avatar
Descartar