Hello,
Please Check this code,
from_date = fields.Date("From Date")
to_date = fields.Date("To Date")
month_days = fields.Selection([('Monday','Monday'),('Tuesday','Tuesday'),
('Wednesday','Wednesday'),('Thursday','Thursday'),
('Friday','Friday'),('Saturday','Saturday'),
('Sunday','Sunday')], "Day")
day_count = fields.Integer("Number Of Days")
@api.onchange('from_date', 'to_date', 'month_days')
def onchange_count_days(self):
count_days = 0
if self.from_date and self.to_date and self.month_days:
day_from = datetime.strptime(self.from_date, "%Y-%m-%d")
day_to = datetime.strptime(self.to_date, "%Y-%m-%d")
nb_of_days = (day_to - day_from).days + 1
for day in range(0, nb_of_days):
if day == 0 and str(day_from.strftime('%A')) == str(self.month_days):
count_days += 1
else:
month_date = day_from + relativedelta(days=day)
if str(month_date.strftime('%A')) == str(self.month_days):
count_days += 1
self.day_count = count_days
Hope it will work for you,
Thanks