I have a class Student. How can auto increment the id_number. The id_number should also be unique. id_number should always check the highest number and then increment it by one.
class Student(models.Model):
id_number = fields.Integer('Number')
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
I have a class Student. How can auto increment the id_number. The id_number should also be unique. id_number should always check the highest number and then increment it by one.
class Student(models.Model):
id_number = fields.Integer('Number')
Hi,
You can create a sequence like this,
first in XML:
<record id="seq_hr_employee" model="ir.sequence"><field name="name">omega_sequencer</field> <field name="code">hr.employee</field><field name="prefix">QO</field> <field name="padding">5</field> </record>
Then in the python, override the create method and assign the value
@api.model
def create(self, vals):
seq = self.env['ir.sequence'].next_by_code('hr.employee') or '/'
vals['sequence_id'] = seq
return super(omega, self).create(vals)Thanks
สร้างบัญชีวันนี้เพื่อเพลิดเพลินไปกับฟีเจอร์พิเศษและมีส่วนร่วมกับคอมมูนิตี้ที่ยอดเยี่ยมของเรา!
ลงชื่อ| Related Posts | ตอบกลับ | มุมมอง | กิจกรรม | |
|---|---|---|---|---|
|
|
3
พ.ย. 24
|
31173 | ||
|
|
6
มี.ค. 24
|
22164 | ||
|
Limit the number of digits in integer?
แก้ไขแล้ว
|
|
4
ก.ค. 25
|
35945 | |
|
Integer Field Converts Value to Zero
แก้ไขแล้ว
|
|
1
มี.ค. 23
|
2820 | |
|
|
1
ธ.ค. 21
|
3311 |