Odoo Help

Welcome!

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.

1

Print manually a report [TypeError: print_report() takes at most 7 arguments (11 given)]

By
William Mb
on 8/1/16, 12:09 PM 355 views

Hi everyone, 

Pls I try manually print a report this is the method action of a button that I use.

def clear_record_data(self):
    module_name = 'cookbook.recipe'    
    orm_button = self.env[module_name]         
    cr = self._cr     
    context = self._context     
    uid = self._uid     
    button_ids = orm_button.search([])     
    buttons = orm_button.browse(button_ids)     
    return orm_button.print_report(cr, uid, button_ids, module_name, buttons, context)

 

When the print_report method is call, I have this message


Traceback (most recent call last):

File "D:/odoo-8.0\openerp\http.py", line 544, in _handle_exception

return super(JsonRequest, self)._handle_exception(exception)

File "D:/odoo-8.0\openerp\http.py", line 581, in dispatch

result = self._call_function(**self.params)

File "D:/odoo-8.0\openerp\http.py", line 317, in _call_function

return checked_call(self.db, *args, **kwargs)

File "D:/odoo-8.0\openerp\service\model.py", line 118, in wrapper

return f(dbname, *args, **kwargs)

File "D:/odoo-8.0\openerp\http.py", line 314, in checked_call

return self.endpoint(*a, **kw)

File "D:/odoo-8.0\openerp\http.py", line 810, in __call__

return self.method(*args, **kw)

File "D:/odoo-8.0\openerp\http.py", line 410, in response_wrap

response = f(*args, **kw)

File "D:\odoo-8.0\addons\web\controllers\main.py", line 948, in call_button

action = self._call_kw(model, method, args, {})

File "D:\odoo-8.0\addons\web\controllers\main.py", line 936, in _call_kw

return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)

File "D:/odoo-8.0\openerp\api.py", line 268, in wrapper

return old_api(self, *args, **kwargs)

File "D:/odoo-8.0\openerp\api.py", line 399, in old_api

result = method(recs, *args, **kwargs)

File "D:\odoo-8.0\customs_addons\cookbook\models\button.py", line 38, in clear_record_data

return orm_button.print_report(cr, uid, button_ids, module_name, buttons, context)

File "D:/odoo-8.0\openerp\api.py", line 266, in wrapper

return new_api(self, *args, **kwargs)

File "D:/odoo-8.0\openerp\api.py", line 592, in new_api

result = method(self._model, cr, uid, self.ids, *args, **old_kwargs)

TypeError: print_report() takes at most 7 arguments (11 given)


you are mixin old and new api...

try smthg like: return orm_button.print_report(module_name, buttons) ?

Jérémy Kersten (jke)
on 8/1/16, 12:18 PM
0
William Mb
On 8/2/16, 9:35 AM

The python file

# -*- coding: utf-8 -*-
from openerp.osv import orm, fields
class ManualReport(orm.TransientModel):
    _name = 'cookbook.manualreport'
    _columns = {
        'name' : fields.char('Nom de la recette'),
        'category_id' : fields.many2one('cookbook.recipe.category', 'Categorie'),
        'difficulty' : fields.char('Niveau de difficulte'),
        'ingredients' : fields.char('Ingredient inclu'),
    }
    def recipe_report(self, cr, uid, ids, context=None):
        recipe_obj = self.pool.get('cookbook.recipe')
        cur_obj = self.browse(cr, uid, ids, context=context)
        filtre = []
        if cur_obj.name :
            filtre.append(('name', 'ilike', cur_obj.name))
        if cur_obj.category_id :
            filtre.append(('category_id', '=', cur_obj.category_id.name))
        if cur_obj.difficulty :
            filtre.append(('difficulty', 'ilike', cur_obj.difficulty))
        if cur_obj.ingredients :
            filtre.append(('ingredients', 'ilike', cur_obj.ingredients))
        recipe_ids = recipe_obj.search(cr, uid, filtre, context=context)
        if recipe_ids :
            datas = {
                'ids' : recipe_ids,
                'model' : self._name,
                'form' : self.read(cr, uid, ids, context=context)[0],
                'context' : context
        }
        return {
            'type' : 'ir.actions.report.xml',
            'report_name' : 'cookbook.report_recipe',
            'datas' : datas,
        }


The xml file view

<openerp>    
    <data>
        <record id="report_action" model="ir.actions.act_window">
            <field name="name">Buttons</field>
            <field name="res_model">cookbook.manualreport</field>
            <field name="type">ir.actions.act_window</field>
            <field name="view_type">form</field>
            <field name="view_mode">form</field>
            <field name="target">new</field>
        </record>
        <menuitem id="report_elt_menu" name="Print" parent="cookbook_main_menu"
            action="report_action"/>
        <record id="report_view_form" model="ir.ui.view">
            <field name="name">cookbook.manualreport.form</field>
            <field name="model">cookbook.manualreport</field>
            <field name="arch" type="xml">
                <form string="Recipe Report">
                    <group string="Search elements">
                        <field name="name"/>
                        <field name="category_id" options="{'no_create':True}"/>
                        <field name="difficulty" options="{'no_create':True}"/>
                        <field name="ingredients"/>
                    </group>
                    <footer>
                        <button string="Report" name="recipe_report" type="object" class="oe_highlight"/>
                        or
                        <button string="Cancel" class="oe_link" special="cancel"/>
                    </footer>
                </form>
            </field>
        </record>
    </data>
</openerp>


0
reda rouichi
On 8/2/16, 6:38 AM

try this

i assume you are using the new api :)

def clear_record_data(self):
    orm_button = self.env['cookbook.recipe']
    button_ids = orm_button.search([])
   return button_ids.print_report()

The issue don't change. The message error don't change

William Mb
on 8/2/16, 9:48 AM

can you show me the code of print_report() method.

reda rouichi
on 8/2/16, 9:53 AM

def print_report(self, cr, uid, ids, name, data, context=None):

"""

Render the report ``name`` for the given IDs. The report must be defined

for this model, not another.

"""

report = self.pool['ir.actions.report.xml']._lookup_report(cr, name)

assert self._name == report.table

return report.create(cr, uid, ids, data, context)

William Mb
on 8/2/16, 1:33 PM

It is the print_report() method of the models.py file in the openerp module

William Mb
on 8/2/16, 1:35 PM

try this

@api.multi

def clear_record_data(self):

orm_button = self.env['cookbook.recipe']

button_ids = orm_button.search([])

return button_ids.print_report('cookbook.report_recipe',{})

reda rouichi
on 8/2/16, 1:44 PM

Traceback (most recent call last):

File "D:/odoo-8.0\openerp\http.py", line 544, in _handle_exception

return super(JsonRequest, self)._handle_exception(exception)

File "D:/odoo-8.0\openerp\http.py", line 581, in dispatch

result = self._call_function(**self.params)

File "D:/odoo-8.0\openerp\http.py", line 317, in _call_function

return checked_call(self.db, *args, **kwargs)

File "D:/odoo-8.0\openerp\service\model.py", line 118, in wrapper

return f(dbname, *args, **kwargs)

File "D:/odoo-8.0\openerp\http.py", line 314, in checked_call

return self.endpoint(*a, **kw)

File "D:/odoo-8.0\openerp\http.py", line 810, in __call__

return self.method(*args, **kw)

File "D:/odoo-8.0\openerp\http.py", line 410, in response_wrap

response = f(*args, **kw)

File "D:\odoo-8.0\addons\web\controllers\main.py", line 948, in call_button

action = self._call_kw(model, method, args, {})

File "D:\odoo-8.0\addons\web\controllers\main.py", line 936, in _call_kw

return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)

File "D:/odoo-8.0\openerp\api.py", line 268, in wrapper

return old_api(self, *args, **kwargs)

File "D:/odoo-8.0\openerp\api.py", line 399, in old_api

result = method(recs, *args, **kwargs)

File "D:\odoo-8.0\customs_addons\cookbook\models\button.py", line 38, in clear_record_data

return button_ids.print_report(report_name,{})

File "D:/odoo-8.0\openerp\api.py", line 266, in wrapper

return new_api(self, *args, **kwargs)

File "D:/odoo-8.0\openerp\api.py", line 592, in new_api

result = method(self._model, cr, uid, self.ids, *args, **old_kwargs)

File "D:/odoo-8.0\openerp\models.py", line 5050, in print_report

assert self._name == report.table

AttributeError: 'unicode' object has no attribute 'table'

William Mb
on 8/3/16, 5:02 AM

When I do this :

@api.multi

def clear_record_data(self):

module_name = 'cookbook.recipe' # 'button.demo'

report_name = 'cookbook.report_recipe'

orm_button = self.env[module_name]

openerp.report.interface.report_int._reports['report.' + report_name] = report_custom('report.' + report_name)

openerp.report.interface.report_int._reports['report.' + report_name].table = module_name

button_ids = orm_button.search([])

buttons = orm_button.browse(button_ids)

return button_ids.print_report(report_name,{})

I have this

Traceback (most recent call last):

File "D:/odoo-8.0\openerp\http.py", line 544, in _handle_exception

return super(JsonRequest, self)._handle_exception(exception)

File "D:/odoo-8.0\openerp\http.py", line 581, in dispatch

result = self._call_function(**self.params)

File "D:/odoo-8.0\openerp\http.py", line 317, in _call_function

return checked_call(self.db, *args, **kwargs)

File "D:/odoo-8.0\openerp\service\model.py", line 118, in wrapper

return f(dbname, *args, **kwargs)

File "D:/odoo-8.0\openerp\http.py", line 314, in checked_call

return self.endpoint(*a, **kw)

File "D:/odoo-8.0\openerp\http.py", line 810, in __call__

return self.method(*args, **kw)

File "D:/odoo-8.0\openerp\http.py", line 410, in response_wrap

response = f(*args, **kw)

File "D:\odoo-8.0\addons\web\controllers\main.py", line 948, in call_button

action = self._call_kw(model, method, args, {})

File "D:\odoo-8.0\addons\web\controllers\main.py", line 936, in _call_kw

return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)

File "D:/odoo-8.0\openerp\api.py", line 268, in wrapper

return old_api(self, *args, **kwargs)

File "D:/odoo-8.0\openerp\api.py", line 399, in old_api

result = method(recs, *args, **kwargs)

File "D:\odoo-8.0\customs_addons\cookbook\models\button.py", line 38, in clear_record_data

return button_ids.print_report(report_name,{})

File "D:/odoo-8.0\openerp\api.py", line 266, in wrapper

return new_api(self, *args, **kwargs)

File "D:/odoo-8.0\openerp\api.py", line 592, in new_api

result = method(self._model, cr, uid, self.ids, *args, **old_kwargs)

File "D:/odoo-8.0\openerp\models.py", line 5051, in print_report

return report.create(cr, uid, ids, data, context)

File "D:/odoo-8.0\openerp\report\custom.py", line 130, in create

report = self.pool['ir.report.custom'].browse(cr, uid, [datas['report_id']])[0]

File "D:/odoo-8.0\openerp\modules\registry.py", line 102, in __getitem__

return self.models[model_name]

KeyError: 'ir.report.custom'

William Mb
on 8/3/16, 5:14 AM

Thks for your help.

William Mb
on 8/4/16, 7:19 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

1 follower(s)

Stats

Asked: 8/1/16, 12:09 PM
Seen: 355 times
Last updated: 8/4/16, 7:18 AM