0
2 Answers
0
Best Answer
Hi,
This error is caused because of multiple values/null values in an instance(Units_ids), thus here we need to loop this field and then we can check the condition;
Please try this.
@api.onchange('date', 'Units_ids')
def _get_day_of_date(self):
for r in self:
if r.date:
selected = fields.Datetime.from_string(r.date)
r.date_day = calendar.day_name[selected.weekday()].lower()
dayoff = r.Units_ids.mapped('dayoff')
for record in dayoff:
if record ==calendar.day_name[selected.weekday()].lower():
raise UserError(
_(F'This Day( {calendar.day_name[selected.weekday()]} ) Is Day Off For This Unit , Please Choose Another Unit!'))
Regards