def test_recurrent_meeting6(self): ev = self.CalendarEvent.create({ 'name': 'Rec1', 'start': '2018-06-28 11:00:00', 'stop': '2018-06-28 12:00:00', 'day': 0.0, 'duration': 1.0, 'count': ' 2', 'end_type': 'count', 'fr': True, 'recurrency': True, 'allday': False, 'rrule_type': 'weekly' }) #event 2018-07-06 and 2018-06-29 meetings = self.CalendarEvent.with_context({'virtual_id': True}).search([ '|', '&', ('start', '>=', '2018-06-30 00:00:00'), ('start', '<=', '2018-06-30 23:59:59'), ('allday', '=', True) ]) base_ids = [calendar_id2real_id(meeting.id, with_date=False) for meeting in meetings] self.assertNotIn(ev.id, base_ids, "Event does not match the domain") meetings = self.CalendarEvent.with_context({'virtual_id': True}).search([ '|', '&', ('start', '>=', '2018-06-29 00:00:00'), ('start', '<=', '2018-06-29 23:59:59'), ('allday', '=', True) ]) base_ids = [calendar_id2real_id(meeting.id, with_date=False) for meeting in meetings] self.assertIn(ev.id, base_ids, "Event does match the domain") meetings = self.CalendarEvent.with_context({'virtual_id': True}).search(['!', ['id', 'in', []]]) all_meetings = self.CalendarEvent.with_context({'virtual_id': True}).search([]) self.assertEqual(meetings, all_meetings, "All events match the domain") recurrent_ids = ['{}-20180706110000'.format(ev.id), '{}-20180629110000'.format(ev.id)] meetings = self.CalendarEvent.with_context({'virtual_id': True}).search(['!', ['id', 'in', recurrent_ids[:1]]]) excluded_meetings = (all_meetings - meetings).ids self.assertEqual(excluded_meetings, recurrent_ids, "Recurrent event is excluded by the domain")
def test_recurrent_meeting6(self): ev = self.CalendarEvent.create({ 'name': 'Rec1', 'start': '2018-06-28 11:00:00', 'stop': '2018-06-28 12:00:00', 'day': 0.0, 'duration': 1.0, 'count': ' 2', 'end_type': 'count', 'fr': True, 'recurrency': True, 'allday': False, 'rrule_type': 'weekly' }) #event 2018-07-06 and 2018-06-29 meetings = self.CalendarEvent.with_context({'virtual_id': True}).search([ '|', '&', ('start', '>=', '2018-06-30 00:00:00'), ('start', '<=', '2018-06-30 23:59:59'), ('allday', '=', True) ]) base_ids = [calendar_id2real_id(meeting.id, with_date=False) for meeting in meetings] self.assertNotIn(ev.id, base_ids, "Event does not match the domain") meetings = self.CalendarEvent.with_context({'virtual_id': True}).search([ '|', '&', ('start', '>=', '2018-06-29 00:00:00'), ('start', '<=', '2018-06-29 23:59:59'), ('allday', '=', True) ]) base_ids = [calendar_id2real_id(meeting.id, with_date=False) for meeting in meetings] self.assertIn(ev.id, base_ids, "Event does match the domain")
def test_recurrent_meeting5(self): # I create a recurrent event and I check if the virtual_id are correct self.CalendarEvent.create({ 'count': 5, 'start': '2012-04-13 11:00:00', 'stop': '2012-04-13 12:00:00', 'duration': 1.0, 'name': 'Test Meeting', 'recurrency': True, 'rrule_type': 'daily' }) # I search for the first recurrent meeting meeting = self.CalendarEvent.with_context({ 'virtual_id': True }).search([('start', '=', '2012-04-13 11:00:00'), ('stop', '=', '2012-04-13 12:00:00')]) virutal_dates = calendar_id2real_id(meeting.id, with_date=True) # virtual_dates are used by the calendar view and I check if the start date for the first virtual event is correct. self.assertEqual( virutal_dates[1], '2012-04-13 11:00:00', "The virtual event doesn't have the correct start date !") # virtual_dates are used by the calendar view and I check if the stop date for the first virtual event is correct. self.assertEqual( virutal_dates[2], '2012-04-13 12:00:00', "The virtual event doesn't have the correct stop date !")
def test_calendar_survey(self): real_id = calendar_id2real_id(self.event.id) self.assertFalse(self.event.user_input_ids) wizard = self.wizard_obj.with_context({ 'active_id': self.event.id, 'active_model': 'calendar.event' }).create({}) self.assertEqual(self.event, wizard.event_id) self.assertIn(self.survey, wizard.survey_ids) self.assertIn(self.partner, wizard.partner_ids) wizard.create_survey_response() self.assertTrue(self.event.user_input_ids) self.assertEqual( self.event.user_input_count, len(self.event.user_input_ids)) action_dict = self.event.button_open_user_input() domain = expression.AND([ [('event_id', '=', real_id)], safe_eval(self.action.domain or '[]')]) self.assertEquals(action_dict.get('domain'), domain) wizard = self.wizard_obj.with_context({ 'active_id': self.event.id, 'active_model': 'calendar.event' }).create({ 'survey_ids': [], 'partner_ids': [], }) with self.assertRaises(UserError): wizard.create_survey_response()
def get(self, key, key2, models, meta=False, res_id_req=False, without_user=True, key2_req=True): new_model = [] for data in models: if type(data) in (list, tuple): new_model.append((data[0], calendar_id2real_id(data[1]))) else: new_model.append(data) return super(IrValues, self).get(key, key2, new_model, meta, res_id_req, without_user, key2_req)
def set(self, key, key2, name, models, value, replace=True, isobject=False, meta=False, preserve_user=False, company=False): new_model = [] for data in models: if type(data) in (list, tuple): new_model.append((data[0], calendar_id2real_id(data[1]))) else: new_model.append(data) return super(IrValues, self).set(key, key2, name, new_model, value, replace, isobject, meta, preserve_user, company)
def set_action(self, name, action_slot, model, action, res_id=False): if res_id: res_id = calendar_id2real_id(res_id) return super(IrValues, self).set_action(name, action_slot, model, action, res_id=res_id)
def default_get(self, fields): res = super(CalendarUserInput, self).default_get(fields) context = self.env.context assert context.get('active_model') == 'calendar.event',\ 'active_model should be calendar.event' assert context.get('active_id'), 'Missing active_id in context !' event_id = calendar_id2real_id(context.get('active_id')) event = self.env['calendar.event'].browse(event_id) res.update({ 'event_id': event.id, 'survey_ids': event.mapped('categ_ids.survey_ids').ids, 'partner_ids': event.mapped('partner_ids').ids, }) return res
def button_open_user_input(self): self.ensure_one() real_id = calendar_id2real_id(self.id) self = self.with_context(default_calendar_id=real_id, default_deadline=self.start) action = self.env.ref('survey.action_survey_user_input') action_dict = action.read()[0] if action else {} action_dict['context'] = safe_eval(action_dict.get('context', '{}')) action_dict['context'].update({ 'default_event_id': real_id, 'default_deadline': self.start, }) domain = expression.AND([[('event_id', '=', real_id)], safe_eval(action.domain or '[]')]) action_dict.update({'domain': domain}) return action_dict
def test_recurrent_meeting5(self): # I create a recurrent event and I check if the virtual_id are correct self.CalendarEvent.create({ 'count': 5, 'start': '2012-04-13 11:00:00', 'stop': '2012-04-13 12:00:00', 'duration': 1.0, 'name': 'Test Meeting', 'recurrency': True, 'rrule_type': 'daily' }) # I search for the first recurrent meeting meeting = self.CalendarEvent.with_context({'virtual_id': True}).search([ ('start', '=', '2012-04-13 11:00:00'), ('stop', '=', '2012-04-13 12:00:00') ]) virutal_dates = calendar_id2real_id(meeting.id, with_date=True) # virtual_dates are used by the calendar view and I check if the start date for the first virtual event is correct. self.assertEqual(virutal_dates[1], '2012-04-13 11:00:00', "The virtual event doesn't have the correct start date !") # virtual_dates are used by the calendar view and I check if the stop date for the first virtual event is correct. self.assertEqual(virutal_dates[2], '2012-04-13 12:00:00', "The virtual event doesn't have the correct stop date !")
def create_survey_response(self): if not self.survey_ids or not self.partner_ids: raise UserError( _('You must select at least a survey and a attendee.')) response_obj = self.env['survey.user_input'] real_id = calendar_id2real_id(self.event_id.id) for survey in self.survey_ids: for partner in self.partner_ids: response = response_obj.search([ ('event_id', '=', real_id), ('survey_id', '=', survey.id), ('partner_id', '=', partner.id), ]) # create a response and link it to this applicant if not response: response_obj.create({ 'event_id': real_id, 'survey_id': survey.id, 'partner_id': partner.id, 'type': 'manually', }) return True
def get_actions(self, action_slot, model, res_id=False): if res_id: res_id = calendar_id2real_id(res_id) return super(IrValues, self).get_actions(action_slot, model, res_id=res_id)