add ne tab on hr.official.mission ,tran, date duration on the end

This commit is contained in:
blackbelts 2025-06-16 16:07:23 +03:00
parent 7f0298f1ca
commit af4399b4ef
1 changed files with 32 additions and 29 deletions

View File

@ -105,6 +105,7 @@ class HrOfficialMission(models.Model):
@api.onchange('hour_duration', 'date_duration')
@api.constrains('hour_duration', 'date_duration')
def compute_number_of_hours(self):
for item in self:
@ -275,40 +276,42 @@ class HrOfficialMission(models.Model):
start_mission_date = datetime.strptime(str(item.date_from), "%Y-%m-%d")
end_mission_date = datetime.strptime(str(item.date_to), "%Y-%m-%d")
if end_mission_date >= start_mission_date:
if not item.table_ids:
if end_mission_date >= start_mission_date:
if not item.table_ids:
days = (end_mission_date - start_mission_date).days
item.date_duration = days + 1
# days = (end_mission_date - start_mission_date).days
# item.date_duration = days + 1
date_range = [start_mission_date.date() + timedelta(days=i)
for i in range((end_mission_date - start_mission_date).days + 1)]
if item.mission_type.working_days:
calendar = item.company_id.resource_calendar_id
if not calendar:
raise ValidationError(_('Company working calendar is not configured.'))
weekend_days = calendar.full_day_off or calendar.shift_day_off
weekend_names = [d.name.lower() for d in weekend_days]
date_range = [d for d in date_range if d.strftime('%A').lower() not in weekend_names]
item.date_duration = len(date_range)
if not item.table_ids:
days = (end_mission_date - start_mission_date).days
item.date_duration = days + 1
else:
unique_dates = set(item.table_ids.mapped('date'))
item.date_duration = len(unique_dates)
# days = (end_mission_date - start_mission_date).days
# item.date_duration = days + 1
date_range = [start_mission_date.date() + timedelta(days=i)
for i in range((end_mission_date - start_mission_date).days + 1)]
if item.mission_type.working_days:
calendar = item.company_id.resource_calendar_id
if not calendar:
raise ValidationError(_('Company working calendar is not configured.'))
weekend_days = calendar.full_day_off or calendar.shift_day_off
weekend_names = [d.name.lower() for d in weekend_days]
date_range = [d for d in date_range if d.strftime('%A').lower() not in weekend_names]
item.date_duration = len(date_range)
# item.duration = 0.0
raise exceptions.Warning(_('Date Form Must Be Less than Date To'))
if item.mission_type.maximum_days > 0.0:
if item.date_duration > item.mission_type.maximum_days:
raise exceptions.Warning(
_('mission duration must be less than "%s" maximum days in mission type "%s" ') % (
item.mission_type.maximum_days, item.mission_type.name))
else:
# item.duration = 0.0
raise exceptions.Warning(_('Date Form Must Be Less than Date To'))
unique_dates = set(item.table_ids.mapped('date'))
item.date_duration = len(unique_dates)
if item.mission_type.maximum_days > 0.0:
if item.date_duration > item.mission_type.maximum_days:
raise exceptions.Warning(
_('mission duration must be less than "%s" maximum days in mission type "%s" ') % (
item.mission_type.maximum_days, item.mission_type.name))
# Difference hour duration
# elif item.mission_type.duration_type == 'hours':
if item.hour_from == 0.0: