Se rendre au contenu
Menu
Cette question a été signalée
1 Répondre
5966 Vues

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
Ignorer
Meilleure réponse

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
Ignorer
Publications associées Réponses Vues Activité
3
nov. 24
29944
6
mars 24
21399
4
juil. 25
34974
1
mars 23
2228
1
déc. 21
2718