Skip to Content
Menu
This question has been flagged
1 Reply
3311 Views

Hii All,


I want to show total numbers of record on screen. For this i have write query language for function and i get desire result on Ubuntu 14.04 command line screen by printing that value from python code. But when i return this value in function then it shows me error pop-up message "TypeError: 'int' object is not iterable". So, anyone can give me proper solution for this problem. My python code for function and field is below. 


Python code:


    def get_count(self, cr, uid, ids, sequence, arg, context=None):

        cr.execute('SELECT count(*) from sun_helpdesk')

        u_data = cr.fetchall()

        print "cr:", u_data

        print "res:",int(u_data[0][0])

        return int(u_data[0][0])


    _columns = {

        'sequence': fields.function(get_count, method=True, string='Total Tickets', type='integer'),

    }


XML code:

In XML this field added simply.

<field name="sequence"/>


Result on the Ubuntu Screen is:

cr: [(101L,)]

res: 101

new_values = dict(values)

TypeError: 'int' object is not iterable

Avatar
Discard
Best Answer

If you want to show the result on the screen, you have to return a view from get_count. That means, that you return a dictionary where you specify certain fields for odoo, e.g.:

 return {
            'name': _('View title'),
            'type': 'ir.actions.act_window',
            'view_type': 'form',
            'view_mode': 'form',
            'res_model': 'some_model',
            'target': 'new',
         }
For this to work, you'll have to define a model (ideally you'll want to create a wizard, since, I guess, you don't want to store the result), add a filed for your return value (a fields.Integer) and then pass the return value also in your dictionary. There you have two choices: either in the context as a default or you'll create a new record before the return and pass its id in the 'res_id' key.
Since this is only a very brief explanation, please ask if you would like to know further details.
Avatar
Discard
Related Posts Replies Views Activity
2
Jul 19
4266
0
Aug 17
2441
3
Dec 22
9952
5
Apr 24
39350
6
Apr 24
36752