I created a sequence via user interface : Configuration/Technical/Sequences and identifiers/ Sequences
I also created its code so as so to call it, on the python method on : Configuration/technical/Sequence Code
The model concerned is account.invoice , I want that when validating the invoice, it switches to state open, and generate a sequence number, for that :
1. I overrided the type of validate invoice button to object ( it was workflow )
2. I used invoice_validate as a button method , and overrided it.
3. I overrided the number field, it was related, I made it simple char field.
and then I used the sequence, after the code for more explaination.
.py :
class AccountInvoice(orm.Model):
_inherit = 'account.invoice'
_name = 'account.invoice'
_colmuns = {
'number': fields.char(size=64, readonly=True),
}
def invoice_validate(self, cr, uid, ids, context=None):
num_facture = self.pool.get('ir.sequence').get(cr, uid,'Invoice_number')
self.write(cr, uid, ids[0], {'state':'open','number': num_facture,}, context=context)
return True
.xml :
<record id="invoice_form_custom" model="ir.ui.view">
<field name="name">invoice.form.custom</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form"/>
<field name="arch" type="xml">
<xpath expr="//form/header/button[@name='invoice_open']" position="replace">
<button name="invoice_validate" states="draft" string="Valider" type="object" class="oe_highlight"/>
</xpath>
</field>
</record>
The issue is that the sequence is not displayed on the field "number" I overrided, should I add "number" on the xml view also ?
Thanks