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.

5

How do I make a button to move to next record? [Closed]

By
AJ Schrafel Paper Corp
on 6/12/13, 12:39 AM 2,027 views

The Question has been closed

by
Sudhir Arya (SA)
on 06/13/2013 16:38:10

I want to create a button on my custom module that will mark the current record finished, then move to the next record, as if I hit the arrows in the upper right corner to move between records.

def action_button_verify_bad(self, cr, uid, ids, context=None):
    res = self.write(cr, uid, ids, {'fail_check': True}, context=context)
    return {'type':'ir.actions.act_window_close'}

What do I have to return to move the the next record?

9

Sudhir Arya (SA)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

Sudhir Arya (SA)
On 6/12/13, 4:17 AM

Add the following code in you py file:

def action_button_verify_bad(self, cr, uid, ids, context=None):
    range = self.search(cr, uid, [], context=context)
    if len(range) > 0:
        range.sort()
        range = range[-1:]
        range = range and range[0]
    else:
        return {}
    next_id = ids and ids[0]
    while True:
        if range == next_id:
            next_id = 1
        next_id += 1
        res_id = self.search(cr,uid,[('id', '=', next_id)], context=context)
        if res_id:
            self.write(cr, uid, ids, {'fail_check': True}, context=context)
            return {
                'name': _("Your Object Name"),
                'res_id': res_id[0],
                'view_type': 'form',
                'res_model': 'sale.order',
                'view_mode': 'form,tree',
                'nodestroy': True,
                'target': 'current',
                'context': context,
                'type': 'ir.actions.act_window',
            }

This will work for sure.

this worked 95%, i had to add in my view search parameters and the view_id, but your answer got me there.

AJ Schrafel Paper Corp
on 6/13/13, 12:46 PM

It's good to hear that it worked.

Sudhir Arya (SA)
on 6/13/13, 4:37 PM

So useful!! Thanks a lot!

Michael O. Lambert
on 3/27/14, 10:45 AM
6

Sandeep

--Sandeep--
6083
| 6 5 8
Delhi, India
--Sandeep--
Python OpenERP Developer http://in.linkedin.com/pub/sandeep-rana/3b/a16/786/
Sandeep
On 6/12/13, 3:22 AM

Hi

for that case you do one thing

          def action_button_verify_bad(self, cr, uid, ids, context=None):
                       for id in ids:
                              next=id+1
                              yes=self.search(cr,uid,[('id','=',next)])
                              if yes:
                                     return {
                                            'name':_("My module name"), 
                                        'view_mode': 'form',
                                        'view_id': False,
                                        'view_type': 'form',
                                        'res_model': 'my.module',
                                        'res_id': yes[0],
                                        'type': 'ir.actions.act_window',
                                        'nodestroy': True,
                                        'target': 'current',
                                        'domain': '[]',
                                            'context': context
                                            }
                              else:
                                    return {'type':'ir.actions.act_window_close'}

Thanks
Sandeep

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 6/12/13, 12:39 AM
Seen: 2027 times
Last updated: 3/16/15, 8:10 AM