Skip to Content
Menu
This question has been flagged
2 Replies
2225 Views

hi,

Kindly advise how to create auto number in helpdesk? I need to have an ID everytime i create help desk.


Thanks.


Avatar
Discard
Best Answer

Hi,

If you are looking to add sequence number for your model, what you have to do is that,


In the xml,

<record id="seq_sample_name" model="ir.sequence">
<field
name="name">Sample Name</field>
<field
name="code">model_name</field>
<field
name="prefix">PRE</field>
<field
name="padding">3</field>
<field
name="company_id" eval="False"/>
</record>

Then in the Python inside the corresponding model, you can override the create method and assign the sequence number,

@api.model
def create(self, vals):
if vals.get('name', _('New')) == _('New'):
vals['name'] = self.env['ir.sequence'].next_by_code('model_name') or _('New')
res = super(ClassName, self).create(vals)
return res


Also define a field to assign the sequence,


name = fields.Char(string='Order Reference', required=True, copy=False, readonly=True,
index=True, default=lambda self: _('New'))


Thanks

Avatar
Discard
Author Best Answer

Hi Cybrosys,

Thank you for your response. But can i do it on UI only?


Avatar
Discard