Odoo Help


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.


Where are the sequences?

Francesco OpenCode
on 10/11/13, 2:04 PM 2,441 views

I created a sequence for a class. This is the xml structure that create it:

    <record id="seq_type_report_review" model="ir.sequence.type">
        <field name="name">Report Review</field>
        <field name="code">management.reports_review</field>

    <record id="seq_report_review" model="ir.sequence">
        <field name="name">Report Review</field>
        <field name="code">management.reports_review</field>
        <field name="prefix">%(year)s\</field>
        <field name="padding">3</field>
        <field name="company_id" eval="False"/>

And this is the system I use to call the sequence in the class:

def create(self, cr, uid, vals, context=None):
    vals['review_number'] = self.pool.get('ir.sequence').get(cr, uid, 'management.reports_review') or ''
    return super(management_reports_review, self).create(cr, uid, vals, context)

If I create a new voice, the sequence increse by 1. It's ok for me but if I go in the Configuration section the next number voice is always on 1! Why? I would change it but if I change it the sequence go on with is old number.


Brett Lehrer

--Brett Lehrer--
| 5 4 8
Milwaukee, United States
--Brett Lehrer--
Director of IT and open source enthusiast.
Brett Lehrer
On 10/21/13, 11:57 PM

Depends if you're using standard or no-gap sequence implementation. Check out this function in openerp/addons/base/ir/ir_sequence.py:

def _get_number_next_actual(self, cr, user, ids, field_name, arg, context=None):
    '''Return number from ir_sequence row when no_gap implementation,
    and number from postgres sequence when standard implementation.'''
    res = dict.fromkeys(ids)
    for element in self.browse(cr, user, ids, context=context):
        if  element.implementation != 'standard':
            res[element.id] = element.number_next
            # get number from postgres sequence. Cannot use
            # currval, because that might give an error when
            # not having used nextval before.
            statement = (
                "SELECT last_value, increment_by, is_called"
                " FROM ir_sequence_%03d"
                % element.id)
            (last_value, increment_by, is_called) = cr.fetchone()
            if is_called:
                res[element.id] = last_value + increment_by
                res[element.id] = last_value
    return res

Using no-gap implementation, the current sequence should be listed directly in the table in ir_sequence. Otherwise, using something like pgAdmin, you can just look directly at the sequence value under "Sequences" -> "ir_sequence_<sequence id="">". Or, referring to that function, a SQL query like:

select last_value from ir_sequence_041;

Why you aren't seeing the updated number on the configuration page is odd. Something else must be going wrong there, but I don't know what. Using updated server source code?

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

0 follower(s)


Asked: 10/11/13, 2:04 PM
Seen: 2441 times
Last updated: 3/16/15, 8:10 AM