Odoo Help

0

How can i get the last record id from "account.config.settings" table?

id
By
samba
on 7/30/14, 3:36 AM 3,142 views

I have added one extra column to ""account.config.settings" i.e "threelevelinvoiceapproval". I have written this function to validate invoice.

def approve(self, cr, uid, ids):
        flag=False
        for invoice in self.pool.get('account.invoice').browse(cr, uid, ids, context=None):
            for i in self.pool.get('account.config.settings').browse(cr, uid, ids, context=None):
                flag=i.threelevelinvoiceapproval
                # Three level approval true.
            if flag:
                if invoice.create_uid1.id==uid:
                    raise openerp.exceptions.Warning("You don't have right to validate purchase order")
                    return False
                else:
                    self.write(cr, uid, ids, {'state': 'validate','write_uid1':uid})
                    return True
            # No three level approval use the fields in the user creation to approve
            else:
                for i in self.pool.get('res.users').browse(cr, uid, [uid], context=None):
                    flag=i.canvalidateinvoice
                if flag:
                    self.write(cr, uid, ids, {'state': 'validate','write_uid1':uid})
                    return True
                else:
                    raise openerp.exceptions.Warning("You don't have right to validate purchase order")
                    return False

In fourth line of the function getting the "ids" from invoice line but i need the id of the last record of "account.config.settings". Please tell me how can i solve this?

1
Prakash
On 7/30/14, 3:58 AM

You can get last record id from account.config.settings table using the below code:-

account_config_obj = self.pool.get('account.config.settings')

account_config_ids = account_config_obj.search(cr, uid,  [], limit=1, order='id desc')

Thank you prakash, I have written like this cr.execute('SELECT id FROM account_config_settings ') account_config_settings_last_id= cr.fetchall()[-1][0] but your suggested way is good. I am going to follow your way.

samba
on 7/30/14, 4:02 AM

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 7/30/14, 3:36 AM
Seen: 3142 times
Last updated: 3/16/15, 8:10 AM