This question has been flagged
1 Reply
6285 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?

Avatar
Discard
Best Answer

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.

Avatar
Discard
Author

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?

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.

Author

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

Author

Can you be a bit descriptive?

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

Author

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

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

Author

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

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.

Author

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

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

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

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