Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2 Ответы
6209 Представления

company_id = filed.Many2one('res.company','Company', required=True)

I defined a field like this. When I open a form, I must fill this company_id to complete save.Unfortunatly, when i use import function, the company_id is not necessary anymore. I can finish validate without company_id.

So , how can I make this field checked when I use import function?

Аватар
Отменить
Лучший ответ

Constraints are actually evaluated only when a modification on that field is done. when your field is required param set, you cant save the form until it is filled. You should define the company id on the desired form first.

Another option is, override the orm function write() and check the dict contain the value company_id, if not raise the error.

Аватар
Отменить
Автор Лучший ответ

I find a way to work. But it's not perfect.Like this:

Would you please give me some advise.tks

@api.constrains('license_plate')
def _validate_plate(self):    
    res = self.env['fleet.vehicle'].sudo().search([('license_plate', '=', self.license_plate)])    
    if len(res) > 1:        
        raise ValidationError('This license plate already exist')    
    else:                
        if not res.company_id:                        
            raise ValidationError('You must choose company!')

Why I can't use below code? In fact, it's never execute for some reason, which i don't know.

@api.constrains('company_id')
def _check_company(self):    
    if not self.company_id:        
        raise ValidationError('You must choose company!')
Аватар
Отменить
Related Posts Ответы Просмотры Активность
1
сент. 23
2008
4
апр. 25
1030
0
апр. 25
391
3
февр. 23
4249
0
окт. 22
1640