Make a 'ref' field to auto increment when I press CONFIRM SALE button
<p><a href="http://i.stack.imgur.com/pjKv4.jpg" rel="nofollow">confrm_sale</a></p>

<p>I have the problem how to make a 'ref' field to be auto increment every time I press the <em>Confirm Sale Button</em>.</p>

<p>In my first case I made this field to be auto increment every time I create a new customer with the following code:</p>

<p><strong>Python code:</strong></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>

<p><strong>XML code:</strong></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>Now my problem is that I want this field also to be auto incremented, but not when I create the customer, only when I press the <em>Confirm Sale</em> button.</p>

<p>For example, I create a new sale order and I create a new customer for that order and I click save. When I now press <em>Confirm Sale</em>, that action needs to trigger auto increment for the internal reference field (<code>ref</code>).</p>

<p>If I make an order for existing customer than it should take the old sequence for that customer.</p>

<p>I have this code for the <code>action_confirm()</code>:</p>

<pre><code>@api.multi
def action_confirm(self):
    for order in self:
        order.state = 'sale'
        if self.env.context.get('send_email'):
            self.force_quotation_send()
        order.order_line._action_procurement_create()
        if not order.project_id:
            for line in order.order_line:
                if line.product_id.invoice_policy == 'cost':
                    order._create_analytic_account()
                    break
    if self.env['ir.values'].get_default('sale.config.settings', 'auto_done_setting'):
        self.action_done()
    return True
</code></pre>

<p>Probably my first code for the auto increment I should add in this second code but I don't know how to do that.</p>

<p>Can anyone help? Thank you in advance.</p>

<p>If I get your requirement right, I guess you should do something like inside your loop on orders:</p>

<pre><code>order.partner_id.ref = self.env['ir.sequence'].get('res.debt')
</code></pre>

python auto-increment confirm odoo-9