在odoo-8中输入QWEB报告中的参数

时间:2016-01-15 05:42:25

标签: openerp odoo-8 openerp-8

美好的一天!有人可以帮助我解决我的问题吗,我已经在odoo中创建了一个报告,该报告有一个用户输入来按员工和日期周期过滤报告,然后生成pdf报告,如Odoo中的Leave Per Department Report,但生成的pdf是空。我只是复制了每个部门的报告代码。

这是我的示例代码,这是报告菜单中的菜单 瞬态模型

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

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

我的QWEB报告

    <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'"/>

我的QWEB代码太长而无法发布,我是否遗漏了将价值传递给报告的内容?请帮忙 再次感谢您的帮助

1 个答案:

答案 0 :(得分:2)

您的报告视图还需要一个AbstractModel。 我有我为POS销售详细信息报告尝试过的示例代码。 像你一样的瞬态模型!

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)

您需要添加的示例AbstractModel!

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

我不确定,但我认为您需要为报告视图添加model.AbstractModel。