仅对一行值应用复选框条件,否则在 Odoo10 中显示警告
Apply check-box condition for only one row value else show warning in Odoo10
我有一个 One2many 字段。在这个字段中,我有复选框字段。而且,我已经为复选框选择应用了验证。而且功能很好。现在,当我选择检查时,值为 returning,如果未选择,则没有问题。但是,现在我希望如果选中 One2many 字段中的任何行复选框,则值 return 否则它会显示警告。意思是,整体 One2many 中的单行复选框足以满足价值 returning.
我的代码在这里:
@api.multi
def action_salepack_add(self):
rec = self._context.get('active_ids', [])
wiz = [q.id for q in self.wizard]
res_wiz= []
#here is check box condition#
for s in self.wizard:
if s.check_box==True:
res_wiz.append(s.id)
#check-box condition over#
if rec:
line_values = {'product_id': self.product_id.id,
'wizards': [(6, 0, res_wiz)],
}
sale_order_line = self.env['sale.order.line'].create(line_values)
提前致谢
我认为您需要添加约束,即 return 警告;
from openerp.exceptions import ValidationError
@api.constrains('wizard') # wizard is the one2many field
def _check_grade_choisi(self):
for record in self:
l = []
if not any([s.check_box for s in record.wizard]) : #Here i check if all checkbox field is False
raise ValidationError("Your warning")
我有一个 One2many 字段。在这个字段中,我有复选框字段。而且,我已经为复选框选择应用了验证。而且功能很好。现在,当我选择检查时,值为 returning,如果未选择,则没有问题。但是,现在我希望如果选中 One2many 字段中的任何行复选框,则值 return 否则它会显示警告。意思是,整体 One2many 中的单行复选框足以满足价值 returning.
我的代码在这里:
@api.multi
def action_salepack_add(self):
rec = self._context.get('active_ids', [])
wiz = [q.id for q in self.wizard]
res_wiz= []
#here is check box condition#
for s in self.wizard:
if s.check_box==True:
res_wiz.append(s.id)
#check-box condition over#
if rec:
line_values = {'product_id': self.product_id.id,
'wizards': [(6, 0, res_wiz)],
}
sale_order_line = self.env['sale.order.line'].create(line_values)
提前致谢
我认为您需要添加约束,即 return 警告;
from openerp.exceptions import ValidationError
@api.constrains('wizard') # wizard is the one2many field
def _check_grade_choisi(self):
for record in self:
l = []
if not any([s.check_box for s in record.wizard]) : #Here i check if all checkbox field is False
raise ValidationError("Your warning")