Sometimes when we delete few or all records from a table, we may want ids of records to be in sync with the last record or the first one, but what we get is that new ids with a significant amount of gap have been generated, for example if it should be 10 but it is 323. In OpenERP sometimes its creates problems when operating on data, so we need to adjust the id(primary key) back to the required id.
What can be done:
First delete the records if u you want to
Run the following query:
SELECT setval('account_voucher_id_seq' , mx.mx+1)
FROM (SELECT max(id) AS mx FROM account_voucher) mx
This query first selects the max id from the records and then change it to next value, for example if the last id was 4, then next id will be 5.
Note:account_voucher_id_seq is the sequence under the database->Schemas->Public->Sequences for the table account_voucher, All the sequences for all the tables are defined under the same menu.