Hi,
If you are looking to create a sequence for your model like SO001, SO002 in sales, you create it like this,
In the XML,
add the field to view for which the sequence has to be given,
<field name="name" readonly="1"/>
Then for creating a record in ir.sequence model,
<record id="seq_test" model="ir.sequence">
<field name="name">Test</field>
<field name="code">test_seq</field>
<field name="prefix">Test</field>
<field name="padding">3</field>
<field name="company_id" eval="False"/>
</record>
Then in the python,
define a field to which the sequence is given,
name = fields.Char(string='Order Reference', required=True, copy=False, readonly=True,
index=True, default=lambda self: _('New'))
Then override the create method and assign the value to the field,
@api.model
def create(self, vals):
if vals.get('name', _('New')) == _('New'):
vals['name'] = self.env['ir.sequence'].next_by_code('test_seq') or _('New')
res = super(Class_Name, self).create(vals)
return res
Thanks
Hope this will help: https://learnopenerp.blogspot.com/2020/08/generate-create-sequence-number-odoo.html