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

how to set unique number?

By
sneha antony
on 3/27/14, 5:47 AM 1,289 views

I have developed a new module in openerp to enter the warranty details of the customer.Each entry made is displayed in the tree view.I want to set a unique no.in a specific format to each of the entry.Now there entries are generated with numbers 25,26,29.I want some recognizable number so that I can easily identify each entry when used in reference fields.How can this be done?

0

Nehal

--Nehal--
2090
| 5 2 8
Ahmadabad, India
--Nehal--
Nehal
On 3/27/14, 5:52 AM

You can use sequence for generating unique number like SO001 if you want to auto generate. Or you can apply unique constraint for the field of the specific object in case of manual entry.

I want to autogenerate the no.But how to autogenerate unique numbers for each entry using sequence in warranty module?what are the steps involved?

sneha antony
on 3/27/14, 6:07 AM

For that you need to create sequence file with the sequence based on your requirement. Then apply that sequence in the field you want from .py file. You can refer sale_sequence.xml for the name field of sale order. You need to define 'name': lambda obj, cr, uid, context: '/', in _defaults of the object.

Nehal
on 3/27/14, 6:26 AM

where to give the name of the sequence file created thus?

sneha antony
on 3/27/14, 6:31 AM

Can you be a bit descriptive?

sneha antony
on 3/27/14, 6:39 AM

Create sequece file in your module. Include that file in to _openerp_.py file in data tag. 'data': ['sale_sequence.xml',]. e.g. name': fields.char('Order Reference', size=64), and in _defaults = { 'name': lambda obj, cr, uid, context: '/', }. Then override the create method where you need to fill the sequence in name field. E.g. def create(self, cr, uid, vals, context=None): if vals.get('name','/')=='/': vals['name'] = self.pool.get('ir.sequence').get(cr, uid, 'sale.order') or '/' return super(sale_order, self).create(cr, uid, vals, context

Nehal
on 3/27/14, 6:47 AM

where to give this code?e.g. name': fields.char('Order Reference', size=64), and in _defaults = { 'name': lambda obj, cr, uid, context: '/', }.

sneha antony
on 3/27/14, 7:00 AM

in object of your module. Suppose test.test object contains name field. then the code should be in test.test

Nehal
on 3/27/14, 7:04 AM

and the module is to be upgrraded to reflect changes no?

sneha antony
on 3/27/14, 7:16 AM

You need to restart the server and upgrade the module as for .py changes server needs to be restarted and for .xml changes module to be upgraded.

Nehal
on 3/27/14, 7:21 AM

what does the ir.sequence in the .xml file represents?should it be declared somewhere in the files?

sneha antony
on 3/28/14, 5:57 AM

ir.sequence is the Table where all sequences are defined. you need to use this object in your sequence file.

Nehal
on 3/28/14, 6:32 AM

ir.sequence is the Table where all sequences are defined. you need to use this object in your sequence file.

Nehal
on 3/28/14, 6:33 AM

ir.sequence is the Table where all sequences are defined. you need to use this object in your sequence file.

Nehal
on 3/28/14, 6:38 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

0 follower(s)

Stats

Asked: 3/27/14, 5:47 AM
Seen: 1289 times
Last updated: 3/16/15, 8:10 AM