How To create Sequence in odoo/openerp
Step -1
Create One Xml File and register xml file in __openerp__.py and Add below code.
<data noupdate="1">
<!-- Sequences for any object -->
<record id="seq_id" model="ir.sequence.type">
<field name="name">Give Any Name</field>
<field name="code">seq.seq</field>
</record>
<record id="give_any_unique_id" model="ir.sequence">
<field name="name">name same as above</field>
<field name="code">seq.seq</field>
<field name="prefix">SQ</field>
<field name="padding">5</field>
</record>
</data>
Step - 2
Create Py file when you want to add sequence like below
class proejct_task(models.Model):
_inherit = "project.task"
sequence_id = fields.Char('Sequence', readonly=True)
@api.model
def create(self, vals):
seq = self.env['ir.sequence'].get('seq.seq') or '/' //seq.seq is code which is define in xml file
vals['sequence_id'] = seq
return super(proejct_task, self).create(vals)
step - 3
Add sequence_id in project task form view like below.
<record id="view_task_form2_inherit" model="ir.ui.view">
<field name="name">view.task.form2.form</field>
<field name="model">project.task</field>
<field name="type">form</field>
<field name="inherit_id" ref="project.view_task_form2" />
<field name="arch" type="xml">
<xpath expr="//field[@name='project_id']" position="after">
<field name="sequence_id"/>
</xpath>
</field>
</record>
When you crate ptoject task sequence field is auto create like SQ00002,SQ00003,SQ00004
Step -1
Create One Xml File and register xml file in __openerp__.py and Add below code.
<data noupdate="1">
<!-- Sequences for any object -->
<record id="seq_id" model="ir.sequence.type">
<field name="name">Give Any Name</field>
<field name="code">seq.seq</field>
</record>
<record id="give_any_unique_id" model="ir.sequence">
<field name="name">name same as above</field>
<field name="code">seq.seq</field>
<field name="prefix">SQ</field>
<field name="padding">5</field>
</record>
</data>
Step - 2
Create Py file when you want to add sequence like below
class proejct_task(models.Model):
_inherit = "project.task"
sequence_id = fields.Char('Sequence', readonly=True)
@api.model
def create(self, vals):
seq = self.env['ir.sequence'].get('seq.seq') or '/' //seq.seq is code which is define in xml file
vals['sequence_id'] = seq
return super(proejct_task, self).create(vals)
step - 3
Add sequence_id in project task form view like below.
<record id="view_task_form2_inherit" model="ir.ui.view">
<field name="name">view.task.form2.form</field>
<field name="model">project.task</field>
<field name="type">form</field>
<field name="inherit_id" ref="project.view_task_form2" />
<field name="arch" type="xml">
<xpath expr="//field[@name='project_id']" position="after">
<field name="sequence_id"/>
</xpath>
</field>
</record>
When you crate ptoject task sequence field is auto create like SQ00002,SQ00003,SQ00004
hope this will also helps: https://learnopenerp.blogspot.com/2020/08/generate-create-sequence-number-odoo.html
ReplyDelete