Monday, 25 July 2016

How to make sequence name Odoo



http://dedyyuristiawan.blogspot.com


Hello world. Today i am gonna share about little trick in Odoo, this is a how to make field name sequence. Actually its basic from Odoo, but i just know when i got task like that. Lol. So just follow my step by step.

1. Declaration code for sequence

For declaration sequence i create xml file like this. the code is test.dedy.yuristiawan, prefix DY, padding is 5, and it would be like this 'DY00001'. Prefix is for first char (DY) and padding is for long number (00001). You can call this sequence with test.dedy.yuristiawan. See this code

  <?xml version="1.0" encoding="utf-8"?>  
  <openerp>  
    <data noupdate="1">  
      <record id="seq_test_dedy_yuristiawan" model="ir.sequence">  
        <field name="name">Test Dedy Yuristiawan</field>  
        <field name="code">test.dedy.yuristiawan</field>  
        <field name="prefix">DY</field>  
        <field name="padding">5</field>  
        <field eval="1" name="number_increment"/>  
      </record>  
    </data>  
  </openerp>  

and then i put this code in test_dedy_yuristiawan.xml

2. Override Function set Field Name, before Create.

Yap, now i override create function like this. This code i set field name readonly=True (anybody can't change) and call  self.env['ir.sequence'].next_by_code('test.input.machine') that i create in xml file. If you don't know about override function i will create specially post for How to Override Function in Odoo in the next post.

name = fields.Char('Code Dedy', readonly=True)

@api.model
def create(self, vals):
    print "+++++++++++++++++++++++++++++++++++++++++++++++++"
    print "prepare inherit create function"
    print "change the name TI with sequence"
    vals['name'] = self.env['ir.sequence'].next_by_code('test.input.machine')
    print "Inherit complete"
    print "+++++++++++++++++++++++++++++++++++++++++++++++++"
    return super(test_input_machine, self).create(vals)


3. Declaration xml file into __openerp__.py

Last step don't forget to declaration xml file to __openerp__.py

'data'          : [
                         'data/test_dedy_yuristiawan.xml',

That it, i hope this is can help you little bit, so if you still confuse about my code, you fill comment bellow and i will try to help you later. Thanks.



Share:


<br>


Advice for contacting me at dedyy54@gmail.com