我有一个One2many字段。在这个字段中,我有复选框字段。而且,我已经对复选框的选择进行了验证。功能运作得很好。现在,当我选择check时,值将返回,如果未选中,则没有问题。但是,现在我希望如果选中One2many字段中的任何行复选框,那么值返回,否则它会显示警告。意味着,来自整个One2many的单行复选框足以返回值。
我的代码在这里:
@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)提前谢谢
发布于 2017-10-25 10:08:28
我认为你需要加上约束,那就回一个警告;
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")https://stackoverflow.com/questions/46929212
复制相似问题