تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
2502 أدوات العرض

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?


الصورة الرمزية
إهمال