Odoo Help


Print days in a month(if it is January it should be 31 ,if it is February it should be 28...) horizontally in a report.

on 3/11/14, 2:18 AM 2,938 views

I want to print days in a month horizontally in a report . if it is January it should be 31 ,if it is February it should be 28... How can be print it in a report.

Which report package(open office report,webkit report, Aero report...) is easier to print this requirement ?.

what have you done for this ? I can do but first send me your exact requirement in word file at jain.atul43@gmail.com

Atul Kumar jain
on 3/11/14, 2:22 AM

I want to print the days in month horizontally using any report package.

on 3/11/14, 2:34 AM

Like a report printed from Reporting -> Human resources -> Reports -> Employee timesheet..

on 3/11/14, 2:45 AM

Now can't open any mails from here so kindly please help me through this forum..

on 3/11/14, 2:48 AM

hi I tried to make a report by refering the above report. the error displayed while print the report."object with reference: action - action"

on 3/11/14, 5:55 AM

René Schuster

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

Challenge Everything!

René Schuster
On 3/11/14, 6:19 AM

Dear, Ashmsh.M

as you mentioned yourself, examples for your requirement are the HR Timesheet / HR holiday reports.
Those are created using XSL:RML transformation with code generated XML templates. And that's what I used too.
To get the number of days of a month OpenERP uses this very helpful, small function:

def lengthmonth(year, month):
    if month == 2 and ((year % 4 == 0) and ((year % 100 != 0) or (year % 400 == 0))):
        return 29
    return [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month]

If you prefer any other Report Designer you should add the information of the amount of days to the object you want to print, and then loop over it.
Somehow like:

[[ repeatIn(object.day_list, 'days', 'td' ]]

Hope that will help a little.

Hi am new to python , i have no idea about how to implement this code in my report/ how to link my report to the python function. will u plese give an example.

on 3/12/14, 5:46 AM

Please review addons\hr_holidays\report\holidays_summary.xsl and


as an example.

Besides: medhabibs solution for getting the last day of a month also works very well.

René Schuster
on 3/12/14, 5:52 AM

ok thank i will refer

on 3/12/14, 6:22 AM

As a python beigner which files shall I create for printing this report... eg: files like .py file,.xml or .xsl file.. etc.please mention.

on 3/12/14, 6:32 AM

I check the related xsl and py, xml files in hr_timesheet/report and hr_timesheet/wizard... and I am confused with this. How to implement it in our custom report.

on 3/12/14, 10:05 AM

hi., René Schuster please refer my py and xml files posted as answer. By installing it as a module , A menu appears , while click on it a pop up form appears in that for i select month, year in the next line i select the employee . Then click on the below print button. openerp warning will be displayed..

on 3/13/14, 2:19 AM

hi., René Schuster I just generate a report (xsl) , in this first row contain month name and its dates ,Second row contain employee name in the first coloumn and next empty coloumns, I need to fill the empty coloumn with employee login-time from the attendance. shall post the .PY and .XSL file

on 3/21/14, 2:13 AM

posted the py and .xsl file

on 3/21/14, 2:18 AM
On 3/11/14, 5:59 AM

from report import report_sxw import datetime class class_name(report_sxw.rml_parse): def __init__(self, cr, uid, name, context): super(bulletin, self).__init__(cr, uid, name, context) self.localcontext.update({ 'time_day': self.get_days, }

def get_days(self): today = datetime.date.today() first = datetime.date(day=1, month=today.month, year=today.year) lastMonth = first - datetime.timedelta(days=1) return lastMonth.strftime("%d")

image description

On 3/13/14, 2:22 AM

Doing this by refering hr_timesheet.

import datetime
from openerp.report.interface import report_rml
from openerp.report.interface import toxml
import time
from openerp import pooler
from openerp.tools.translate import _
from openerp.report import report_sxw
from openerp.tools import ustr

def lengthmonth(year, month):
    if month == 2 and ((year % 4 == 0) and ((year % 100 != 0) or (year % 400 == 0))):
        return 29
    return [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month]

def emp_create_xml(cr, id, som, eom, emp):
    # Computing the attendence by analytical account
        "select line.date, (unit_amount / unit.factor) as amount "\
        "from account_analytic_line as line, hr_analytic_timesheet as hr, "\
        "product_uom as unit "\
        "where hr.line_id=line.id "\
        "and product_uom_id = unit.id "\
        "and line.user_id=%s and line.date >= %s and line.date < %s "
        "order by line.date",
        (id, som.strftime('%Y-%m-%d'), eom.strftime('%Y-%m-%d')))

    # Sum by day
    month = {}
    for presence in cr.dictfetchall():
        day = int(presence['date'][-2:])
        month[day] = month.get(day, 0.0) + presence['amount']

    xml = '''
    <time-element date="%s">
    time_xml = ([xml % (day, amount) for day, amount in month.iteritems()])

    # Computing the xml
    xml = '''
    <employee id="%d" name="%s">
    ''' % (id, toxml(emp), '\n'.join(time_xml))
    return xml

class report_custom(report_rml):

    def get_month_name(self, cr, uid, month, context=None):
        _months = {1:_("January"), 2:_("February"), 3:_("March"), 4:_("April"), 5:_("May"), 6:_("June"), 7:_("July"), 8:_("August"), 9:_("September"), 10:_("October"), 11:_("November"), 12:_("December")}
        return _months[month]

    def get_weekday_name(self, cr, uid, weekday, context=None):
        _weekdays = {1:_('Mon'), 2:_('Tue'), 3:_('Wed'), 4:_('Thu'), 5:_('Fri'), 6:_('Sat'), 7:_('Sun')}
        return _weekdays[weekday]
    def _last_sign(self, cr, uid, ids, name, args, context=None):
        result = {}
        if not ids:
            return result
        for id in ids:
            result[id] = False
            cr.execute("""select max(name) as name
                        from hr_attendance
                        where action in ('sign_in', 'sign_out') and employee_id = %s""",(id,))
            for res in cr.fetchall():
                result[id] = res[0]
        return result
    def create_xml(self, cr, uid, ids, data, context):

        # Computing the dates (start of month: som, and end of month: eom)
        som = datetime.date(data['form']['year'], data['form']['month'], 1)
        eom = som + datetime.timedelta(lengthmonth(som.year, som.month))
        date_xml = ['<date month="%s" year="%d" />' % (self.get_month_name(cr, uid, som.month, context=context), som.year), '<days>']
        date_xml += ['<day number="%d" name="%s" weekday="%d" />' % (x, self.get_weekday_name(cr, uid, som.replace(day=x).weekday()+1, context=context), som.replace(day=x).weekday()+1) for x in range(1, lengthmonth(som.year, som.month)+1)]
        date_xml.append('<cols>2.5cm%s,2cm</cols>\n' % (',0.7cm' * lengthmonth(som.year, som.month)))

        emp_obj = pooler.get_pool(cr.dbname).get('hr.employee')        
        for id in data['form']['employee_ids']:
            user = emp_obj.browse(cr, uid, id).user_id.id
            empl_name = emp_obj.browse(cr, uid, id).name
            if user:
                emp_xml += emp_create_xml(cr, user, som, eom, empl_name)
        # Computing the xml
        #Without this, report don't show non-ascii characters (TO CHECK)
        date_xml = '\n'.join(date_xml)
        rpt_obj = pooler.get_pool(cr.dbname).get('hr.attendance')
        rml_obj=report_sxw.rml_parse(cr, uid, rpt_obj._name,context)
        header_xml = '''

        xml='''<?xml version="1.0" encoding="UTF-8" ?>
        ''' % (header_xml,date_xml, ustr(emp_xml))
        return xml

report_custom('report.hr.analytical.timesheet_users3', 'hr.attendance', '', 'addons/atten_em/report/users_timesheet_new.xsl')

In mycorresponding .xsl file .

<xsl:stylesheet version="1.0" xmlns:xsl="&lt;a href=" http:="" www.w3.org="" 1999="" xsl="" transform"="">http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">

<xsl:import href="custom_default.xsl"/>
<xsl:import href="custom_rml.xsl"/>

<xsl:template match="/">
    <xsl:call-template name="rml" />

<xsl:template name="stylesheet">
            <paraStyle name="normal" fontName="Helvetica" fontSize="6" alignment="center" />
            <paraStyle name="normal-title" fontName="Helvetica" fontSize="6" />
            <paraStyle name="title" fontName="Helvetica" fontSize="18" alignment="center" />
            <paraStyle name="employee" fontName="Helvetica-Oblique" fontSize="10" textColor="blue" />
            <paraStyle name="glande" textColor="red" fontSize="7" fontName="Helvetica"/>
            <paraStyle name="normal_people" textColor="green" fontSize="7" fontName="Helvetica"/>
            <paraStyle name="esclave" textColor="purple" fontSize="7" fontName="Helvetica"/>
            <blockTableStyle id="month">
                <blockAlignment value="CENTER" start="1,0" stop="-1,-1" />
                <blockFont name="Helvetica" size="8" start="0,0" stop="-1,1"/>
                <blockFont name="Helvetica" size="6" start="0,2" stop="-2,-2"/>
                <blockFont name="Helvetica-BoldOblique" size="8" start="0,-1" stop="-1,-1"/>
                <blockBackground colorName="#AAAAAA" start="1,0" stop="-2,1"/>
                <xsl:for-each select="/report/days/day[@weekday=6 or @weekday=7]">
                    <xsl:variable name="col" select="attribute::number" />
                        <xsl:attribute name="colorName">lightgrey</xsl:attribute>
                        <xsl:attribute name="start">
                            <xsl:value-of select="$col" />
                        <xsl:attribute name="stop">
                            <xsl:value-of select="$col" />
                <lineStyle kind="LINEABOVE" colorName="black" start="0,0" stop="-1,-1" />
                <lineStyle kind="LINEBEFORE" colorName="black" start="0,0" stop="-1,-1"/>
                <lineStyle kind="LINEAFTER" colorName="black" start="-1,0" stop="-1,-1"/>
                <lineStyle kind="LINEBELOW" colorName="black" start="0,-1" stop="-1,-1"/>
                <blockValign value="TOP"/>

<xsl:template name="story">
    <spacer length="1cm" />
    <para style="title" t="1">Employees attendanceSS</para>
    <spacer length="1.5cm" />
        <xsl:attribute name="style">month</xsl:attribute>
        <xsl:attribute name="colWidths"><xsl:value-of select="report/cols" /></xsl:attribute>
            <td><xsl:value-of select="report/date/attribute::year" /></td>
            <xsl:for-each select="report/days/day">
                    <xsl:value-of select="attribute::name" />
                <td><xsl:value-of select="report/date/attribute::month" /></td> 
            <xsl:for-each select="report/days/day">
                    <xsl:value-of select="attribute::number" />
            <!--<td t="1">Total</td>-->
        <xsl:apply-templates select="report/employee"/>
        <xsl:for-each select="report/employee">
            <xsl:variable name="id" select="attribute::id"/>
                <td><xsl:value-of select="attribute::name"/></td>
                   <xsl:for-each select="//report/days/day">        <!--select="//report/days/day"-->
                <!--    <xsl:variable name="result" select="attribute::id" />-->
                <xsl:for-each select="//report/result/name">
                <td><xsl:variable name="result" select="attribute::id"/></td>   
                    <xsl:value-of select="//report/sign_in"/>
                </td> -->
            <td t="1">Total</td>
            <xsl:for-each select="report/days/day">
                <xsl:variable name="today" select="attribute::number"/>
                <td><xsl:value-of select="format-number(sum(//time-element[@date=$today]),'##.##')"/></td>
            <td><xsl:value-of select="format-number(sum(//time-element),'##.##')"/></td>


while click on the print button the errror appears "AttributeError: 'analytical_timesheet_daily' object has no attribute 'print_report'".

on 3/13/14, 2:35 AM

Remove _inherit = 'hr.attendance'

René Schuster
on 3/13/14, 6:45 AM

removed inherit = 'hr.attendance'.. By refering the hr_timesheet module , Next i added the corresponding files to my report folder .

on 3/14/14, 1:19 AM

About This Community

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


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 3/11/14, 2:18 AM
Seen: 2938 times
Last updated: 3/16/15, 8:10 AM