auto increment - internal reference odoo9
<p>I want to change the type of the field 'ref' (Internal Reference) to be auto incremented (for example every time I create a new contact my Internal Reference should increase by 1). So first contact should have Internal Reference 1, the second 2, the third 3 and so on...</p>

<p>There are no errors but still the reference field is empty. Have I missed some additional code? Can someone help me?</p>

<pre><code>@api.model
def create(self, vals):
    if vals.get('ref', 'New') == 'New':
        vals['ref'] = self.env['ir.sequence'].next_by_code(
            'res.debt') or 'New'
    return super(Partner, self).create(vals)
</code></pre>

<p>And the xml file:</p>

<pre><code>      &lt;record id="your_sequence_id" model="ir.sequence"&gt;
          &lt;field name="name"&gt;Reference&lt;/field&gt;
          &lt;field name="padding"&gt;3&lt;/field&gt;
          &lt;field name="code"&gt;res.debt&lt;/field&gt;
      &lt;/record&gt;
</code></pre>

<p><img src="http://i.stack.imgur.com/EMIn7.png" alt="Example of current result"></p>

<p>You don't need the unnecessary if statement, because as you stated in your question you want the reference to autoincrement every time a new user is created. the users can't change the field from the form, this is how you get the next reference in odoo.</p>

<pre><code>@api.model
def create(self, vals):
    vals['ref'] = self.env['ir.sequence'].get('res.debt')
    return super(Partner, self).create(vals)
</code></pre>

python xml auto-increment odoo-9