I am trying to generate a unique id using ir.sequence for my newely created model. Here is my python code
name = fields.Char(string="Name",required=True, default= lambda self: self.env['ir.sequence'].next_by_code('pv.plant.sequence'))
the xml is
record id="sequence_pv_plant" model="ir.sequence">
field name="name">PV Plant Sequence
field name="code">pv.plant.sequence
field name="prefix">PV
field name="padding">4
/record>
this works completely fine!
but when i try to make the name field as"readonly" the number being generated is with a step of +2. I have checked my step value in the technical--> sequences and it is 1.
This occurs only when the readonly = True.
Any help would be appreciated.
name = fields.Char(string="Name ID", copy=False, required=True, readonly=True,
default=lambda self: _('New'))
@api.model
def create(self, vals):
if vals.get('name', _("New")) == _("New"):
vals['name'] = self.env['ir.sequence'].next_by_code('pv.plant.sequence') or _("New")
res = super(PvPlant, self).create(vals)
return res
works with the code above