Skip to Content
Menu
This question has been flagged
1 Reply
4129 Views

I have to increase default value on a field 

Here is the code.. using this code I am getting every time 0 value..here I have to get 0,1,2... like this

serial_no = fields.Integer(string='ID', readonly=1, default=False)

    _defaults = {

    'field': 0,

    }

<field name="serial_no" readonly="1"/>


so please let me know

Avatar
Discard
Best Answer

Hi,

you can use sequence number generator for that.

<data noupdate="1">
<record
id="sequence_id" model="ir.sequence">
<field
name="name">Sequence Name</field>
<field
name="code">your.model</field>
<field
name="prefix"></field>
<field
name="number_next">0</field>
<field
name="number_increment">1</field>
<field
name="padding">1</field>
</record>
</data>

You can use this sequence in Python by

serial_no = fields.Integer(string="ID", default=lambda self: self.env['ir.sequence'].next_by_code('your.model'))

Thank you

Avatar
Discard
Related Posts Replies Views Activity
3
Aug 24
5509
4
Jul 24
38821
5
Apr 23
93761
3
Nov 22
2960
3
Aug 22
3044