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

How to get the last record id from existing table

By
Eric
on 12/31/13, 3:57 PM 6,560 views

I am trying to get the last record id with out using the create() from the ORM. Does anyone know how to get a last record id from a table? thank you

Maybe with SELECT max(id) FROM table

GH Mediacloud, Grover Menacho
on 12/31/13, 4:13 PM
4
Eric
On 12/31/13, 4:21 PM

Well I finally got something working. This is what I did, I used the database cursor and wrote an sql select statement like this:

cr.execute('select "id" from "table_name" order by "id" desc limit 1')

id_returned = cr.fetchone()

the fetchone() method returns a tuple of one value which is assigned to the id_returned variable. I can then get the id from the tuple by referencing the first index like this: id_returned[0]

3

Atul Arvind

--Atul Arvind--
1854
| 3 3 5
India
--Atul Arvind--

Hello, 

I am odoo Enthusiast/Consultant from Baroda, Gujarat, India. Working with odoo from v5 to v9 and other opensource technology since 4+ years. Having Strong Expertise in

Requirement gathering & Gap Analysis

Odoo Development

Odoo Customization

Odoo Training

Odoo Integration

Server Administration

Odoo Migration

Implementation

I am also active on StackOverflow.

or 


Atul Arvind
On 1/1/14, 1:43 AM

If you don't want to execute PSQL query then you can search the record and get the max number, eg.

search_ids = self.pool.get("res.partner").search(cr, uid, [])
last_id = search_ids and max(search_ids)
1
Rich Granata
On 1/2/14, 2:30 PM

The sequencing is also stored in the database and can be retrieved with a statement like:

select * from res_partner_id_seq

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: 12/31/13, 3:57 PM
Seen: 6560 times
Last updated: 9/14/16, 10:26 AM