Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

auto number

By
louie
on 9/21/14, 8:11 AM 1,127 views

hello, lately i have successfully get the auto number. now. everytime i create a new record then im going to cancel then create a new one again the auto number is continiuosly add. what i want is everytime i click create button then i need to exit then add again. i want it to become a efault or back to the original number. can anyone help me please? for example. the new number is SN/00001 on the field if ever im going to exit it should be go back in SN/00001. Please help me.

2

Bole

--Bole--
2385
| 5 4 6
Zagreb | Karlovac, Croatia
--Bole--

there is only 10 kind of people the ones that understand binary ... and others

Bole
On 9/22/14, 8:08 AM

Well good example for your problem is in two common odoo modules: sales orders and invoices...
Sales orders : takes next sequence number on object create ( every created order get its own sequence number) 
Invoices : on create default value for number is '/' (or draft) and only when you validate invoice it triggers wkf activity and gets the next sequence number.. .

Wise thing is to decide in wich exact moment the sequence needs to be assigned... 
As i can see, you need invoice - like beahviour, that assignes number but not until you are sure in all the data...

Check methods in those two modules and you will soon find the correct way to use sequences

may the source be with you !

can you give those code or step by step to do it? or i mean the codes to add on my code so that everytime i cancel the transaction it will go back to the original number and not continuously increment.

louie
on 9/24/14, 5:55 AM
1

Odoo

--Odoo --
1328
| 5 2 5
kerala, India
--Odoo --

Working as a Odoo Functional and Technical Expert

Odoo
On 9/22/14, 8:36 AM

Here I define a custom module code sample you can use any of your custom field....

--------define your model  here-------

class----(--)

_columns={
            
            
              'installment_number':fields.char('ID',readonly=True),

 

-------------first override create method

 def create(self, cr, uid, vals, context=None):
        vals['installment_number'] = self.pool.get('ir.sequence').get(cr, uid,'lending.info')
        return super(lending_info, self).create(cr, uid, vals, context=context)

----------------

         }
    _defaults={
                'installment_number': lambda obj, cr, uid, context: '/',
           
              }

define .xml file for auto increment //auto_id.xml

<openerp><data noupdate="1"><!-- Sequences for loan_id --><record id="seq__loan_code_inh1" model="ir.sequence.type"><field name="name">Lending info1 ID</field><field name="code">lending.info</field></record>

 

<record id="seq_cloan_code_inh2" model="ir.sequence"><field name="name">Lending info1 ID</field><field name="code">lending.info</field><field name="prefix">LN</field><field name="padding">2</field></record></data></openerp>

 

check openerp.py,init.py also

 

Thanks

Libu

 

hello, can you give the code to add? because i successfully done already with the auto increment because my only problem is just everytime i create then cancel it or not save it. it will go back to the default number since i didnt save the record. thanks

louie
on 9/24/14, 6:01 AM

def create(self, cr, uid, vals, context=None): vals['installment_number'] = self.pool.get('ir.sequence').get(cr, uid,'lending.info') return super(lending_info, self).create(cr, uid, vals, context=context)

Odoo
on 9/24/14, 6:15 AM

the installment_number and the lending_info where did you get that? and where im going to insert this code?

louie
on 9/24/14, 11:03 AM

the installment_number and the lending_info where did you get that? and where im going to insert this code?

louie
on 9/24/14, 11:03 AM
1
Ishwar Malvi
On 9/22/14, 6:09 AM

Hello,

       You can override create method and call super method for the same, when it returns an id for record at successful creation of record, you can generate sequence and then update the last record with sequence id.

Thanks,

Ishwar Malvi

i need the code please. or the example code. i am newbie in openerp

louie
on 9/24/14, 6:44 AM

def create(self, cr, uid, vals, context=None): ir_sequence_obj = self.pool.get('ir.sequence') cur_id = super(model_name, self).create(cr, uid, vals, context=context) if cur_id: self.write(cr, uid, cur_id, {'auto_num': ir_sequence_obj.get(cr, uid, 'seq_object_name')}, context=context) somekind of code you need to achieve this. thanks, Ishwar Malvi

Ishwar Malvi
on 9/25/14, 1:45 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 9/21/14, 8:11 AM
Seen: 1127 times
Last updated: 3/28/15, 3:13 AM