I built a module to return my employee payslip in a row format which is working perfectly.
I however have a challenge, when I ask the report to be generated it brings all the payslips not according to the date selected.
However can I make the report bring only the date selected.
My code is below:
import time
from datetime import datetime
from dateutil import relativedelta
from openerp.osv import osv
from openerp.report import report_sxw
from openerp import models
class bluspiral_sche_report_parser(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context=None):
if context is None:
context = {}
super(bluspiral_sche_report_parser, self).__init__(cr, uid, name, context=context)
self.localcontext.update({ 'get_payslips': self.get_payslips, 'sum_cal': self.sum_cal,
})
self.context = context
def set_context(self, objects, data, ids, report_type=None):
date_from = data['form'].get('date_from', time.strftime('%Y-%m-%d'))
date_to = data['form'].get('date_to', str(datetime.now() + relativedelta.relativedelta(months=+1, day=1, days=-1))[:10])
return super(bluspiral_sche_report_parser, self).set_context(objects, data, ids, report_type=report_type)
def sum_cal(self):
return self.total_cash
def get_payslips(self):
ids = self.pool['hr.payslip'].search(self.cr, self.uid, [('struct_id.name', 'in', ['Auxiliary_Accord_Structure', 'IT_Accord_Structure'])], context=self.context)
payslips = self.pool['hr.payslip'].read(self.cr, self.uid, ids, context=self.context)
mp = []
self.total_cash = 0.0
for payslip in payslips:
row = {'employee_id': payslip['employee_id'][1],
}
lines = self.pool['hr.payslip.line'].read(self.cr, self.uid, payslip['line_ids'], context=self.context)
for line in lines:
row[line['code']] = line['total']
self.total_cash += line['total']
mp.append(row)
return mp
class report_generalledger(osv.AbstractModel):
_name = 'report.bluspiral_sche.cash_report'
_inherit = 'report.abstract_report'
_template = 'bluspiral_sche.cash_report'
_wrapped_report_class = bluspiral_sche_report_parser
class PayrollSchedule(models.Model):
_name = 'bluspiral.sche.schedule'
def print_payroll_schedule_report(self, cr, uid, ids, data, context=None):
if context is None:
context = {}
context['portrait'] = True
return self.pool['report'].get_action(cr, uid, [], 'bluspiral_sche.cash_report', context=context)