Question

I am learning how to generates reports in OpenERP and specifically I am trying to be able to generate a report from a wizard but I am not able to find much documentation about it.

I am already able to generate a wizard and populate it with the fields I need.For it I created a sales_wizard class and an xml file with the structure of the wizard.

my sales_wizard.py is inside a wizard folder in my custom module and looks similar to this

class sales_wizard(osv.osv_memory):

    _name = 'sim.sales.wizard'
    print "Wizard IN"
    _rec_name = 'building'
    _columns = {
                'building':fields.many2one('sim.buildings','building',required=True,ondelete='cascade'),
                'period':fields.many2one('sim.periods','Period',required=True,ondelete='cascade')
                }

What I am lacking is the knowledge to understand how to connect the wizard with the creation of a report and how to pass the variables that are input in the wizard, in this case the building and the period

Any orientation,tip,link to the right direction will be much appreciated.

Was it helpful?

Solution

You can find many example of print report from wizard in openerp. Lets check in product module product_pricelist report & wizard.

In wizard when you open there is a button print, in print button in py side define code for send data to report

def print_report(self, cr, uid, ids, context=None):
        """
        To get the date and print the report
        @return : return report
        """
        if context is None:
            context = {}
        datas = {'ids': context.get('active_ids', [])}
        res = self.read(cr, uid, ids, ['price_list','qty1', 'qty2','qty3','qty4','qty5'], context=context)
        res = res and res[0] or {}
        res['price_list'] = res['price_list'][0]
        datas['form'] = res
        return {
            'type': 'ir.actions.report.xml',
            'report_name': 'product.pricelist',
            'datas': datas,
       }

and in .rml file file define a para like <para style="terp_default_Centre_8">[[ get_pricelist(data['form']['price_list']) ]]</para>

get_pricelist a function define in report file , where data['form']['price_list'] is a argument passed from wizard which used in function get_pricelist

Hope this will help

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top