コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
2835 ビュー

I override create method@api.model

def create(self, vals):
if vals.get('branch_id'):
fields_to_check = ['drawer_id', 'flexible_id', 'runner_id', 'group_1_id', 'group_2_id', 'group_3_id']
fields_to_check_in_vals = [vals.get(f) for f in fields_to_check]
if not any(fields_to_check_in_vals):
raise UserError('If branch is selected then you need to select one of the fields from data raport')
return super(ResPartner, self).create(vals)

it checks if branch_id is checked then 1 of the fields from fields_to_check should be seleced.

How can i do the same for write method. If some one selects branch_id fields then 1 of the fields from fields_to_check = ['drawer_id', 'flexible_id', 'runner_id', 'group_1_id', 'group_2_id', 'group_3_id'] should be selected to. 



アバター
破棄
最善の回答

Hello Grf,


Try below code :-

@api.multi
def write(self, vals):
    res = super(ResPartner, self).write(vals)
    if self.branch_id:
        if not self.drawer_id or not self.flexible_id or not self.runner_id or not self.group_1_id or not self.group_2_id or not self.group_3_id:
            raise UserError('If branch is selected then you need to select one of the fields from data raport')
    return res


Hope it will helps you.

Thanks,

アバター
破棄

res is a boolean !

you either get the value from the record ( you should make a loop on self) or from the vals : vals.get('branch_id', False) and so on

See my updated answer. Thanks,

関連投稿 返信 ビュー 活動
1
3月 15
5294
0
4月 15
4622
2
6月 23
2237
1
2月 21
4811
1
6月 20
35289