Black and White
Black and White

Reputation: 452

Input Paramaters in QWEB Report in odoo-8

Good Day! Can someone help me with my problem, I've created a report in odoo, the report has a user input to filter the report by employee and date period before generating the pdf report like Leave Per Department Report in Odoo but when the generated pdf is empty. Ive just replicate the Leaves per Department Report code.

Here's my Sample Code this is the Menu in Reporting Menu Transient Model

class payslip_per_Employee(models.TransientModel):
_name = 'payroll.payslip.employee'

employee_id = fields.Many2one('hr.employee', 'Employee', required=True)
month_of_from = fields.Selection(genx.MONTH_SELECTION, 'From the Month of', required=True, default = 1)
month_quarter_from = fields.Selection(MONTH_QUARTER_SELECTION, 'Month Quarter', required=True, default = 1)
month_year_from = fields.Integer('Year', required=True, default = genx.YEAR_NOW)
month_of_to = fields.Selection(genx.MONTH_SELECTION, 'To the Month of', required=True, default = 12)
month_quarter_to = fields.Selection(MONTH_QUARTER_SELECTION, 'Month Quarter', required=True, default = 2)
month_year_to = fields.Integer('Year', required=True, default = genx.YEAR_NOW)

def print_report(self, cr, uid, ids, context=None):
    data = self.read(cr, uid, ids, context=context)[0]
    datas = {
         'ids': [],
         'model': 'ir.ui.menu',
         'form': data
        }
    return {
        'type': 'ir.actions.report.xml',
        'report_name': 'hr_payroll_ezra.report_payslip_employee',
        'datas': datas,
        }

My XML in Transient Model

    <data>

    <record id="view_payslip_per_employee" model="ir.ui.view">
        <field name="name">payroll.payslip.employee.form</field>
        <field name="model">payroll.payslip.employee</field>
        <field name="arch" type="xml">
        <form string="Payslip Employee">
            <group>
                <field name="employee_id" />
                <field name="month_of_from"/>
                <field name="month_quarter_from"/>
                <field name="month_year_from"/>

                <field name="month_of_to"/>
                <field name="month_quarter_to"/>
                <field name="month_year_to"/>
            </group>
            <footer>
                <button name="print_report" string="Print" type="object" class="oe_highlight"/> or
                <button string="Cancel" special="cancel" class="oe_link"/>
            </footer>
        </form>
        </field>
    </record>`enter code here`

    <record id="action_payslip_per_employee" model="ir.actions.act_window">
        <field name="name">Payslip Employee</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">payroll.payslip.employee</field>
        <field name="view_type">form</field>
        <field name="view_mode">form</field>
        <field name="target">new</field>
    </record>

    <menuitem
        name="Payslip Employee"
        parent="hr.menu_hr_reporting_timesheet"
        action="action_payslip_per_employee"
        id="menu_payslip_per_employee"
        icon="STOCK_PRINT"/>
</data>

My QWEB Report

    <data>
    <report
    id="payroll_payslip_employee_ezra"
    model="hr.payroll.detail"
    string="Employee Payslip"
    report_type="qweb-html"
    name="hr_payroll_ezra.report_payslip_employee"
    file="hr_payroll_ezra.report_payslip_employee"
    attachment_use="True"
    attachment="object.name+'.pdf'"/>

My QWEB Code is too long to post, did I miss something in passing the value to the reports? Please Help Thanks again for the help

Upvotes: 2

Views: 1361

Answers (1)

Nyein Mon Soe
Nyein Mon Soe

Reputation: 129

You need one more AbstractModel for your report view. I have sample code that I have tried for my POS Sales Details Report. Transient model like you have!

import psycopg2
import pytz

from odoo import api, fields, models
from odoo.exceptions import UserError
from datetime import datetime

class PosDetails(models.TransientModel):

_inherit = 'pos.details.wizard'

ticket_type = fields.Selection([('s','Single'),('g','Group')],string="By Ticket Type")
user_id = fields.Many2one(
    comodel_name='res.users', string='By Salesman',
    help="Person who uses the cash register. It can be a reliever, a student or an interim employee."
)

@api.multi
def generate_report(self):
    data = {'date_start': self.start_date, 'date_stop': self.end_date, 'ticket_type': self.ticket_type, 'user_id': self.user_id.id, 'config_ids': self.pos_config_ids.ids}
    return self.env['report'].get_action(
        [], 'point_of_sale.report_saledetails', data=data)

Sample AbstractModel that you need to add!

class ReportSaleDetails(models.AbstractModel):

_inherit = 'report.point_of_sale.report_saledetails'    

@api.model
def get_sale_details(self, date_start=False, date_stop=False, ticket_type=False, user_id=False, configs=False):
    """ Serialise the orders of the day information

    params: date_start, date_stop string representing the datetime of order
    """
    if not configs:
        configs = self.env['pos.config'].search([])

    user_tz = pytz.timezone(self.env.context.get('tz') or self.env.user.tz or 'UTC')
    today = user_tz.localize(fields.Datetime.from_string(fields.Date.context_today(self)))
    today = today.astimezone(pytz.timezone('UTC'))
    if date_start:
        date_start = fields.Datetime.from_string(date_start)
    else:
        # start by default today 00:00:00
        date_start = today

    if date_stop:
        # set time to 23:59:59
        date_stop = fields.Datetime.from_string(date_stop)
    else:
        # stop by default today 23:59:59
        date_stop = today + timedelta(days=1, seconds=-1)

    # avoid a date_stop smaller than date_start
    date_stop = max(date_stop, date_start)

    date_start = fields.Datetime.to_string(date_start)
    date_stop = fields.Datetime.to_string(date_stop)

if user_id != False:
    orders = self.env['pos.order'].search([
    ('date_order', '>=', date_start),
    ('date_order', '<=', date_stop),
    ('user_id','=', user_id),
    ('state', 'in', ['paid','invoiced','done']),
    ('config_id', 'in', configs.ids)])
elif user_id == False:
    orders = self.env['pos.order'].search([
    ('date_order', '>=', date_start),
    ('date_order', '<=', date_stop),
    ('state', 'in', ['paid','invoiced','done']),
    ('config_id', 'in', configs.ids)])

user_currency = self.env.user.company_id.currency_id

I'm not sure but I think you need to add model.AbstractModel for your report view.

Upvotes: 2

Related Questions