Make a field to auto increment when I press CONFIRM SALE
<p><img src="http://i.stack.imgur.com/nyg8G.jpg" alt="enter image description here"></p>

<p>I have made the field 'internal reference' in customers to be auto increment as you can see on the picture (001, 002, 003....).
That happens every time I create a new customer.</p>

<p>Now my problem is that I want the same (internal reference to be auto increment) but not when I create a customer but when I click CONFIRM SALE button.</p>

<p>Can someone help me with the Python code and .xml file how can I do that?</p>

<p>It should be something like this but still is the thing I search:</p>

<pre><code>@api.onchange('state', 'partner_id')
def _onchange_partner(self): 
    if self.partner_id: contact_id = self.partner_id.address_get().get('contact', False)
        if contact_id: contact = self.env['res.partner'].browse(contact_id) self.name = self.name or contact.name â
</code></pre>

<p>Just a more detailed example of Palza's answer above (which is correct). Override the action_confirm() method from sale.sale model. I think some variation of this should do the trick.</p>

<pre><code>class SaleOrder(models.Model):
    _inherit = "sale.order"

    @api.multi
    def action_confirm(self):
        import logging
        _logger = logging.getLogger(__name__)
        _logger.info("OVERRIDING action_confirm()")
        _logger.info("CURRENT INT REF: " + str(self.internal_reference))  
        self.write({'internal_reference':self.internal_reference+1})
        _logger.info("NEW INT REF: " + str(self.internal_reference))
        return super(SaleOrder, self).action_confirm()
</code></pre>

python xml odoo-9