Odoo Help


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.


print value of a field in wizard to report?

on 10/24/13, 10:09 AM 4,093 views

I need to pass the value of my two fields i.e date_from n date_to from my wizard to the report it calls/prints. Following is my code. This is working fine but only problem is i am not able to find how to print these two fields. Any help is appreciated.

class my_wizard_report(osv.osv_memory):

    _name = 'my.wizard.report'
##    _inherit = 'account.invoice'
    _description = 'Test Report'  

    _columns = {
        'date_from':fields.date('Date From',store=True),
        'date_to':fields.date('Date To',store=True),
        'invoice_ids':fields.many2many('account.invoice', string='Filter on invoices',help="Only selected invoices will be printed"),

    _defaults = {
        'date_from': lambda *a: time.strftime('%Y-%m-%d'),
        'date_to': lambda *a: time.strftime('%Y-%m-%d'),

    def print_report(self, cr, uid, ids, context=None):
        datas = {}
        if context is None:
            context = {}
        data = self.read(cr, uid, ids,['date_from', 'date_to', 'invoice_ids'], context=context)
        date_from = data[0]['date_from'] 
        date_to = data[0]['date_to']
        obj = self.pool.get('account.invoice')
        ids = obj.search(cr, uid, [('date_invoice','>=',date_from),('date_invoice','<=',date_to)])
        datas = {
                 'ids': ids,
                 'model': 'account.invoice',
                 'form': data
        return {'type': 'ir.actions.report.xml', 'report_name': 'account.invoice.rnd5c3tV', 'datas': datas}


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

<!-- cancel order  -->

        <record id="view_my_wiz_form" model="ir.ui.view">
            <field name="name">print.report.form</field>
            <field name="model">my.wizard.report</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Print Report">
                    <group colspan="4" >
                        <field name="date_from" filter_domain="[('date_invoice','&gt;=',self)]" />
                        <field name="date_to" filter_domain="[('date_invoice','&lt;=',self)]"  />
                        <separator string="Print Only" colspan="4" />
                        <group colspan = "4">
                            <field name="invoice_ids" colspan="4" nolabel="1"/>
                    <group colspan="4" col="6">                     
                        <button  icon="gtk-ok" name="print_report" string="Print" type="object"/>

        <record id="action_my_wiz_form" model="ir.actions.act_window">
            <field name="name">Print Report</field>
            <field name="res_model">my.wizard.report</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
           <field name="view_id" ref="view_my_wiz_form"/>
           <field name="target">new</field>        

        <act_window id="action_my_wiz_form_values"
            key2="client_action_multi" name="Print Report"
            res_model="my.wizard.report" src_model="add.penalty"
            view_mode="form" target="new" view_type="form"/>





Abhishek H Menon
On 10/24/13, 10:26 AM

Use data = self.read(cr, uid, ids,)[-1] in your print_report method and you will get the details that you entered via the wizard. It will a dictionary in which you will have keys and values as per the above defined fields

babis peroukas
On 10/28/13, 3:33 AM

I copy the code from sale.py that I edited to send some fields to my invoice.

   def _prepare_invoice(self, cr, uid, order, lines, context=None):
    """Prepare the dict of values to create the new invoice for a
       sales order. This method may be overridden to implement custom
       invoice generation (making sure to call super() to establish
       a clean extension chain).

       :param browse_record order: sale.order record to invoice
       :param list(int) line: list of invoice line IDs that must be
                              attached to the invoice
       :return: dict of value to create() the invoice
    if context is None:
        context = {}
    journal_ids = self.pool.get('account.journal').search(cr, uid,
        [('type', '=', 'sale'), ('company_id', '=', order.company_id.id)],
    if not journal_ids:
        raise osv.except_osv(_('Error!'),
            _('Please define sales journal for this company: "%s" (id:%d).') % (order.company_id.name, order.company_id.id))
    invoice_vals = {
        'name': order.client_order_ref or '',
        'origin': order.name,
        'type': 'out_invoice',
        'reference': order.client_order_ref or order.name,
        'account_id': order.partner_id.property_account_receivable.id,
        'partner_id': order.partner_invoice_id.id,
        'journal_id': journal_ids[0],
        'invoice_line': [(6, 0, lines)],
        'currency_id': order.pricelist_id.currency_id.id,
        'comment': order.note,
        'payment_term': order.payment_term and order.payment_term.id or False,
        'fiscal_position': order.fiscal_position.id or order.partner_id.property_account_position.id,
        'date_invoice': context.get('date_invoice', False),
        'company_id': order.company_id.id,
        'user_id': order.user_id and order.user_id.id or False,
        'x_destplace': order.x_destplace,
        'x_loadplace': order.x_loadplace,
        'x_vehivle': order.x_vehicle

    # Care for deprecated _inv_get() hook - FIXME: to be removed after 6.1
    invoice_vals.update(self._inv_get(cr, uid, order, context=context))
    return invoice_vals

I 've added the x_ fields in both models (sales.order and account.invoice) and with this addition to the code (in invoice_vals) it just copies their values. So if you want to send those values to your invoice and then print it you have to create something like a _prepare_invoice function.

the account.invoice model doesn't contain these fields, these are in the wizard.

on 10/28/13, 4:09 AM

Ah then you have to send those fields from your form to the account.invoice. Wait a minute I 'll copy a code.

babis peroukas
on 10/28/13, 4:11 AM

sry I dont know how to post a code clearly

babis peroukas
on 10/28/13, 4:23 AM

Also check this video http://www.youtube.com/watch?v=5dDoPcm6pVM

babis peroukas
on 10/28/13, 7:03 AM
On 10/25/13, 2:22 AM
I didnt understand your requirement properly, If you want to print something you can use
import logging 
_logger = logging.getLogger(__name__)
_logger.info('Create a with vals ..............................%s', res)
Is that your requirement?

I don't understand what you said above but my requirement is very simple. The report is created by me already using Openoffice(base report designer) then i created a wizard in my custom module, i defined two fields date_from and date_to on the wizard and whatever dates are selected there i want to print them on my report which i called from here. Now its clear i hope. Please let me know if you have a solution to it.

on 10/28/13, 3:09 AM

I added few screen shots above.

on 10/28/13, 5:43 AM

@evon sorry I dnt have any idea :(

on 10/31/13, 8:32 AM

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)


Asked: 10/24/13, 10:09 AM
Seen: 4093 times
Last updated: 3/16/15, 8:10 AM