[IMP] hr_holidays: Convert Leaves Summary xsl report in qweb report

This commit is contained in:
rsi-odoo
2015-02-04 15:28:50 +01:00
committed by Damien Bouvy
parent 5823a6c64a
commit 1a2b4f4de7
11 changed files with 228 additions and 577 deletions
+2
View File
@@ -46,12 +46,14 @@ A synchronization with an internal agenda (Meetings of the CRM module) is also p
""",
'depends': ['hr', 'calendar', 'resource'],
'data': [
'data/report_paperformat.xml',
'security/ir.model.access.csv',
'security/ir_rule.xml',
'hr_holidays_workflow.xml',
'hr_holidays_view.xml',
'hr_holidays_data.xml',
'hr_holidays_report.xml',
'views/report_hr_holidays_summary.xml',
'report/hr_holidays_report_view.xml',
'report/available_holidays_view.xml',
'wizard/hr_holidays_summary_department_view.xml',
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="paperformat_hrsummary" model="report.paperformat">
<field name="name">Holidays Summary</field>
<field name="default" eval="True"/>
<field name="format">custom</field>
<field name="page_height">297</field>
<field name="page_width">210</field>
<field name="orientation">Landscape</field>
<field name="margin_top">30</field>
<field name="margin_bottom">23</field>
<field name="margin_left">5</field>
<field name="margin_right">5</field>
<field name="header_line" eval="False"/>
<field name="header_spacing">20</field>
<field name="dpi">90</field>
</record>
</data>
</openerp>
+13 -9
View File
@@ -2,14 +2,18 @@
<openerp>
<data>
<report id="report_holidays_summary"
string="Leaves Summary"
model="hr.holidays"
name="holidays.summary"
xsl="hr_holidays/report/holidays_summary.xsl"
auto="False"
menu="False"/>
<report
id="report_holidays_summary"
string="Leaves Summary"
model="hr.holidays"
report_type="qweb-pdf"
name="hr_holidays.report_holidayssummary"
file="hr_holidays.report_holidayssummary"
menu="False"/>
<record id="report_holidays_summary" model="ir.actions.report.xml">
<field name="paperformat_id" ref="hr_holidays.paperformat_hrsummary"/>
</record>
</data>
</openerp>
</openerp>
@@ -1,259 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:import href="hr_custom_default.xsl"/>
<xsl:import href="hr_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="left" />
<paraStyle name="normal-title" fontName="Helvetica" fontSize="10" alignment="center"/>
<paraStyle name="digits" fontName="Helvetica" fontSize="6" alignment="left"/>
<paraStyle name="title" fontName="Helvetica" fontSize="18" alignment="center" />
<paraStyle name="dept" fontName="Helvetica-Bold" fontSize="8" alignment="left" />
<paraStyle name="employee" fontName="Helvetica-Bold" fontSize="6" textColor="black" />
<paraStyle name="leaveid" fontName="Helvetica" fontSize="6" alignment="center" />
<paraStyle name="print-date" fontName="Helvetica" fontSize="11" alignment="right" />
<paraStyle name="sum" fontName="Helvetica-BoldOblique" fontSize="6" alignment="left" />
<paraStyle name="company" textColor="purple" fontName="Helvetica-Bold" fontSize="11" alignment="left"/>
<blockTableStyle id="header">
<blockAlignment value="LEFT" start="0,0" stop="-1,-1"/>
<blockFont name="Helvetica" size="8" start="0,0" stop="-1,-1"/>
<blockValign value="TOP"/>
</blockTableStyle>
<blockTableStyle id="products">
<blockAlignment value="CENTER" start="1,0" stop="-1,-1"/>
<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"/>
<blockFont name="Helvetica-Bold" size="8" start="0,-1" stop="-1,-1"/>
<blockValign value="TOP"/>
</blockTableStyle>
<blockTableStyle id="legend">
<blockAlignment value="CENTER" start="0,0" stop="-1,-1" />
<blockFont name="Helvetica" size="7" start="0,0" stop="-1,-1"/>
<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"/>
<blockBackground colorName="#FFFFFF" start="0,0" stop="-1,-1"/>
<xsl:for-each select="/report/legend">
<blockBackground>
<xsl:attribute name="colorName">
<xsl:value-of select="attribute::color" />
</xsl:attribute>
<xsl:attribute name="start">
<xsl:text>0,</xsl:text>
<xsl:value-of select="attribute::row" />
</xsl:attribute>
<xsl:attribute name="stop">
<xsl:text>0,</xsl:text>
<xsl:value-of select="attribute::row" />
</xsl:attribute>
</blockBackground>
</xsl:for-each>
<blockValign value="TOP"/>
</blockTableStyle>
<blockTableStyle id="month">
<blockAlignment value="CENTER" start="1,0" stop="-1,-1" />
<blockFont name="Helvetica" size="5" start="0,0" stop="-1,-1"/>
<blockFont name="Helvetica-BoldOblique" size="4.5" start="-1,0" stop="-1,-1"/>
<blockBackground colorName="#FFFFFF" start="1,0" stop="-2,1"/>
<xsl:for-each select="/report/days/dayy[@name='Sat' or @name='Sun']">
<xsl:variable name="col" select="attribute::cell" />
<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>
<xsl:for-each select="/report/info">
<xsl:variable name="val" select="attribute::val" />
<xsl:variable name="col" select="attribute::number" />
<xsl:variable name="row" select="attribute::id" />
<xsl:for-each select="/report/legend">
<xsl:variable name="val_id" select="attribute::id" />
<xsl:variable name="color" select="attribute::color" />
<xsl:if test="$val_id = $val ">
<blockBackground>
<xsl:attribute name="colorName"><xsl:value-of select="$color" /></xsl:attribute>
<xsl:attribute name="start">
<xsl:value-of select="$col" />
<xsl:text>,</xsl:text>
<xsl:value-of select="$row + 1" />
</xsl:attribute>
<xsl:attribute name="stop">
<xsl:value-of select="$col" />
<xsl:text>,</xsl:text>
<xsl:value-of select="$row + 1" />
</xsl:attribute>
</blockBackground>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
<xsl:for-each select="report/employee">
<xsl:variable name="dept" select="attribute::id" />
<xsl:variable name="row" select="attribute::row" />
<xsl:if test="$dept = 1">
<blockBackground>
<xsl:attribute name="colorName">lightgrey</xsl:attribute>
<xsl:attribute name="start">
<xsl:text>0,</xsl:text>
<xsl:value-of select="$row +1" />
</xsl:attribute>
<xsl:attribute name="stop">
<xsl:text>0,</xsl:text>
<xsl:value-of select="$row +1" />
</xsl:attribute>
</blockBackground>
</xsl:if>
</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">
<xsl:variable name="cols_header">
<xsl:text>13.7cm,13.7cm</xsl:text>
</xsl:variable>
<blockTable>
<xsl:attribute name="style">header</xsl:attribute>
<xsl:attribute name="colWidths"><xsl:value-of select="$cols_header"/></xsl:attribute>
<tr>
<xsl:for-each select="report/res">
<td>
<para>
</para>
</td>
<td>
<para>
</para>
</td>
</xsl:for-each>
</tr>
</blockTable>
<spacer length="1.0cm" />
<para style="title" t="1">Leaves Summary <xsl:value-of select="report/name" /></para>
<spacer length="0.5cm" />
<para style="normal-title" t="1">Analyze from <u><xsl:value-of select="report/from" /></u> to <u> <xsl:value-of select="report/to" /> </u> of the <u><xsl:value-of select="report/type" /></u> leaves. </para>
<spacer length="1.0cm" />
<xsl:variable name="cols_legend">
<xsl:text>0.7cm,5.0cm</xsl:text>
</xsl:variable>
<blockTable>
<xsl:attribute name="style">products</xsl:attribute>
<xsl:attribute name="colWidths"><xsl:value-of select="report/cols_months"/></xsl:attribute>
<tr>
<td>Month</td>
<xsl:for-each select="report/months">
<td>
<xsl:value-of select="attribute::name" />
</td>
</xsl:for-each>
<td> </td>
</tr>
</blockTable>
<blockTable>
<xsl:attribute name="style">month</xsl:attribute>
<xsl:attribute name="colWidths"><xsl:value-of select="report/cols" /></xsl:attribute>
<tr>
<td> </td>
<xsl:for-each select="report/days/dayy">
<td>
<xsl:value-of select="attribute::name" />
</td>
</xsl:for-each>
<td> </td>
</tr>
<tr>
<td><para>
<xsl:attribute name="style">employee</xsl:attribute>
Departments and Employees
</para>
</td>
<xsl:for-each select="report/days/dayy">
<td><para><xsl:attribute name="style">digits</xsl:attribute>
<xsl:value-of select="attribute::number" /></para>
</td>
</xsl:for-each>
<td>Sum</td>
</tr>
<xsl:apply-templates select="report/employee"/>
<xsl:for-each select="report/employee">
<xsl:variable name="id" select="attribute::id"/>
<xsl:variable name="rw" select="attribute::row"/>
<xsl:variable name="sum" select="attribute::sum"/>
<tr>
<td t="1">
<para>
<xsl:choose>
<xsl:when test="$id = 1">
<xsl:attribute name="style">dept</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="style">normal</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="attribute::name"/>
</para>
</td>
<xsl:for-each select="//report/days/dayy">
<xsl:variable name="cell" select="attribute::cell" />
<td>
<para><xsl:attribute name="style">digits</xsl:attribute>
<xsl:value-of select="//employee[@row=$rw]/time-element[@index=$cell]"/>
</para>
</td>
</xsl:for-each>
<td><para>
<xsl:attribute name="style">sum</xsl:attribute><xsl:value-of select="attribute::sum"/></para></td>
</tr>
</xsl:for-each>
</blockTable>
<spacer length="1cm" />
<condPageBreak height="1in" />
<blockTable>
<xsl:attribute name="style">legend</xsl:attribute>
<xsl:attribute name="colWidths"><xsl:value-of select="$cols_legend"/></xsl:attribute>
<tr>
<td>Color</td>
<td>Leave Type</td>
</tr>
<xsl:for-each select="report/legend">
<tr>
<td>
<para>
<xsl:attribute name="style">digits</xsl:attribute>
</para>
</td>
<td>
<para>
<xsl:attribute name="style">normal</xsl:attribute>
<xsl:value-of select="attribute::name"/>
</para>
</td>
</tr>
</xsl:for-each>
</blockTable>
</xsl:template>
</xsl:stylesheet>
@@ -19,236 +19,117 @@
#
##############################################################################
import datetime
import time
import openerp
from openerp.osv import fields, osv
from openerp.report.interface import report_rml
from openerp.report.interface import toxml
from openerp.report import report_sxw
from openerp.tools import ustr
from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
from openerp.osv import osv
from openerp.tools.translate import _
from openerp.tools import to_xml
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
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]
class HrHolidaySummaryReport(osv.AbstractModel):
_name = 'report.hr_holidays.report_holidayssummary'
def strToDate(dt):
if dt:
dt_date=datetime.date(int(dt[0:4]),int(dt[5:7]),int(dt[8:10]))
return dt_date
else:
return
def _get_header_info(self, start_date, holiday_type):
return {
'start_date': datetime.strptime(start_date, DEFAULT_SERVER_DATE_FORMAT).strftime('%Y-%m-%d'),
'end_date': (datetime.strptime(start_date, DEFAULT_SERVER_DATE_FORMAT) + relativedelta(days=59)).strftime('%Y-%m-%d'),
'holiday_type': 'Confirmed and Approved' if holiday_type == 'both' else holiday_type
}
def _get_day(self, start_date):
res = []
start_date = datetime.strptime(start_date, DEFAULT_SERVER_DATE_FORMAT)
for x in range(0, 60):
color = '#ababab' if start_date.strftime('%a') == 'Sat' or start_date.strftime('%a') == 'Sun' else ''
res.append({'day_str': start_date.strftime('%a'), 'day': start_date.day , 'color': color})
start_date = start_date + relativedelta(days=1)
return res
def emp_create_xml(self, cr, uid, dept, holiday_type, row_id, empid, name, som, eom):
display={}
if dept==0:
count=0
registry = openerp.registry(cr.dbname)
holidays_ids = registry['hr.holidays'].search(cr, uid, [('employee_id','in',[empid,False]), ('type', '=', 'remove')])
ids_date = registry['hr.holidays'].read(cr, uid, holidays_ids, ['date_from','date_to','holiday_status_id','state'])
def _get_months(self, start_date):
# it works for geting month name between two dates.
res = []
start_date = datetime.strptime(start_date, DEFAULT_SERVER_DATE_FORMAT)
end_date = start_date + relativedelta(days=59)
while start_date <= end_date:
last_date = start_date + relativedelta(day=1, months=+1, days=-1)
if last_date > end_date:
last_date = end_date
month_days = (last_date - start_date).days + 1
res.append({'month_name': start_date.strftime('%B'), 'days': month_days})
start_date += relativedelta(day=1, months=+1)
return res
for index in range(1,61):
diff=index-1
current=som+datetime.timedelta(diff)
def _get_leaves_summary(self, cr, uid, ids, start_date, empid, holiday_type, context=None):
res = []
count = 0
start_date = datetime.strptime(start_date, DEFAULT_SERVER_DATE_FORMAT)
end_date = start_date + relativedelta(days=59)
for index in range(0, 60):
current = start_date + timedelta(index)
res.append({'day': current.day, 'color': ''})
if current.strftime('%a') == 'Sat' or current.strftime('%a') == 'Sun':
res[index]['color'] = '#ababab'
# count and get leave summary details.
holidays_obj = self.pool['hr.holidays']
holiday_type = ['confirm','validate'] if holiday_type == 'both' else ['confirm'] if holiday_type == 'Confirmed' else ['validate']
holidays_ids = holidays_obj.search(cr, uid, [('employee_id', '=', empid), ('state', 'in', holiday_type), ('type', '=', 'remove'), ('date_from', '<=', str(end_date)), ('date_to', '>=', str(start_date))], context=context)
for holiday in holidays_obj.browse(cr, uid, holidays_ids, context=context):
date_from = datetime.strptime(holiday.date_from, DEFAULT_SERVER_DATETIME_FORMAT)
date_to = datetime.strptime(holiday.date_to, DEFAULT_SERVER_DATETIME_FORMAT)
for index in range(0, ((date_to - date_from).days + 1)):
if date_from >= start_date and date_from <= end_date:
res[(date_from-start_date).days]['color'] = holiday.holiday_status_id.color_name
count+=1
date_from += timedelta(1)
self.sum = count
return res
for item in ids_date:
if current >= strToDate(item['date_from']) and current <= strToDate(item['date_to']):
if item['state'] in holiday_type:
display[index]=item['holiday_status_id'][0]
count=count +1
else:
display[index]=' '
break
else:
display[index]=' '
else:
for index in range(1,61):
display[index]=' '
count=''
data_xml=['<info id="%d" number="%d" val="%s" />' % (row_id,x,display[x]) for x in range(1,len(display)+1) ]
# Computing the xml
xml = '''
%s
<employee row="%d" id="%d" name="%s" sum="%s">
</employee>
''' % (data_xml,row_id,dept, ustr(toxml(name)),count)
def _get_data_from_report(self, cr, uid, ids, data, context=None):
res = []
emp_obj = self.pool['hr.employee']
department_obj = self.pool['hr.department']
if 'depts' in data:
for department in department_obj.browse(cr, uid, data['depts'], context=context):
res.append({'dept' : department.name, 'data': [], 'color': self._get_day(data['date_from'])})
employee_ids = emp_obj.search(cr, uid, [('department_id', '=', department.id)], context=context)
employees = emp_obj.browse(cr, uid, employee_ids, context=context)
for emp in employees:
res[len(res)-1]['data'].append({
'emp': emp.name,
'display': self._get_leaves_summary(cr, uid, ids, data['date_from'], emp.id, data['holiday_type'], context=context),
'sum': self.sum
})
elif 'emp' in data:
employees = emp_obj.browse(cr, uid, data['emp'], context=context)
res.append({'data':[]})
for emp in employees:
res[0]['data'].append({
'emp': emp.name,
'display': self._get_leaves_summary(cr, uid, ids, data['date_from'], emp.id, data['holiday_type'], context=context),
'sum': self.sum
})
return res
return xml
def _get_holidays_status(self, cr, uid, ids, context=None):
res = []
holiday_obj = self.pool['hr.holidays.status']
holiday_ids = holiday_obj.search(cr, uid, [], context=context)
holiday_datas = holiday_obj.browse(cr, uid, holiday_ids, context=context)
for holiday in holiday_datas:
res.append({'color': holiday.color_name, 'name': holiday.name})
return res
class report_custom(report_rml):
def create_xml(self, cr, uid, ids, data, context):
registry = openerp.registry(cr.dbname)
obj_dept = registry['hr.department']
obj_emp = registry['hr.employee']
depts=[]
emp_id={}
rpt_obj = registry['hr.holidays']
rml_obj=report_sxw.rml_parse(cr, uid, rpt_obj._name,context)
cr.execute("SELECT name FROM res_company")
res=cr.fetchone()[0]
date_xml=[]
date_today=time.strftime('%Y-%m-%d %H:%M:%S')
date_xml +=['<res name="%s" today="%s" />' % (to_xml(res),date_today)]
cr.execute("SELECT id, name, color_name FROM hr_holidays_status ORDER BY id")
legend=cr.fetchall()
today=datetime.datetime.today()
first_date=data['form']['date_from']
som = strToDate(first_date)
eom = som+datetime.timedelta(59)
day_diff=eom-som
name = ''
if len(data['form'].get('emp', ())) == 1:
name = obj_emp.read(cr, uid, data['form']['emp'][0], ['name'])['name']
if data['form']['holiday_type']!='both':
type=data['form']['holiday_type']
if data['form']['holiday_type']=='Confirmed':
holiday_type=('confirm')
else:
holiday_type=('validate')
else:
type="Confirmed and Approved"
holiday_type=('confirm','validate')
date_xml.append('<from>%s</from>\n'% (str(rml_obj.formatLang(som.strftime("%Y-%m-%d"),date=True))))
date_xml.append('<to>%s</to>\n' %(str(rml_obj.formatLang(eom.strftime("%Y-%m-%d"),date=True))))
date_xml.append('<type>%s</type>'%(type))
date_xml.append('<name>%s</name>'%(name))
# date_xml=[]
for l in range(0,len(legend)):
date_xml += ['<legend row="%d" id="%d" name="%s" color="%s" />' % (l+1,legend[l][0],_(legend[l][1]),legend[l][2])]
date_xml += ['<date month="%s" year="%d" />' % (ustr(som.strftime('%B')), som.year),'<days>']
cell=1
if day_diff.days>=30:
date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som.replace(day=x).strftime('%a')),x-som.day+1) for x in range(som.day, lengthmonth(som.year, som.month)+1)]
else:
if day_diff.days>=(lengthmonth(som.year, som.month)-som.day):
date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som.replace(day=x).strftime('%a')),x-som.day+1) for x in range(som.day, lengthmonth(som.year, som.month)+1)]
else:
date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som.replace(day=x).strftime('%a')),x-som.day+1) for x in range(som.day, eom.day+1)]
cell=x-som.day+1
day_diff1=day_diff.days-cell+1
width_dict={}
month_dict={}
i=1
j=1
year=som.year
month=som.month
month_dict[j]=som.strftime('%B')
width_dict[j]=cell
while day_diff1>0:
if month+i<=12:
if day_diff1 > lengthmonth(year,i+month): # Not on 30 else you have problems when entering 01-01-2009 for example
som1=datetime.date(year,month+i,1)
date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som1.replace(day=x).strftime('%a')),cell+x) for x in range(1, lengthmonth(year,i+month)+1)]
i=i+1
j=j+1
month_dict[j]=som1.strftime('%B')
cell=cell+x
width_dict[j]=x
else:
som1=datetime.date(year,month+i,1)
date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som1.replace(day=x).strftime('%a')),cell+x) for x in range(1, eom.day+1)]
i=i+1
j=j+1
month_dict[j]=som1.strftime('%B')
cell=cell+x
width_dict[j]=x
day_diff1=day_diff1-x
else:
years=year+1
year=years
month=0
i=1
if day_diff1>=30:
som1=datetime.date(years,i,1)
date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som1.replace(day=x).strftime('%a')),cell+x) for x in range(1, lengthmonth(years,i)+1)]
i=i+1
j=j+1
month_dict[j]=som1.strftime('%B')
cell=cell+x
width_dict[j]=x
else:
som1=datetime.date(years,i,1)
i=i+1
j=j+1
month_dict[j]=som1.strftime('%B')
date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som1.replace(day=x).strftime('%a')),cell+x) for x in range(1, eom.day+1)]
cell=cell+x
width_dict[j]=x
day_diff1=day_diff1-x
date_xml.append('</days>')
date_xml.append('<cols>3.5cm%s,0.4cm</cols>\n' % (',0.4cm' * (60)))
date_xml = ''.join(date_xml)
st='<cols_months>3.5cm'
for m in range(1,len(width_dict)+1):
st+=',' + str(0.4 *width_dict[m])+'cm'
st+=',0.4cm</cols_months>\n'
months_xml =['<months number="%d" name="%s"/>' % (x, _(month_dict[x])) for x in range(1,len(month_dict)+1) ]
months_xml.append(st)
emp_xml=''
row_id=1
if data['model'] == 'hr.employee':
for items in obj_emp.read(cr, uid, data['form']['emp'], ['id', 'name']):
emp_xml += emp_create_xml(self, cr, uid, 0, holiday_type, row_id, items['id'], items['name'], som, eom)
row_id = row_id +1
elif data['model']=='ir.ui.menu':
for dept in obj_dept.browse(cr, uid, data['form']['depts'], context=context):
emp_ids = obj_emp.search(cr, uid, [('department_id', '=', dept.id)], context=context)
if emp_ids==[]:
continue
dept_done=0
for item in obj_emp.read(cr, uid, emp_ids, ['id', 'name']):
if dept_done==0:
emp_xml += emp_create_xml(self, cr, uid, 1, holiday_type, row_id, dept.id, dept.name, som, eom)
row_id = row_id +1
dept_done=1
emp_xml += emp_create_xml(self, cr, uid, 0, holiday_type, row_id, item['id'], item['name'], som, eom)
row_id = row_id +1
header_xml = '''
<header>
<date>%s</date>
<company>%s</company>
</header>
''' % (str(rml_obj.formatLang(time.strftime("%Y-%m-%d"),date=True))+' ' + str(time.strftime("%H:%M")),to_xml(registry['res.users'].browse(cr,uid,uid).company_id.name))
# Computing the xml
xml='''<?xml version="1.0" encoding="UTF-8" ?>
<report>
%s
%s
%s
%s
</report>
''' % (header_xml,months_xml,date_xml, ustr(emp_xml))
return xml
report_custom('report.holidays.summary', 'hr.holidays', '', 'addons/hr_holidays/report/holidays_summary.xsl')
def render_html(self, cr, uid, ids, data=None, context=None):
report_obj = self.pool['report']
holidays_report = report_obj._get_report_from_name(cr, uid, 'hr_holidays.report_holidayssummary')
selected_records = self.pool['hr.holidays'].browse(cr, uid, ids, context=context)
docargs = {
'doc_ids': ids,
'doc_model': holidays_report.model,
'docs': selected_records,
'get_header_info': self._get_header_info(data['form']['date_from'], data['form']['holiday_type']),
'get_day': self._get_day(data['form']['date_from']),
'get_months': self._get_months(data['form']['date_from']),
'get_data_from_report': self._get_data_from_report(cr, uid, ids, data['form'], context=context),
'get_holidays_status': self._get_holidays_status(cr, uid, ids, context=context),
}
return report_obj.render(cr, uid, ids, 'hr_holidays.report_holidayssummary', docargs, context=context)
@@ -1,36 +0,0 @@
<?xml version = '1.0' encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template name="first_page_graphics_corporation">
<!--logo-->
<fill color="black"/>
<stroke color="black"/>
<setFont name="DejaVuSans" size="8"/>
<drawString x="1.3cm" y="19.5cm"><xsl:value-of select="//report/header/date"/></drawString>
<setFont name="DejaVuSans-Bold" size="10"/>
<drawString x="13.8cm" y="19.5cm"><xsl:value-of select="//report/header/company"/></drawString>
<stroke color="#000000"/>
<lines>1.3cm 19.3cm 28.5cm 19.3cm</lines>
</xsl:template>
<xsl:template name="other_pages_graphics_corporation">
<!--logo-->
<fill color="black"/>
<stroke color="black"/>
<setFont name="DejaVuSans" size="8"/>
<drawString x="1.3cm" y="19.5cm"><xsl:value-of select="//report/header/date"/></drawString>
<setFont name="DejaVuSans-Bold" size="10"/>
<drawString x="27.8cm" y="19.5cm"><xsl:value-of select="//report/header/company"/></drawString>
<stroke color="#000000"/>
<lines>1.3cm 19.3cm 28.5cm 19.3cm</lines>
</xsl:template>
<xsl:template name="first_page_frames">
<frame id="col1" x1="2.0cm" y1="2.5cm" width="24.7cm" height="17cm"/>
</xsl:template>
<xsl:template name="other_pages_frames">
<frame id="col1" x1="2.0cm" y1="2.5cm" width="24.7cm" height="17cm"/>
</xsl:template>
</xsl:stylesheet>
@@ -1,37 +0,0 @@
<?xml version = '1.0' encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template name="first_page_graphics_report"/>
<xsl:template name="other_pages_graphics_report"/>
<xsl:template name="rml">
<document filename="example.pdf">
<template pageSize="29.7cm,21cm" leftMargin="2.0cm" rightMargin="2.0cm" topMargin="2.0cm" bottomMargin="2.0cm" title="Timesheets" author="Generated by Odoo, Fabien Pinckaers" allowSplitting="20">
<pageTemplate id="first_page">
<pageGraphics>
<xsl:call-template name="first_page_graphics_corporation"/>
</pageGraphics>
<xsl:call-template name="first_page_frames"/>
</pageTemplate>
<pageTemplate id="other_pages">
<pageGraphics>
<xsl:call-template name="other_pages_graphics_corporation"/>
</pageGraphics>
<xsl:call-template name="other_pages_frames"/>
</pageTemplate>
</template>
<stylesheet>
<xsl:call-template name="stylesheet"/>
</stylesheet>
<story>
<xsl:call-template name="story"/>
</story>
</document>
</xsl:template>
</xsl:stylesheet>
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="report_holidayssummary">
<t t-call="report.html_container">
<t t-call="report.internal_layout">
<div class="page">
<h3 class="mb32">Leaves Summary</h3>
<t t-set="info" t-value="get_header_info"/>
<h3 class="text-center mb32">
Analyze from <u><t t-esc="info['start_date']"/></u> to <u><t t-esc="info['end_date']"/></u> of the <u><t t-esc="info['holiday_type']"/></u> Leaves.
</h3>
<table class="table table-bordered mb32" style="table-layout:auto">
<thead>
<tr>
<th>Month</th>
<t t-foreach="get_months" t-as="month">
&lt;th class="text-center" colspan=<t t-esc="month['days']"/>&gt;<t t-esc="month['month_name']"/>&lt;/th&gt;
</t>
<th/>
</tr>
<tr>
<td rowspan="2">
<strong>Departments and Employees</strong>
</td>
<t t-foreach="get_day" t-as="day">
&lt;td class="text-center oe_leftfit oe_rightfit" style="background-color:<t t-esc="day['color']"/>!important; font-size: 8px; min-width: 18px"&gt; <t t-esc="day['day_str']"/>&lt;/td&gt;
</t>
<td/>
</tr>
<tr>
<t t-foreach="get_day" t-as="day">
&lt;td class="text-center oe_leftfit oe_rightfit" style="background-color:<t t-esc="day['color']"/>!important; font-size: 10px" &gt; <t t-esc="day['day']"/>&lt;/td&gt;
</t>
<td class="text-center">Sum</td>
</tr>
</thead>
<tbody>
<t t-foreach="get_data_from_report" t-as="obj">
<tr t-if="'dept' in obj">
<td style="background-color:#ababab">
<strong><t t-esc="obj['dept']"/></strong>
</td>
<t t-foreach="obj['color']" t-as="c">
&lt;td style=background-color:<t t-esc="c['color']"/> !important/&gt;
</t>
<td/>
</tr>
<tr t-foreach="obj['data']" t-as="emp">
<td><t t-esc="emp['emp']"/></td>
<t t-foreach="emp['display']" t-as="details">
&lt;td style=background-color:<t t-esc="details['color']"/> !important /&gt;
</t>
<td class="text-center"><strong><t t-esc="emp['sum']"/></strong></td>
</tr>
</t>
</tbody>
</table>
<div class="col-xs-3 col-xs-offset-5 mt32">
<table class="table table-bordered">
<thead>
<tr>
<th class="col-xs-1">Color</th>
<th class="text-center">Leave Type</th>
</tr>
</thead>
<tbody>
<tr t-foreach="get_holidays_status" t-as="status">
&lt;td style=background-color:<t t-esc="status['color']"/>!important &gt;&lt;/td&gt;
<td><t t-esc="status['name']"/></td>
</tr>
</tbody>
</table>
</div>
</div>
</t>
</t>
</template>
</data>
</openerp>
@@ -45,11 +45,7 @@ class hr_holidays_summary_dept(osv.osv_memory):
raise UserError(_('You have to select at least one Department. And try again.'))
datas = {
'ids': [],
'model': 'ir.ui.menu',
'model': 'hr.department',
'form': data
}
return {
'type': 'ir.actions.report.xml',
'report_name': 'holidays.summary',
'datas': datas,
}
return self.pool['report'].get_action(cr, uid, data['depts'], 'hr_holidays.report_holidayssummary', data=datas, context=context)
@@ -38,14 +38,10 @@ class hr_holidays_summary_employee(osv.osv_memory):
def print_report(self, cr, uid, ids, context=None):
data = self.read(cr, uid, ids, context=context)[0]
data['emp'] = context['active_ids']
data['emp'] = context.get('active_ids',[])
datas = {
'ids': [],
'model': 'hr.employee',
'form': data
}
return {
'type': 'ir.actions.report.xml',
'report_name': 'holidays.summary',
'datas': datas,
}
return self.pool['report'].get_action(cr, uid, data['emp'], 'hr_holidays.report_holidayssummary', data=datas, context=context)
+2
View File
@@ -13,6 +13,7 @@
<link href="/web/static/lib/bootstrap/css/bootstrap.css" rel="stylesheet"/>
<link href="/website/static/src/css/website.css" rel="stylesheet"/>
<link href="/web/static/lib/fontawesome/css/font-awesome.css" rel="stylesheet"/>
<link href="/base/static/src/css/description.css" rel="stylesheet"/>
<style type="text/css">
<t t-call="report.style"/>
</style>
@@ -149,6 +150,7 @@
<link href="/web/static/lib/bootstrap/css/bootstrap.css" rel="stylesheet"/>
<link href="/website/static/src/css/website.css" rel="stylesheet"/>
<link href="/web/static/lib/fontawesome/css/font-awesome.css" rel="stylesheet"/>
<link href="/base/static/src/css/description.css" rel="stylesheet"/>
<style type='text/css'><t t-raw="css"/></style>
<t t-if="subst is True">
<script src='/report/static/src/js/subst.js'></script>