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 make an Auto incremental field in Odoo with prefix letters?

By
Crysler Belisario Araujo Enoc
on 5/22/15, 9:57 AM 1,669 views

Odoo team, my question is about how to create a read-only field in Odoo, have a prefix or suffix, eg. fact00001, fact00002, fact00003 etc. or 00001A,00002A,00003A, etc

I need that new field in the invoice module but I have no idea how to make it appear there.

I know I create a new class in python, then inherit from the base class, you need to create the field, then create an .xml file with the structure of the view and modify the view from the xml, but I do not know how to do it ... 

thanks in advance ...


ok thanks you, I will try it and I will comment the result :)

Crysler Belisario Araujo Enoc
on 5/23/15, 10:46 AM
1

Akhil P Sivan

--Akhil P Sivan--
3423
| 5 3 6
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 10/21/15, 1:11 AM

Hi,

You can have better understanding with an example:

in your xml file, you can define the sequence with the prefix or suffix you need:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<record id="seq_invoice_code" model="ir.sequence.type">
<field name="name">Invoice</field>
<field name="code">account.invoice</field>
</record>

<record id="seq_invoice" model="ir.sequence">
<field name="name">Invoice</field>
<field name="code">account.invoice</field>
<field name="padding">5</field>
<field name="prefix">fact</field>
<field name="suffix">A</field>
</record>

</data>
</openerp>

in your .py file, you can define the readonly field and override the create() to get the sequence on that field:

class account_invoice(models.Model):
_inherit = "account.invoice"

inv_code = fields.Char(string='Code', readonly=True)

@api.v7
def create(self, cr, uid, vals, context=None):
vals['inv_code'] = self.pool.get('ir.sequence').get(cr, uid,'account.invoice')

return super(account_invoice, self).create(cr, uid, vals, context=context)

You can then call this field in the form view wherever you want, by inheriting the corresponding form view.

And you may also check all the sequences available in your current database and can also modify from here:

Settings >> Technical >> Sequences & identifiers >> Sequences

Hope this helps!

0

Dhinesh - Technical Consultant, Sodexis Inc

--Dhinesh - Technical Consultant, Sodexis Inc--
3577
| 5 4 9
Pondicherry, India
--Dhinesh - Technical Consultant, Sodexis Inc--

Passionate coder in Python/OpenERP. Knows Django/Flask MVC frameworks. Did code in Java, PHP.

Contact me at: dvdhinesh.mail@gmail.com

Dhinesh - Technical Consultant, Sodexis Inc
On 5/23/15, 10:00 AM

You should consider using the sequence in invoice module. It has the prefix, suffix and auto increment feature. You need to create a sequence and sequence code. Invoice already has a sequence field there. You should take it has a example. Go through the following links to get the basics:

http://www.zbeanztech.com/blog/sequence-openerp

https://matiar.wordpress.com/2011/09/29/sequence-in-openerp/

http://pinakinnayi.blogspot.in/2012/05/auto-number-generate-in-openerp.html

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

1 follower(s)

Stats

Asked: 5/22/15, 9:57 AM
Seen: 1669 times
Last updated: 10/21/15, 1:36 AM