Friday, January 1, 2021

sequence in odoo 14

 

Add sequence to odoo object

 
we can add sequence in odoo 14 by following the example bellow 
 
now let us say that we have objects by the name "shilal.object" and we want to 
create sequence field for this objects as "S_O000001" , so to do that 

1/ add char field in this model as 
 
sequence  = fields.Char(string="Sequence")
 
 
2/add the function that will generate the value for this field as bellow
 
@api.model
    def create(self, vals):
       if vals.get('sequence', 'New') == 'New':
           vals['sequence'] = self.env['ir.sequence'].next_by_code(
               'shilal.object') or 'New'
       result = super(ShilalObject, self).create(vals)
       return result

3/ create the xml code for this sequence as bellow

<record id="shilal_object_sequence" model="ir.sequence"> // define sequence record
          <field name="name">Shilal Object Sequence</field> // define sequence name
          <field name="prefix">s_O </field>
          <field name="padding">6</field>
          <field name="code">input.fields</field>
</record>

No comments:

Post a Comment

Odoo Invoice Qr code issues

There are two main issues must of us facing with the QR code in Odoo invoice & these issues are 1/ QR code displayed as broken image w...