Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
2495 มุมมอง

hi,

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


Thanks.


อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

Hi Cybrosys,

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


อวตาร
ละทิ้ง