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.

0

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

id
By
samba
on 7/30/14, 3:36 AM 2,713 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

--Prakash--
3173
| 5 4 7
Bikaner, India
--Prakash--

OpenERP Devloper at SunARC Technology

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

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: 7/30/14, 3:36 AM
Seen: 2713 times
Last updated: 3/16/15, 8:10 AM