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

only number in value of char [Closed]

By
Susi
on 12/23/14, 12:44 AM 747 views

The Question has been closed

by
Susi
on 01/21/2016 23:17:51

i have a field with type char i want this field only have number value

for example : 023455

how can i make it?

Bole, what about the Help attribute ?

Gopalakrishnan Kasilingam
on 12/23/14, 5:29 AM
3

Anil R. Kesariya

--Anil R. Kesariya--
4321
| 6 5 8
Gandhinagar, India
--Anil R. Kesariya--
ERP Consultant

Key Skill
-
Technical & Functional Expert
Anil R. Kesariya
On 12/23/14, 1:02 AM

Hello Susi ,

You have three option you can use

constraints or on change method.

 

Eg. 1) by using widget (as Ben Bernard said):

in  your xml file inside form view.

<field name="your_field" widget="integer"/>

 

Eg. 2) by using constraint.

#by using constraint you can raise your own warning message on the screen if user enter the #wrong value.

_columns = { 'your_field':fields.char('Your Field Label')}

def check_numval(self, cr, uid, ids, context=None):

    for obj in self.browse(cr, uid, ids, context = context): 

        val = obj.your_field

        if val.isdigit():

            return True

        else:

            return False

_constraints = [(check_numval, 'Enter Value is not correct!', ['your_field']), ]

 

#like wise you can apply in onchange method, you can is isdigit() method to check entered value.

Hope this will helps you.

thank u Anil Kesariya its work :)

Susi
on 12/23/14, 1:24 AM

if i want two field with using constraint,,how i make it?

Susi
on 12/23/14, 1:27 AM

you can use the same method check for both the field in condition simple, pass both field as argument in list.

Anil R. Kesariya
on 12/23/14, 1:46 AM
1

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 12/23/14, 5:21 AM

and you can use onchange method like

in xml: 
<field name="field_name" on_change="check_numeric(field_name)" />

py:
def check_numeric(self, cr, uid, ids, value, context=None:
    try:
       test = int(value) #->be creative with check... this is basic
    except:
        return {'warning':{'title':'error','message':'value should be numeric'}}
    return True

hope it helps

        

 

0

Ben Bernard

--Ben Bernard--
1083
| 4 3 6
Jakarta, Indonesia
--Ben Bernard--
Ben Bernard
On 12/23/14, 5:35 AM

You can also use attribute integer widget in the field: widget="integer"

About This Community

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

Question tools

3 follower(s)

Stats

Asked: 12/23/14, 12:44 AM
Seen: 747 times
Last updated: 1/21/16, 11:17 PM