For any module or a part of the module we may have to have a field which is sequential and auto generated. For this we can create a sequence through the OpenERP UI and include in our model pragmatically through python code.
- First create a sequence from the UI, Go to Settings/Configuration/Sequences & Identifiers/Sequences.
- Then specify the name for the sequence like Mass Return Number.
- Select the code i.e model you want this sequence to work for like Mass Return.
- Provide prefix or suffx or both as you need, here we created prefix MR. %(month)s/%(y)s/.
- Provide next number, padding, increment number and implementation and save.
Your sequence is ready and you can use it now in your module to show as a field. Just add the following field:
'number': fields.char('Number', size=128, help="Company internal claim unique number"),
and then in defaults define its value:
'number': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'mass.return'),
ir.sequence is the model where all the sequences are defined. So simple, isn't it.
0 Comment(s)