Odoo Help

0

I'm trying to validate a field

By
Uillino
on 8/17/15, 6:25 AM 650 views

I'm tryng to validate a field, so I've written this code:

        @api.one
@api.constrains('code')
def control_code(self):
i=0
a=1
while i<9:
if i==0:
if unicode.isdigit(self.code[0]):
a=i+1
raise Warning(("Warning!\nThe character %s must be a letter") % (a))
elif i in range (1,4) or i in range (5,10):
if not unicode.isdigit(self.code[i]):
raise Warning(('Warning!\nThe character %s must be a number') % (a))
elif i == 4:
if self.code[i] is not '/':
raise Warning(("Warning!\nThe character %s must be '/'") % (a))
i=i+1
a=a+1

Everything works fine, except for i==4. Even if I put a '/', I get the warning message.

Anyone knows why?

2

Drees Far

--Drees Far--
1154
| 5 2 6
Tunis, Tunisia
--Drees Far--
Drees Far
On 8/17/15, 6:46 AM

Hi friend:

Try this

if self.code[i] !=  '/':

raise Warning(("Warning!\nThe character %s must be '/'") % (a))

Use != (preferred) or <> (deprecated). See comparison operators : https://docs.python.org/release/2.5.2/lib/comparisons.html. For comparing object identities, you can use the keyword is and its negation is not.

Regards.


It works! Thank you!

Uillino
on 8/17/15, 7:18 AM

Happy for you :) You Re WELCOME

Drees Far
on 8/17/15, 7:20 AM
1

Axel Mendoza

--Axel Mendoza--
12136
| 7 8 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 8/17/15, 6:47 AM

Maybe because you are checking if self.code[i] is not '/' and raising the error based in var a, when:

i = 4

a = 5

Maybe you expect some string in code like:

'http://www'

For something like this you need to check:

if self.code[a] is not '/':


0

Tarek Mohamed Ibrahim

--Tarek Mohamed Ibrahim--
904
| 5 3 7
Gîza, Egypt
--Tarek Mohamed Ibrahim--

I am an old VFP developer on ERP

I have moved to 2p since Nov-2014 and started developing with Python on Odoo.

https://www.linkedin.com/profile/public-profile-settings?trk=prof-edit-edit-public_profile

tibrahim@2p.com.sa

Tarek Mohamed Ibrahim
On 8/17/15, 7:06 AM

Try

if self.code[i] != chr(47):



About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)

Stats

Asked: 8/17/15, 6:25 AM
Seen: 650 times
Last updated: 8/17/15, 7:18 AM