Skip to Content
Menu
This question has been flagged
2 Replies
12199 Views

I want to create menu like Reporting/Point of sale/Sale Details and print my report while clicking Print Report button. I have created a report which comes under Settings/Technical/Actions/Reports.How can i integrate my report to button click and how to create pop up? Any one please help?

Avatar
Discard
Best Answer

hello, you can use wizard to achieve this, the wizard is as normal model but it will inherit 'osv.osv_memory'

class print_report_wiz(osv.osv_memory):
    _name = "print.report.wiz"

    _columns = {
        'name': fields.many2one('name.name', 'Name',required = True),
    }

the xml view is also as normal but add:

<field name = "target">new</field>

to the action,

the print button will return a dictionary like:

return {
            'type': 'ir.actions.report.xml',
            'report_name': 'your.report.name',
            'datas': datas,
            'context': context,
        }

also you can see these questions:

print report from wizard

create a wizard

Updated

on the print function of the wizard,

first you can fetch the wizard data e.g date_from , date_to, name ....

by using this:

wiz_data = self.read(cr, uid, ids[0], context = context)

now you can access them by using dictionary key e.g : wiz_date[date_from]

after that you can use these values to formulate sql query to fetch the ids you want...

cr.execute('SELECT id '\
                        'FROM table_name ' \
                        "WHERE date BETWEEN %s AND %s", (wiz_data['from_date'], wiz_data['to_date']))

then you have to fetch these ids you can use for e.g:

res_ids = [id for id, in cr.fetchall()]

at this time , you have your desired ids ...

the datas dict will be passed to your report , with three keys: model, ids of this model, and form which contains the wiz_data could be like this:

datas = {
            'ids': res_ids,
            'model': 'model.name',
            'form': wiz_data,
        }

now your report has all information needed,

the "objects" contains a browse record of the given ids on datas dict... also you can use the wizard information in your report like this:

if you want to print e.g this report from date ... to date ...

you can use:

[[ data['form']['from_date'] ]] and [[ data['form']['to_date'] ]]

remember, the form contains your fetched wizard's data ...

also you can filter your data using the report python file by declaring a function to do some filtering...

it depends on your requirements , and it will be a performance issue to filter your data on the wizard function's or in a report's python file [for e.g you'll use the returns values in another function on the python file]....

I hope it'll helps you ....

Regards..

Avatar
Discard
Author

I changed code but still it didnt create any menu under "Reporting" what is the issue?

Author Best Answer
i created the wizard and my code is (calldetails/wizard/calldata_view.xml)
<?xml version="1.0" encoding="utf-8"?>
<openerp>
  <data>

<record model="ir.ui.view" id="wizard_with_step_form">

 <field name="model">calldata.print.report.wiz</field>
    <field name="type">form</field>
    <field name="arch" type="xml">
      <form string="Wizard with step" version="7.0">
    <field name="one" />
 </form>
    </field>
   </record>
 <record model="ir.actions.act_window" id="action_calldata_form1">
   <field name="name">Calldetails</field>
   <field name="res_model">calldata.print.report.wiz</field>
</record>
<act_window name="Create Combined Picking" res_model="calldata.print.report.wiz" src_model="calldata.print.report.wiz" key2="client_action_multi" multi="True" view_mode="form" view_type="form" target="new" id="action_stock_picking_combined_wizard" />
</data>
</openerp>

Object file is(calldetails/wizard/calldata_print.py)
from openerp.osv import fields, osv


class calldata_print_report_wiz(osv.osv_memory):
    _name = "calldata.print.report.wiz"

    _columns = {
        'one':  fields.char('Name 1',),}

calldata_print_report_wiz()

i added calldata_print in wizard/__init__.py  ,wizard in calldetails/__init__.py and calldata_view.xml in __openerp__.py stil it didnt create any menu under "Reporting"
 What is the issue. Please help
Avatar
Discard

you didn't add a menuitem to your view, just try to add a menuitem and specify the the action and parent menu,...

also i think you missing: field name = "name" on the form view,..

Author

It worked :). Thanks alot Ahmed

Author

While clicking print it shoes error "RML is not available at specified location or not enough data to print! (None, None, None)". please help

Author

Corrected. i was given invalid path for rml

Author

helo i have created report and while clicking print it prints all data.but filtering not works .can you please help?what is the value i should pass with datas dictionary and with datas['form']?

Hello, I have updated my answer...Regards..

Author

@Ahmed M.Elmubarak , It worked thanks alot for your help !!

Author

i want remove repetition from my select box .my code is def _sel_func(self, cr, uid,context=None): cr.execute("select distinct on(caller) id,caller FROM calldata1 order by caller") result = cr.fetchall() lst = [] for r in result: dct = {} dct['id'] = r[o] dct['name'] = r[1] lst.append(dct) res_ids = [(r['id'], r['name']) for r in lst] return res_ids How to achive this?

hello @Anuradha, I cannot get what is the problem actually, but if your list has a repetition you can simply convert it to a set and then make it list again,

but note it seems it is another question than the title, I suggest to make a new question, or you can send to me a msg via my LinkedIn profile, it is already in my profile!.

Thanks

Author

I have posted another question http://help.openerp.com/question/29526/how-to-show-distict-data-in-many-to-one-filed/ please check or please send me your email id

Where do I find the setting for the RML issue? "Corrected. i was given invalid path for rml" I get this trying to print an invoice, and I haven't done any coding in the system??

Related Posts Replies Views Activity
1
Nov 16
4352
1
Mar 15
4407
2
Feb 24
13929
1
Oct 22
5637
1
Aug 21
4039