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.

1

how fill zeros at left in a field in Odoo

By
Crysler Belisario Araujo Enoc
on 5/9/15, 5:12 PM 429 views

Hi, my question is about  how fill zeros at left in a field before save into BD...

my class:

class cliente(models.Model):

_inherit = 'res.partner'

Documento=fields.Selection((('V','V'),('E','E'),('J','J'),('P','P'),('G','G')),size=2, help="V=Venezolana , E= Extranjera , J= Juridico , P=Personal , G=Gubernamental", required=True)

cedula=fields.Char(size=11,default=None,string="Cedula De Identidad", help="acredita la identidad",required=True)


my views


<?xml version="1.0" encoding="UTF-8"?>

<openerp>

<data>

  

<record model="ir.ui.view" id="partner_form_view">

<field name="model">res.partner</field>

<field name="inherit_id" ref="base.view_partner_form"/>

<field name="arch" type="xml">

  

<group>

<field name="Documento"/>

<field name="cedula"/>

  

</group>

  

</field>

</record>

<!-- este es un acceso directo a la barra principal del menu-->

<menuitem id="menucontactos" name="Contactos"/>

<record model="ir.actions.act_window" id="contact_list_action">

<field name="name">Contactos de la Empresa</field>

<field name="res_model">res.partner</field>

<field name="view_mode">tree,form</field>

</record>

<menuitem id="configuration_menu" name="Configuraciones"

parent="menucontactos"/>

<menuitem id="contact_menu" name="Contacts"

parent="configuration_menu"

action="contact_list_action"/>

  

</data>

</openerp>

my idea is when press save button, fill zeros at left in a field cedula, Example:

anybody write 123 in field cedula:

cedula<= 123

then press save button

automatically 

cedula<=00000123

save into DB 00000123, not 123...


Thank you :D

0

Atchuthan - Technical Consultant, Sodexis Inc

--Atchuthan - Technical Consultant, Sodexis Inc--
3883
| 5 3 8
Puducherry, India
--Atchuthan - Technical Consultant, Sodexis Inc--
Passionate coder in Python/Odoo(formerly known as OpenERP).

Contact me via GMail: atchuthantu@gmail.com via Skype: atchuthan_skype
via Linkedin: http://in.linkedin.com/in/atchuthantu
Atchuthan - Technical Consultant, Sodexis Inc
On 5/12/15, 4:17 AM

You could either use WRITE/CREATE method or on_change(preferable) method as Ahmed mentioned

cedula = 123
print '{0:08d}'.format(i)
http://stackoverflow.com/questions/733454/best-way-to-format-integer-as-string-with-leading-zeros

0

Ahmed M.Elmubarak

--Ahmed M.Elmubarak--
2988
| 5 3 5
Sudan
--Ahmed M.Elmubarak--


Ahmed M.Elmubarak
On 5/11/15, 4:12 AM

Hi, you can mange this with on_change method..

Regards ..

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: 5/9/15, 5:12 PM
Seen: 429 times
Last updated: 5/12/15, 4:17 AM