Odoo Help

0

1
3 Answers
0
notteccon
2019/6/10 下午2:30

Hi Hilar AK, thanks for your answer.

I'm not asking about validation ( odoo.api.constrains(*args) ), but about manual values verification by an user ("Peterrrr" is a valid value for the name field, but an user need to confirm or verify that). Maybe i don't explain it well. I'll update the question to clarify.

0
Justin Chen
2019/6/9 下午11:08

I think Hilar's answer is the correct way to implement field validation.  

On top of that, in the newapi (v9 or newer), when raising exceptions, 'Warning' is deprecated, UserError and ValidationError are preferred in odoo api.  

UserError is more of a front-end way to avoid user input undesired value.   
ValidationError is designed for function or access right that type of thing.  

Also, I personally would make the constraint method private as well.

0
Avatar

Hilar AK

--Hilar AK--
--Hilar AK--
  Blog:-
        https://hilarlive.wordpress.com/
  StackOverflow:
        http://stackoverflow.com/users/7561347/burmese-pythis

Quora:
    

            https://www.quora.com/profile/Hilar-Ak-1

Experienced Odoo developer, Functional Consultant.



Hilar AK
2019/6/9 上午1:21

Just add some constraints for the fields. You can use SQL Constraints or write in python also using the decorator 

@api.constraints. 

eg:


@api.constrains('field_name')
def field_name_constratints(self):
if condition:
raise Warning(message)


Ask a Question
Writer
Tags
Keep Informed
1 follower(s)
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 eLearning platform and experience all Odoo Apps through learning videos, use cases and quizzes.

Test it now