Odoo Help


How to define a start value for an incremental field ?

Anne-Sylvie Burri
on 2/3/14, 9:24 AM 3,053 views


I have the following code and I wanna define, for example, "1000" as start value for the numbering.

Someone could help me ?

Thanks in advance.


.xml file :

<?xml version="1.0"?>

<record id="view_mutante_form" model="ir.ui.view">
        <field name="name">res.partner.form.inherit</field>
        <field name="model">res.partner</field>
        <field name="inherit_id" ref="base.view_partner_form" />
        <field name="arch" type="xml">
    <xpath expr="/form/sheet/group/group/label[@for='street']" position="before">
        <field name="n_client" attrs="{'invisible':[('customer','!=',True)]}"/>
        <field name="n_supplier" attrs="{'invisible':[('supplier','!=',True)]}"/>
    <data noupdate="1">
        <record model="ir.sequence.type" id="seq_type_res_partner">
            <field name="name">number_client_sequence</field>
            <field name="code">res.partner.customer</field>
        <record model="ir.sequence" id="seq_res_partner">
            <field name="name">number_client_sequence</field>
            <field name="code">res.partner.customer</field>
            <field name="prefix">C</field>
            <field name="padding">6</field>
        <record model="ir.sequence.type" id="seq_type_res_supplier">
            <field name="name">number_supplier_sequence</field>
            <field name="code">res.partner.supplier</field>
        <record model="ir.sequence" id="seq_res_supplier">
            <field name="name">number_supplier_sequence</field>
            <field name="code">res.partner.supplier</field>
            <field name="prefix">S</field>
            <field name="padding">6</field>

.py file :

# -*- coding: utf-8 -*-

from openerp.osv import fields, osv

import openerp.addons.decimal_precision as dp

class res_partner(osv.osv):
    _inherit = 'res.partner'
    _name = 'res.partner'

    _columns = {
        'n_client' : fields.char('Client Number', size=64, readonly=True),
        'n_supplier' : fields.char('Supplier Number', size=64, readonly=True),
    _sql_constraints = [
        ('name_uniq_1', 'unique(n_client)', 'Number of client must be unique!'),
        ('n_supplier_uniq', 'unique(n_supplier)', 'Number of supplier must be unique!'),        

    def create(self, cr, uid, vals, context=None):   

        if vals.get('n_client') == None:
            vals['n_client'] = self.pool.get('ir.sequence').get(cr, uid, 'res.partner.customer')

        if vals.get('n_supplier') == None:
            vals['n_supplier'] = self.pool.get('ir.sequence').get(cr, uid, 'res.partner.supplier')
        return super(res_partner,self).create(cr, uid, vals, context)

    def copy(self, cr, uid, id, default=None, context=None):
            'n_client': self.pool.get('ir.sequence').get(cr, uid, 'res.partner.customer'),
            'n_supplier': self.pool.get('ir.sequence').get(cr, uid, 'res.partner.supplier')
        return super(res_partner, self).copy(cr, uid, id, default, context)




| 5 4 7
Bikaner, India

OpenERP Developer at SunARC Technology

On 2/3/14, 10:28 AM

In openerp default value set

_defaults = {   
        'column_name'   : lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'res.partner'),

The below sql to find the res.partner ID Value

select * from ir_sequence where code='res.partner'

using ID value to set ir_sequence_0IDVALUE start with 1000

select setval('ir_sequence_0id', 999);

After that Default value starts with 1000

It works perfectly ! Thanks :-)

J.-M. Burri - Bureau ing.-conseils informatique, Anne-Sylvie Burri
on 2/4/14, 6:46 AM

Thierry Godin

--Thierry Godin--
| 8 7 8
Collegien, France
--Thierry Godin--


Thierry Godin
On 2/3/14, 10:23 AM


Add number_next_actual field to xml :

<field name="number_next_actual">1000</field>


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.


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

0 follower(s)


Asked: 2/3/14, 9:24 AM
Seen: 3053 times
Last updated: 3/16/15, 8:10 AM