Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Launch a report through a wizard in OpenERP 6.1

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 782
    Comment on it

    Printing a report from a button a wizard is quite easy and very fast in execution. Its really awesome when you created a report on your own format using OpenOffice or any other report designing tool for OpenERP, and you can call that report on a single click of a button.

    I created a report and sent it to server earlier, now I wanted to launch the same report using a wizard. I had to create wizard for this. my wizard folder:

    __init__.py

    print_my_report.py (wizard class)

    I created a wizard, added the necessary fields, and a many2many relation as my report belongs to the invoice module(report), so that i can get a list of the invoices. Notice the print_report function that tells to fetch those invoices that fall in the given date range, then return the report name. I used my own report so I used technical name of my report. Type should always be ir.actions.report.xml.

    class print_my_report(osv.osv_memory):
        _name = 'print.my.report'
        _description = 'Daly Sale 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.rndKhHYk', 'datas': datas}  
    
    print_my_report()
    

    Then print_my_report_view.xml, just need to create a view for wizard as you wish and simply add the button and call the print_report method on it.

    <record id="print_my_report_view" model="ir.ui.view">
                <field name="name">My Report</field>
                <field name="model">print.my.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)]"  />
                        </group>
                            <separator string="Print Only" colspan="4" />
                            <group colspan = "4">
                                <field name="invoice_ids" colspan="4" nolabel="1"/>
                            </group>
                        <group colspan="4" col="6">                     
                            <button  icon="gtk-ok" name="print_report" string="Print" type="object"/>
                       </group>
                </form>
                </field>
            </record>   
    

    That's about it, all the best!

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: