Skip to Content
Menu
This question has been flagged
3 Replies
13409 Views

Hello, I am a beginner in openerp, i am using odoo10,

1.in this what is the use of sequence_id and how it should be implemented in my custom module,any one can explain me in simple terms,with a example,my custom module is library management.

Thanks & Regards,

Ramanathan Lakshmanan.

Avatar
Discard
Best Answer

Hi,

If you are looking to create a sequence for your model like SO001, SO002 in sales,  you create it like this,


In the XML,

add the field to view for which the sequence has to be given,

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


Then for creating a record in ir.sequence model,


<record id="seq_test" model="ir.sequence">
<field name="name">Test</field>
<field name="code">test_seq</field>
<field name="prefix">Test</field>
<field name="padding">3</field>
<field name="company_id" eval="False"/>
</record>


Then in the python,

define a field to which the sequence is given,

name = fields.Char(string='Order Reference', required=True, copy=False, readonly=True,
index=True, default=lambda self: _('New'))


Then override the create method and assign the value to the field,

@api.model
def create(self, vals):
if vals.get('name', _('New')) == _('New'):
vals['name'] = self.env['ir.sequence'].next_by_code('test_seq') or _('New')
res = super(Class_Name, self).create(vals)
return res


Thanks

Avatar
Discard
Best Answer
Hi Friend:
Adding a sequence for records in OpenERP is very simple. For making a field a sequence type, we need to create new sequence or use existing sequence. For creating a sequence, we need to create two type of objects, one is “ir.sequence.type” and other “ir.sequence”.
Here a helpful link: Sequence
Examples : Invoices, Sale Order, Stock Movement ...
Best Regards. 

Avatar
Discard