Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
6001 Zobrazení

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')




Avatar
Zrušit
Nejlepší odpověď

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

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
3
lis 24
29973
6
bře 24
21446
4
čvc 25
35006
1
bře 23
2266
1
pro 21
2736