This question has been flagged

Hello Everyone,

I have to try to apply validation on checkbox. In my process they have product with a multiple option.

So how to apply validation on check box for both option one product option must be select otherwise validation error show. my code below :

m1 = []
for m in self.wizard:
 # print "r::::", m , m.services.gold_service
 if m.services:
 aa =(m.check_box,m.services.id)
 m1.append(aa)
 #print "aaa", m1
 if m.check_box not in m1:
 print "hello", m1
 raise ValidationError("a")

and my terminal show 

hello [(False, 3), (True, 3), (True, 4)]

hello [(False, 3), (True, 3), (True, 4), (False, 4)]


Thanks in advanced.

Avatar
Discard
Author Best Answer

Solution for above problem

@api.multi
def action_optional_flag_add(self):
m1 = []
for m in self.wizard:
if m.services:
aa = (m.services.id, m.check_box)
m1.append(aa)
count_num = dict(Counter(m1))
res_allrecord = []
for val in count_num:
res_allrecord.append(val[0])
list_res = list(set(res_allrecord))

res_True = []
for val in count_num:
if val[1] != False:
res_True.append(val)
count = Counter([x for (x, y) in res_True])
rec5 = dict(count)

for list_val in list_res:
if list_val not in rec5:
rec5[list_val] = 0
output = dict(count)

for key, value in rec5.items():
if value > 1:
raise ValidationError("Please Select Atlease One Item from Flag")
if value == 0:
raise ValidationError("Please Select Atlease One Item from Flag")
Avatar
Discard