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

Getting first log in time of employee in my report.

By
charlesraj
on 3/21/14, 3:11 AM 1,263 views

Hi.. I need to display the day wise login time of employee in a my report. Now i generate a report like this. by refering the hr_timesheet module. I need to display the day wise first login time of the employee in empty coloumns below the date coloumns. how can be add the login time to these coloumns.

image description

Here is the .py and my .xsl files used to generate the report. .PY file

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
    cr.execute(
        "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">
    <amount>%.2f</amount>
</time-element>
'''
time_xml = ([xml % (day, amount) for day, amount in month.iteritems()])

# Computing the xml
xml = '''
<employee id="%d" name="%s">
%s
</employee>
''' % (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('</days>')
    date_xml.append('<cols>2.5cm%s,2cm</cols>\n' % (',0.7cm' * lengthmonth(som.year, som.month)))

    emp_xml=''
    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 = '''
    <header>
    <date>%s</date>
    <company>#####@@@######</company>
    </header>
    '''  

    xml='''<?xml version="1.0" encoding="UTF-8" ?>
    <report>
    %s
    %s
    %s
    </report>
    ''' % (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 my .XSL file.

<?xml version="1.0" encoding="utf-8"?>

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


<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" />
                    <blockBackground>
                        <xsl:attribute name="colorName">lightgrey</xsl:attribute>
                        <xsl:attribute name="start">
                            <xsl:value-of select="$col" />
                            <xsl:text>,0</xsl:text>
                        </xsl:attribute>
                        <xsl:attribute name="stop">
                            <xsl:value-of select="$col" />
                            <xsl:text>,-1</xsl:text>
                        </xsl:attribute>
                    </blockBackground>
                </xsl:for-each>
                <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"/>
            </blockTableStyle>
</xsl:template>

<xsl:template name="story">
    <spacer length="1cm" />
    <para style="title" t="1">Employees attendanceSS</para>
    <spacer length="1.5cm" />
    <blockTable>
        <xsl:attribute name="style">month</xsl:attribute>
        <xsl:attribute name="colWidths"><xsl:value-of select="report/cols" /></xsl:attribute>
        <tr>
            <td><xsl:value-of select="report/date/attribute::year" /></td>
            <xsl:for-each select="report/days/day">
                <td>
                    <xsl:value-of select="attribute::name" />
                </td>
            </xsl:for-each>
            <td></td>
        </tr>
        <tr>
                <td><xsl:value-of select="report/date/attribute::month" /></td> 
            <xsl:for-each select="report/days/day">
                <td>
                    <xsl:value-of select="attribute::number" />
                </td> 
                </xsl:for-each> 
            <!--<td t="1">Total</td>-->
        </tr>
        <xsl:apply-templates select="report/employee"/>
        <xsl:for-each select="report/employee">
            <xsl:variable name="id" select="attribute::id"/>
            <tr>
                <td><xsl:value-of select="attribute::name"/></td>
                   <xsl:for-each select="//report/days/day">        <!--select="//report/days/day"-->
                    <!--<xsl:variable name="today" select="attribute::number" />-->
                    <!--<td>
                        <para>
                            <xsl:choose>
                                <xsl:when test="sum(//employee[@id=$id]/time-element[@date=$today]) &lt; 7.5">
                                    <xsl:attribute name="style">glande</xsl:attribute>
                                </xsl:when>
                                <xsl:when test="sum(//employee[@id=$id]/time-element[@date=$today]) &lt; 8.5 and sum(//time-element[@date=$today]) &gt;= 7.5">
                                    <xsl:attribute name="style">normal_people</xsl:attribute>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:attribute name="style">esclave</xsl:attribute>
                                </xsl:otherwise>
                            </xsl:choose>
                            <xsl:value-of select="format-number(sum(//employee[@id=$id]/time-element[@date=$today]), '##.##')" />
                        </para>
                    </td>-->
                </xsl:for-each>
                <td>
                    <xsl:value-of select="format-number(sum(//employee[@id=$id]/time-element),'##.##')"/>
                </td>
            </tr>
        </xsl:for-each>
        <!--<tr>
            <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>
            </xsl:for-each>
            <td><xsl:value-of select="format-number(sum(//time-element),'##.##')"/></td>
        </tr>-->
    </blockTable>
</xsl:template>

</xsl:stylesheet>

I don't know how to add the first login time to my report. Please check my py file give suggestion for getting the corresponding day wise signin time for employee. / Please provide a python function for getting the sign-in time.

Thanks in advance...

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: 3/21/14, 3:11 AM
Seen: 1263 times
Last updated: 3/16/15, 8:10 AM