Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

${get_month(data['form']['period_id'])} What the form means ?.

By
charlesraj
on 2/24/14, 6:20 AM 1,379 views

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..

1

René Schuster

--René Schuster--
1560
| 5 5 8
Weinheim, Germany
--René Schuster--

Challenge Everything!

René Schuster
On 2/24/14, 7:12 AM

'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).

<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'

charlesraj
on 2/24/14, 7:49 AM

<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'

charlesraj
on 2/24/14, 7:50 AM

please explain what this mean KeyError: 'form'

charlesraj
on 2/24/14, 7:50 AM

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

René Schuster
on 2/24/14, 8:01 AM

how can i add this to the directory.

charlesraj
on 2/24/14, 8:08 AM

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

charlesraj
on 2/24/14, 8:15 AM

Here form is an object..

charlesraj
on 2/24/14, 8:18 AM

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

René Schuster
on 2/24/14, 8:18 AM

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

charlesraj
on 2/24/14, 8:53 AM

will u check my py file and .mako file

charlesraj
on 2/25/14, 12:22 AM

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

This call statement might use a parameter data or datas,

René Schuster
on 2/25/14, 5:14 AM

the py file and the .mako file...

charlesraj
on 2/26/14, 1:05 AM
0
charlesraj
On 2/24/14, 8:52 AM

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.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 2/24/14, 6:20 AM
Seen: 1379 times
Last updated: 3/16/15, 8:10 AM