def _create_task_from_procurement_service_project(self, procurement): task = super( ProjectTask, self)._create_task_from_procurement_service_project(procurement) if task.service_project_sale_line.order_id.project_by_task == 'yes': parent_account = task.project_id.analytic_account_id code = self.env['ir.sequence'].get('account.analytic.account') new_account = self._create_new_account_project_by_task( task, parent_account, code) cond = [('analytic_account_id', '=', new_account.id)] project = self.env['project.project'].search(cond, limit=1) duration = task.service_project_sale_line.performance or 1 begin_date = _convert_to_local_date(task.date_start, tz=self.env.user.tz).date() until_date = _convert_to_local_date(task.date_end, tz=self.env.user.tz).date() task.write({ 'project_id': project.id, 'begin_date': begin_date, 'until_date': until_date, 'start_hour': task.service_project_sale_line.start_hour, 'duration': duration }) task.project_id = project.id new_account.date = parent_account.date project.date = parent_account.date sale_name = task.service_project_sale_line.order_id.name if not self.env.context.get('without_sale_name', False): parent_account.write({'name': sale_name}) return task
def button_group_description(self): tz = self.env.user.tz for line in self: description = u'{}-{}'.format(line.order_id.name, line.sequence) if line.courses: description += '-' + line.courses if line.monday: description += '-' + _('Monday') if line.tuesday: description += '-' + _('Tuesday') if line.wednesday: description += '-' + _('Wednesday') if line.thursday: description += '-' + _('Thursday') if line.friday: description += '-' + _('Friday') if line.saturday: description += '-' + _('Saturday') if line.sunday: description += '-' + _('Sunday') if line.product_id.recurring_service: utc_dt = _convert_to_utc_date(line.start_date, line.start_hour, tz) local = _convert_to_local_date(utc_dt, tz) description += '-' + str(local)[11:16] utc_dt = _convert_to_utc_date(line.end_date, line.end_hour, tz) local = _convert_to_local_date(utc_dt, tz) description += '-' + str(local)[11:16] line.group_description = description
def _validate_employee_contract_and_registration(self, line): tz = self.env.user.tz contract_obj = self.env['hr.contract'] vals = self._prepare_dates_for_registration(line) date_from = _convert_to_local_date(vals.get('date_start'), tz=tz).date() date_to = _convert_to_local_date(vals.get('date_end'), tz=tz).date() cond = contract_obj._search_contracts_without_date_end( line.employee.address_home_id, date_from) permitted_contracts = contract_obj.search(cond) cond = contract_obj._search_contracts_with_date_end( line.employee.address_home_id, date_to, date_from) permitted_contracts += contract_obj.search(cond) if not permitted_contracts: raise exceptions.Warning( _("Employee %s without contract for event %s") % (line.employee.name, line.event.name)) registrations = line.event.registration_ids.filtered( lambda x: x.partner_id and x.date_start and x.date_end and x.state in ('done', 'open' ) and x.partner_id.id == line.employee.address_home_id.id and ( (str(vals.get('date_end')) >= x.date_start and str( vals.get('date_end')) <= x.date_end) or (str(vals.get('date_start')) <= x.date_end and str( vals.get('date_start')) >= x.date_start))) if registrations: raise exceptions.Warning( _('You can not confirm this registration, because their ' 'dates overlap with another record of the same employee,' ' in event: %s') % (line.event.name)) return vals
def _prepare_dates_for_registration(self, line): tz = self.env.user.tz vals = { 'event_id': line.event.id, 'partner_id': line.employee.address_home_id.id, 'replaces_to': self.holiday.employee_id.address_home_id.id } start_time = _convert_time_to_float(line.event.date_begin, tz=tz) vals['date_start'] = max( _convert_to_utc_date(_convert_to_local_date(line.event.date_begin, tz=tz).date(), start_time, tz=tz), _convert_to_utc_date(_convert_to_local_date(self.holiday.date_from, tz=tz).date(), start_time, tz=tz)) end_time = _convert_time_to_float(line.event.date_end, tz=tz) vals['date_end'] = min( _convert_to_utc_date(_convert_to_local_date(line.event.date_end, tz=tz).date(), end_time, tz=tz), _convert_to_utc_date(_convert_to_local_date(self.holiday.date_to, tz=tz).date(), end_time, tz=tz)) return vals
def _search_permitted_contracts(self, registration): contract_obj = self.env['hr.contract'] permitted_contracts = self.env['hr.contract'] tz = self.env.user.tz if not registration.date_start: registration.date_start = registration.event_id.date_begin if not registration.date_end: registration.date_end = registration.event_id.date_end date_start = date2str(_convert_to_local_date( registration.date_start, tz=tz).date()) date_end = date2str(_convert_to_local_date( registration.date_end, tz=tz).date()) cond = contract_obj._search_contracts_without_date_end( registration.partner_id, date_end) contracts = contract_obj.search(cond) for contract in contracts: if contract not in permitted_contracts: permitted_contracts += contract cond = contract_obj._search_contracts_with_date_end( registration.partner_id, date_start, date_end) contracts = contract_obj.search(cond) for contract in contracts: if contract not in permitted_contracts: permitted_contracts += contract return permitted_contracts
def _update_event_dates(self, old_date, new_days, new_date, begin=False, end=False): project_obj = self.env['project.project'] tz = self.env.user.tz vals = {} if begin: vals['date_begin'] =\ str2datetime(self.date_begin).replace( year=new_date.year, month=new_date.month, day=new_date.day) elif end: vals['date_end'] =\ str2datetime(self.date_end).replace( year=new_date.year, month=new_date.month, day=new_date.day) self.with_context(sale_order_create_event=True, no_recalculate=True).write(vals) if begin: registrations = self.registration_ids.filtered( lambda x: str2datetime(x.date_start).date() == old_date) for registration in registrations: registration.date_start =\ str2datetime(registration.date_start).replace( year=new_date.year, month=new_date.month, day=new_date.day) self.my_task_ids.write({'date_start': self.date_begin}) new_date = _convert_to_local_date(self.date_begin, tz=tz).date() projects = self.mapped('my_task_ids.project_id') projects.write({'date_start': new_date}) accounts = projects.mapped('analytic_account_id') accounts.write({'date_start': new_date}) if end: registrations = self.registration_ids.filtered( lambda x: str2datetime(x.date_end).date() == old_date) for registration in registrations: registration.date_end =\ str2datetime(registration.date_end).replace( year=new_date.year, month=new_date.month, day=new_date.day) self.my_task_ids.write({'date_end': self.date_end}) new_date = _convert_to_local_date(self.date_end, tz=tz).date() projects = self.mapped('my_task_ids.project_id') projects.write({'date': new_date}) accounts = projects.mapped('analytic_account_id') accounts.write({'date': new_date}) if self.sale_order and self.sale_order.project_id and (begin or end): if begin: self.sale_order.project_id.date_start = new_date if end: self.sale_order.project_id.date = new_date cond = [('analytic_account_id', '=', self.sale_order.project_id.id) ] project = project_obj.search(cond, limit=1) if project and begin: project.date_start = new_date if project and end: project.date = new_date
def _put_init_dates_in_wizard(self): tz = self.env.user.tz if not self.from_date: self.from_date = _convert_to_local_date( self.min_from_date, tz=tz).date() if not self.to_date: self.to_date = _convert_to_local_date( self.max_to_date, tz=tz).date()
def _catch_employee_presences(self, holiday): presence_obj = self.env['event.track.presence'] tz = self.env.user.tz date_from = date2str(_convert_to_local_date(holiday.date_from, tz=tz)) date_to = date2str(_convert_to_local_date(holiday.date_to, tz=tz)) cond = [('partner', '=', holiday.employee_id.address_home_id.id), ('session_date_without_hour', '>=', date_from), ('session_date_without_hour', '<=', date_to)] presences = presence_obj.search(cond) return presences
def _update_partner_calendar_day(self, holiday, absence_type=False): calendar_day_obj = self.env['res.partner.calendar.day'] tz = self.env.user.tz date_from = date2str(_convert_to_local_date(holiday.date_from, tz=tz)) date_to = date2str(_convert_to_local_date(holiday.date_to, tz=tz)) cond = [('partner', '=', holiday.employee_id.address_home_id.id), ('date', '>=', date_from), ('date', '<=', date_to)] days = calendar_day_obj.search(cond) if absence_type: days.write({'absence': True, 'absence_type': absence_type}) return True self._update_calendar_days_from_presences(holiday, days) return True
def _find_events_for_substitution_employee(self): tz = self.env.user.tz presence_obj = self.env['event.track.presence'] self.ensure_one() date_from = date2str(_convert_to_local_date(self.date_from, tz=tz)) date_to = date2str(_convert_to_local_date(self.date_to, tz=tz)) cond = [('partner', '=', self.employee_id.address_home_id.id), ('session_date_without_hour', '>=', date_from), ('session_date_without_hour', '<=', date_to), ('state', '=', 'pending')] presences = presence_obj.search(cond) events = presences.mapped('event') return events
def button_substitution_employee(self): tz = self.env.user.tz self._validate_employee_calendar( _convert_to_local_date(self.holiday.date_from, tz=tz).year, _convert_to_local_date(self.holiday.date_to, tz=tz).year, self.holiday.employee_id.address_home_id) for line in self.lines: vals = self._validate_employee_contract_and_registration(line) self._validate_employee_calendar( vals.get('date_start').year, vals.get('date_end').year, line.employee.address_home_id) threaded_calculation = threading.Thread( target=self.button_substitution_employee_from_thread) threaded_calculation.start()
def substitution_employee_from_thread(self): registration_obj = self.env['event.registration'] presence_obj = self.env['event.track.presence'] registrations = self.env['event.registration'] wiz_obj = self.env['wiz.event.registration.confirm'] wiz = wiz_obj.create({'name': 'Confirm registration'}) tz = self.env.user.tz self.ensure_one() for line in self.lines: vals_reg = self._prepare_dates_for_registration(line) registration = registration_obj.create(vals_reg) if line.confirm_registration: registrations += registration if len(registration.contracts_permitted) == 1: registration.contract = registration.contracts_permitted[0].id m = ( "<p> " + fields.Date.context_today(self) + ': ' + _('The employee: %s, replaces the employee: %s, from date %s,' ' to date %s') % (line.employee.address_home_id.name, self.holiday.employee_id.address_home_id.name, date2str(_convert_to_local_date(self.holiday.date_from, tz=tz)), date2str(_convert_to_local_date(self.holiday.date_to, tz=tz))) + "<br>") m += "<br> <br>" vals = { 'type': 'comment', 'model': 'event.event', 'record_name': line.event.name, 'res_id': line.event.id, 'body': m } self.env['mail.message'].create(vals) cond = [('event', '=', vals_reg.get('event_id')), ('partner', '=', self.holiday.employee_id.address_home_id.id), ('session_date_without_hour', '>=', vals_reg.get('date_start').date()), ('session_date_without_hour', '<=', vals_reg.get('date_end').date())] presences = presence_obj.search(cond) presences.write({'state': 'canceled'}) self.holiday.signal_workflow('validate') self.holiday._update_presences_validate_holiday() self.holiday._update_partner_calendar_day( self.holiday, absence_type=self.holiday.holiday_status_id.id) wiz.with_context({ 'active_ids': registrations.ids }).action_confirm_registrations()
def _update_wizard_vals(self, wiz_vals): tz = self.env.user.tz date_start = self.date_start or self.event_id.date_begin date_end = self.date_end or self.event_id.date_end from_date = _convert_to_local_date(date_start, tz=tz) start_time = _convert_time_to_float(date_start, tz=tz) to_date = _convert_to_local_date(date_end, tz=tz) end_time = _convert_time_to_float(date_end, tz=tz) wiz_vals.update({ 'from_date': from_date.date(), 'start_time': start_time, 'to_date': to_date.date(), 'end_time': end_time, }) return wiz_vals
def _account_info_for_create_task_service_project(self, vals, procurement): tz = self.env.user.tz vals = super( ProjectTask, self)._account_info_for_create_task_service_project( vals, procurement) project = procurement.sale_line_id.order_id.project_id if project.date_start and project.start_time: date_start = _convert_to_local_date( project.date_start, tz=tz).date() time = project.start_time vals['date_start'] = _convert_to_utc_date(date_start, time, tz=tz) if project.date and project.end_time: date_end = _convert_to_local_date(project.date, tz=tz).date() time = project.end_time vals['date_end'] = _convert_to_utc_date(date_end, time, tz=tz) return vals
def _prepare_session_data_from_sale_line(self, event, num_session, line, date): vals = super(SaleOrder, self)._prepare_session_data_from_sale_line( event, num_session, line, date) vals['name'] = (_('Session %s for %s') % (str(num_session), line.session_description)) new_date = False if line.order_id.project_id: new_date = _convert_to_utc_date( date, time=line.order_id.project_id.start_time, tz=self.env.user.tz) duration = (line.order_id.project_id.end_time - line.order_id.project_id.start_time) if line.order_id.project_id.working_hours: from_date = _convert_to_local_date(date, self.env.user.tz) day = str(from_date.date().weekday()) lines = line.order_id.project_id.working_hours.attendance_ids for line2 in lines: if line2.dayofweek == day: new_date = _convert_to_utc_date(date, time=line2.hour_from, tz=self.env.user.tz) duration = line2.hour_to - line2.hour_from if line.start_hour or line.end_hour: new_date = _convert_to_utc_date(date, time=line.start_hour, tz=self.env.user.tz) duration = line.end_hour - line.start_hour if new_date: vals.update({'date': new_date, 'duration': duration}) return vals
def _compute_first_day_of_class(self): for reg in self.filtered( lambda x: x.event_id and x.event_id.track_ids): session = min(reg.event_id.track_ids, key=lambda x: x.date) if session: reg.first_day_of_class = _convert_to_local_date( session.date, self.env.user.tz)
def create(self, vals): session_date = _convert_to_local_date(vals.get('date'), tz=self.env.user.tz) if session_date.weekday() == 6: vals['type_hour'] = self.env.ref( 'sale_order_create_event_hour.type_hour_sunday').id return super(EventTrack, self).create(vals)
def export_profit(self, sheet1): presence_obj = self.env['event.track.presence'] boldFont = xl.Font() boldFont.bold = True boldS = xl.XFStyle() boldS.font = boldFont boldFont14 = xl.Font() boldFont14.bold = True boldFont14.height = 220 boldS14 = xl.XFStyle() boldS14.font = boldFont14 sheet1.write(0, 0, 'CLIENTE', boldS14) sheet1.write(0, 1, 'DIRECCION', boldS14) sheet1.write(0, 2, 'DIA', boldS14) sheet1.write(0, 3, 'FECHA INICIO', boldS14) sheet1.write(0, 4, 'FECHA FIN', boldS14) line = 1 for p in presence_obj.browse(self.env.context.get('active_ids')): line += 1 partner = p.event.sale_order.partner_shipping_id sheet1.write(line, 0, partner.name) address = u"\n{} {} {}".format(partner.street or '', partner.street2 or '', partner.city or '') sheet1.write(line, 1, address) if p.session_day == '0': day = 'Lunes' elif p.session_day == '1': day = 'Martes' elif p.session_day == '2': day = 'Miércoles' elif p.session_day == '3': day = 'Jueves' elif p.session_day == '4': day = 'Viernes' elif p.session_day == '5': day = 'Sábado' else: day = 'Domingo' sheet1.write(line, 2, day) session_date = fields.Datetime.to_string( _convert_to_local_date(p.session_date, self.env.user.tz)) sheet1.write(line, 3, session_date) session_end_date = fields.Datetime.to_string( _convert_to_local_date(p.estimated_date_end, self.env.user.tz)) sheet1.write(line, 4, session_end_date) return sheet1
def _find_contracts_for_employee(self): tz = self.env.user.tz permitted_contracts = self._search_permitted_contracts(self) self.contracts_permitted = [(6, 0, permitted_contracts.ids)] if len(permitted_contracts) == 1: self.contract = permitted_contracts[0].id from_date = date2str(_convert_to_local_date( self.date_start, tz=tz).date()) if self.contract.date_start > from_date: start_time = _convert_time_to_float(self.date_start, tz=tz) self.date_start = _convert_to_utc_date( self.contract.date_start, start_time, tz=tz) to_date = date2str(_convert_to_local_date( self.date_end, tz=tz).date()) if self.contract.date_end and self.contract.date_end < to_date: end_time = _convert_time_to_float(self.date_end, tz=tz) self.date_end = _convert_to_utc_date( self.contract.date_end, end_time, tz=tz)
def action_confirm_registrations(self): self.ensure_one() registration_obj = self.env['event.registration'] presence_obj = self.env['event.track.presence'] for reg in registration_obj.browse( self.env.context.get('active_ids')).filtered( lambda x: x.state == 'draft' and x.replaces_to): tz = self.env.user.tz from_date = _convert_to_local_date(reg.date_start, tz) to_date = _convert_to_local_date(reg.date_end, tz) cond = [('event', '=', reg.event_id.id), ('partner', '=', reg.replaces_to.id), ('session_date_without_hour', '>=', from_date), ('session_date_without_hour', '<=', to_date)] presences = presence_obj.search(cond) presences.write({'replaced_by': reg.partner_id.id}) return super(WizEventRegistrationConfirm, self).action_confirm_registrations()
def _prepare_data_confirm_assistant(self, reg): session_obj = self.env['event.track'] tz = self.env.user.tz tasks = self.env['project.task'] append_vals = super(WizEventConfirmAssistant, self)._prepare_data_confirm_assistant(reg) from_date = _convert_to_local_date(reg.date_start, tz=tz).date() to_date = _convert_to_local_date(reg.date_end, tz=tz).date() cond = [('event_id', '=', reg.event_id.id), ('session_date', '>=', from_date), ('session_date', '<=', to_date), ('date', '!=', False)] sessions = session_obj.search(cond) tasks = sessions.mapped('tasks') append_vals.update({ 'permitted_tasks': [(6, 0, tasks.ids)], 'tasks': [(6, 0, tasks.ids)] }) return append_vals
def _find_employee_calendar(self, holiday, validate_ausence): wiz_obj = self.env['wiz.calculate.employee.calendar'] partner_calendar_obj = self.env['res.partner.calendar'] tz = self.env.user.tz employee_with_calendar = True from_year = _convert_to_local_date(holiday.date_from, tz=tz).year to_year = _convert_to_local_date(holiday.date_to, tz=tz).year while from_year <= to_year: cond = [('partner', '=', holiday.employee_id.address_home_id.id), ('year', '=', from_year)] calendar = partner_calendar_obj.search(cond) if not calendar: employee_with_calendar = False from_year = to_year from_year += 1 if employee_with_calendar: return {} wiz = wiz_obj.create({ 'validate_ausence': validate_ausence, 'ausence': holiday.id }) context = self.env.context.copy() context['active_id'] = holiday.id context['active_ids'] = [holiday.id] context['active_model'] = 'hr.holidays' return { 'name': _('There is no calendar for the employee, we are going' ' to create'), 'type': 'ir.actions.act_window', 'res_model': 'wiz.calculate.employee.calendar', 'view_type': 'form', 'view_mode': 'form', 'res_id': wiz.id, 'target': 'new', 'context': context }
def _compute_estimated_daynightlight_hours(self): super(EventTrackPresence, self)._compute_estimated_daynightlight_hours() for presence in self.filtered('session_duration'): start_date = _convert_to_local_date(presence.session_date, self.env.user.tz) presence.start_hour = '{:%H:%M:%S}'.format(start_date) end_date = start_date + relativedelta( hours=presence.session_duration) presence.end_hour = '{:%H:%M:%S}'.format(end_date)
def _prepare_registration_data(self, event): vals = super(WizEventAppendAssistant, self)._prepare_registration_data(event) date_start = _convert_to_local_date(self.from_date).date() date_start = _convert_to_utc_date(date_start, time=self.start_time, tz=self.env.user.tz) date_end = _convert_to_local_date(self.to_date).date() date_end = _convert_to_utc_date(date_end, time=self.end_time, tz=self.env.user.tz) vals.update({ 'date_start': event.date_begin if datetime2string(date_start) < event.date_begin else date_start, 'date_end': event.date_end if datetime2string(date_end) > event.date_end else date_end, }) return vals
def _prepare_data_for_account_not_employee(self, event, registration): tz = self.env.user.tz if self.from_date and self.to_date: from_date = self.from_date to_date = self.to_date today = str2date(self.from_date) else: from_date = _convert_to_local_date(registration.date_start, tz=tz).date() to_date = _convert_to_local_date(registration.date_end, tz=tz).date() today = str2date(fields.Datetime.now()) recurring_next_date = "{}-{}-{}".format( today.year, today.month, calendar.monthrange(today.year, today.month)[1]) code = self.env['ir.sequence'].get( 'account.analytic.account') parent_id = event.project_id.analytic_account_id.id or False if len(event.my_task_ids) == 1: parent_id = event.my_task_ids[0].project_id.analytic_account_id.id vals = {'name': (_('Student: %s - Payer: %s') % (registration.partner_id.name, registration.partner_id.parent_id.name)), 'type': 'contract', 'date_start': from_date, 'date': to_date, 'parent_id': parent_id, 'code': code, 'partner_id': registration.partner_id.parent_id.id, 'student': registration.partner_id.id, 'recurring_invoices': True, 'recurring_next_date': recurring_next_date} if (registration.analytic_account and registration.analytic_account.recurring_next_date): old = str2date(registration.analytic_account.recurring_next_date) new = str2date(recurring_next_date) if old > new: vals['recurring_next_date'] = old if registration.event_id.sale_order: vals['sale'] = registration.event_id.sale_order.id return vals
def _onchange_contract(self): self.ensure_one() tz = self.env.user.tz if self.contract: if not self.date_start: self.date_start = self.event_id.date_begin if not self.date_end: self.date_end = self.event_id.date_end from_date = date2str(_convert_to_local_date( self.date_start, tz=tz).date()) if self.contract.date_start and\ self.contract.date_start > from_date: start_time = _convert_time_to_float(self.date_start, tz=tz) self.date_start = _convert_to_utc_date( self.contract.date_start, start_time, tz=tz) to_date = date2str(_convert_to_local_date( self.date_end, tz=tz).date()) if self.contract.date_end and self.contract.date_end < to_date: end_time = _convert_time_to_float(self.date_end, tz=tz) self.date_end = _convert_to_utc_date( self.contract.date_end, end_time, tz=tz)
def button_calculate_employee_calendar(self): self.ensure_one() partner_calendar_obj = self.env['res.partner.calendar'] tz = self.env.user.tz from_year = _convert_to_local_date(self.ausence.date_from, tz=tz).year to_year = _convert_to_local_date(self.ausence.date_to, tz=tz).year while from_year <= to_year: partner = self.ausence.employee_id.address_home_id cond = [('partner', '=', partner.id), ('year', '=', from_year)] calendar = partner_calendar_obj.search(cond) if not calendar: self._generate_calendar(partner, from_year) from_year += 1 if self.validate_ausence: self.ausence.signal_workflow('validate') self.ausence._update_presences_validate_holiday() self.ausence._update_partner_calendar_day( self.ausence, absence_type=self.ausence.holiday_status_id.id) else: self.ausence._update_presences_refuse_holiday() self.ausence._update_partner_calendar_day(self.ausence) self.ausence.signal_workflow('refuse')
def button_substitution_employee(self): registration_obj = self.env['event.registration'] tz = self.env.user.tz self.ensure_one() for line in self.lines: vals = { 'event_id': line.event.id, 'partner_id': line.employee.address_home_id.id, 'replaces_to': self.holiday.employee_id.address_home_id.id } event_date = _convert_to_local_date(line.event.date_begin, tz=tz).date() holiday_date = _convert_to_local_date(self.holiday.date_from, tz=tz).date() if holiday_date < event_date: vals['date_start'] = line.event.date_begin else: start_time = _convert_time_to_float(line.event.date_begin, tz=tz) vals['date_start'] = _convert_to_utc_date(holiday_date, start_time, tz=tz) event_date = _convert_to_local_date(line.event.date_end, tz=tz).date() holiday_date = _convert_to_local_date(self.holiday.date_to, tz=tz).date() if holiday_date > event_date: vals['date_end'] = line.event.date_end else: start_time = _convert_time_to_float(line.event.date_end, tz=tz) vals['date_end'] = _convert_to_utc_date(holiday_date, start_time, tz=tz) registration = registration_obj.create(vals) if len(registration.contracts_permitted) == 1: registration.contract = registration.contracts_permitted[0].id m = ( "<p> " + fields.Date.context_today(self) + ': ' + _('The employee: %s, replaces the employee: %s, from date %s,' ' to date %s') % (line.employee.address_home_id.name, self.holiday.employee_id.address_home_id.name, date2str(_convert_to_local_date(self.holiday.date_from, tz=tz)), date2str(_convert_to_local_date(self.holiday.date_to, tz=tz))) + "<br>") m += "<br> <br>" vals = { 'type': 'comment', 'model': 'event.event', 'record_name': line.event.name, 'res_id': line.event.id, 'body': m } self.env['mail.message'].create(vals) self.holiday.signal_workflow('validate') self.holiday._update_presences_validate_holiday() self.holiday._update_partner_calendar_day( self.holiday, absence_type=self.holiday.holiday_status_id.id)
def _generate_calendar(self, partner, year): contract_obj = self.env['hr.contract'] tz = self.env.user.tz partner._generate_calendar(year) date_start = _convert_to_local_date(self.ausence.date_from, tz=tz).date() cond = [('employee_id', '=', self.ausence.employee_id.id), '|', ('date_end', '=', False), ('date_end', '>', date_start)] contracts = contract_obj.search(cond) contracts = contract_obj.search(cond) for contract in contracts: if (contract.working_hours and contract.working_hours.attendance_ids): contract.partner._put_estimated_hours_in_calendar( year, contract) for calendar in contract.holiday_calendars: partner._generate_festives_in_calendar(year, calendar)
def _compute_session_date(self): for work in self.filtered('date'): from_date = _convert_to_local_date(work.date, self.env.user.tz) work.day = str(from_date.date().weekday())