82. Sql Constraints In Odoo || Constrains In Odoo || Odoo 15 Field Validations

  Рет қаралды 6,393

Odoo Mates

Odoo Mates

Күн бұрын

Пікірлер: 29
@Khmernews-24
@Khmernews-24 6 ай бұрын
Perfect. 🤩
@OdooMates
@OdooMates 6 ай бұрын
thanks
@egyfirst
@egyfirst Жыл бұрын
Perfect. Thank you
@OdooMates
@OdooMates Жыл бұрын
You're welcome!
@OleksiyStepaniuk
@OleksiyStepaniuk Жыл бұрын
Great explanation. Thank you!
@OdooMates
@OdooMates Жыл бұрын
Glad it was helpful!
@wildbeauty9257
@wildbeauty9257 2 жыл бұрын
Thank you. You are doing great work. 👍👍👍
@OdooMates
@OdooMates 2 жыл бұрын
Most welcome 😊
@danakaplan7738
@danakaplan7738 10 ай бұрын
A note for everyone trying this and not worked at the first time check data files for duplicated data, then the data in your module, delete duplicated ones then restart the service and upgrade the module
@mrss7306
@mrss7306 6 күн бұрын
how i can use it for date ?
@muthaiyanselvam4047
@muthaiyanselvam4047 2 жыл бұрын
Hiiiiiii....Odoomates.... i'm regularly following your videos...thanks for your past & future videos........ currently i'm using the odoo14 version..... i tried this sql_constraints............not working in my system............ please advice me class HospitalToggles(models.Model): _name = "patient.toggle" _description = 'Hospital Appointment' name = fields.Char(string='Name') _sql_constraints = [('unique_toggle_name', 'unique(name)', 'name is unique......')]
@OdooMates
@OdooMates 2 жыл бұрын
May be there is existing duplicated names in the db ?
@OdooMates
@OdooMates 2 жыл бұрын
If there is already values that violates the constrains it will not work, try deleting or updating those values manually and try or try in a fresh db
@muthaiyanselvam4047
@muthaiyanselvam4047 2 жыл бұрын
@@OdooMates you are right yes i already fixed in the fields into data files ......., now its working thanks
@futhedude4848
@futhedude4848 2 жыл бұрын
@@OdooMates sir, if there's none values which violates the constrains? How to resolve this?
@OdooMates
@OdooMates 2 жыл бұрын
Fix the existing data manually or use model constrains instead of sql constrains
@kenzasouabni
@kenzasouabni 2 жыл бұрын
after doing this it's always related by id per default not by the field that i need , why?
@OdooMates
@OdooMates 2 жыл бұрын
can you elaborate with your code
@kenzasouabni
@kenzasouabni 2 жыл бұрын
@@OdooMates yeah sure _name = "module.dd" _description = "Dd" _inherits = {'module.A': 'champ1'} _rec_name = 'champ2' champ1 = fields.Many2one('module.A', required=True, ondelete='restrict', auto_join=True, string="Related champ1") champ2= fields.Char(string="champ2") _sql_constraints = [('unique_champ_name', 'unique(champ1)', 'champ1 must be unique !')]
@kenzasouabni
@kenzasouabni 2 жыл бұрын
and the class A is like this _name = "module.A" _description = "A" _rec_name = "champ1" champ1 = fields.Integer(string="champ1", required=True) _sql_constraints = [('unique_name', 'unique(champ1)', 'champ1 must be unique !')]
@OdooMates
@OdooMates 2 жыл бұрын
@@kenzasouabni so if you enter duplicated value in the champ1 field, warning is not raised ?
@kenzasouabni
@kenzasouabni 2 жыл бұрын
@@OdooMates The error "NS must be unique" raised but when I want to see the tables in the command prompt, field1 of table A is correct but field1 of table dd is not the same as table A it returns me the value of the id in field1 and not the value of field1
@eventdz6182
@eventdz6182 2 жыл бұрын
it's not working in odoo 15
@OdooMates
@OdooMates 2 жыл бұрын
This will work in all versions, may be there is already some record that violating this constrains?
@futhedude4848
@futhedude4848 2 жыл бұрын
this _sql_constraints have a huge weakness that if there's already some records which have values violates the rules, then that rule is not affected. in that case, we should use @api.constrains instead. in fact, this is not good to use, i recommend to use @api.constrains instead of _sql_constraints in every posible way.
@OdooMates
@OdooMates 2 жыл бұрын
the advantages sql constrains is,it is much faster than api constrains
@futhedude4848
@futhedude4848 2 жыл бұрын
@@OdooMates thanks you.
The selfish The Joker was taught a lesson by Officer Rabbit. #funny #supersiblings
00:12
Funny superhero siblings
Рет қаралды 11 МЛН
Seja Gentil com os Pequenos Animais 😿
00:20
Los Wagners
Рет қаралды 10 МЛН
Flipping Robot vs Heavier And Heavier Objects
00:34
Mark Rober
Рет қаралды 19 МЛН
Think Fast, Talk Smart: Communication Techniques
58:20
Stanford Graduate School of Business
Рет қаралды 41 МЛН
Debugging a Complex T-SQL Issue
1:00:54
Brent Ozar Unlimited
Рет қаралды 4 М.
Odoo 16 custom addons development | Add a field to a Model
19:47
Odoo Discussions
Рет қаралды 7 М.
The selfish The Joker was taught a lesson by Officer Rabbit. #funny #supersiblings
00:12
Funny superhero siblings
Рет қаралды 11 МЛН