跳至內容
選單
此問題已被標幟
1 回覆
5958 瀏覽次數

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

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
3
11月 24
29894
6
3月 24
21396
4
7月 25
34963
1
3月 23
2225
1
12月 21
2709