def create(self, vals): res = super(OpFeesTerms, self).create(vals) if not res.line_ids: raise exceptions.AccessError(_("Fees Terms must be Required!")) total = 0.0 for line in res.line_ids: if line.value: total += line.value if total != 100.0: raise exceptions.AccessError( _("Fees terms must be divided as such sum up in 100%")) return res
def _contact_iap(local_endpoint, params): # mock single sms sending if local_endpoint == '/iap/message_send': self._sms += [{ 'number': number, 'body': params['message'], } for number in params['numbers']] return True # send_message v0 API returns always True # mock batch sending if local_endpoint == '/iap/sms/1/send': result = [] for to_send in params['messages']: res = { 'res_id': to_send['res_id'], 'state': 'success', 'credit': 1 } error = sim_error or (nbr_t_error and nbr_t_error.get( to_send['number'])) if error and error == 'credit': res.update(credit=0, state='insufficient_credit') elif error and error == 'wrong_number_format': res.update(state='wrong_number_format') elif error and error == 'jsonrpc_exception': raise exceptions.AccessError( 'The url that this service requested returned an error. Please contact the author of the app. The url it tried to contact was ' + local_endpoint) result.append(res) if res['state'] == 'success': self._sms.append({ 'number': to_send['number'], 'body': to_send['content'], }) return result
def _contact_iap(local_endpoint, params): sim_result = { 'name': 'Simulator INC', 'location': 'Simulator Street', 'city': 'SimCity', 'postal_code': '9876', 'country_code': 'BE', 'clearbit_id': 'idontknow', 'phone_numbers': ['+3269001122', '+32456001122'], 'twitter': 'testtwitter', 'facebook': 'testfacebook', } if default_data: sim_result.update(default_data) # mock single sms sending if local_endpoint == '/iap/clearbit/1/lead_enrichment_email': result = {} for lead_id, email in params['domains'].items(): if sim_error and sim_error == 'credit': raise iap.InsufficientCreditError( 'InsufficientCreditError') elif sim_error and sim_error == 'jsonrpc_exception': raise exceptions.AccessError( 'The url that this service requested returned an error. Please contact the author of the app. The url it tried to contact was ' + local_endpoint) result[str(lead_id)] = dict(sim_result) if email_data and email_data.get(email): result[str(lead_id)].update(email_data[email]) return result
def _employee_crash(*args, **kwargs): """ If employee is test employee, consider he has no access on document """ recordset = args[0] if recordset.env.uid == self.user_employee.id: raise exceptions.AccessError( 'Hop hop hop Ernest, please step back.') return DEFAULT
def _check_access(self, operation): """ Rule to access activities * create: check write rights on related document; * write: rule OR write rights on document; * unlink: rule OR write rights on document; """ self.check_access_rights( operation, raise_exception=True) # will raise an AccessError if operation in ('write', 'unlink'): try: self.check_access_rule(operation) except exceptions.AccessError: pass else: return doc_operation = 'read' if operation == 'read' else 'write' activity_to_documents = dict() for activity in self.sudo(): activity_to_documents.setdefault(activity.res_model, list()).append(activity.res_id) for model, res_ids in activity_to_documents.items(): self.env[model].check_access_rights(doc_operation, raise_exception=True) try: self.env[model].browse(res_ids).check_access_rule( doc_operation) except exceptions.AccessError: raise exceptions.AccessError( _('The requested operation cannot be completed due to security restrictions. Please contact your system administrator.\n\n(Document type: %s, Operation: %s)' ) % (self._description, operation) + ' - ({} {}, {} {})'.format(_('Records:'), res_ids[:6], _('User:'), self._uid))
def write(self, values): if values.get('publisher_comment'): if not self.env.user.has_group("website.group_website_publisher"): raise exceptions.AccessError( _("Only the publisher of the website can change the rating comment" )) if not values.get('publisher_datetime'): values['publisher_datetime'] = fields.Datetime.now() if not values.get('publisher_id'): values['publisher_id'] = self.env.user.partner_id.id return super(Rating, self).write(values)
def jsonrpc(url, method='call', params=None, timeout=15): """ Calls the provided JSON-RPC endpoint, unwraps the result and returns JSON-RPC errors as exceptions. """ payload = { 'jsonrpc': '2.0', 'method': method, 'params': params, 'id': uuid.uuid4().hex, } _logger.info('iap jsonrpc %s', url) try: req = requests.post(url, json=payload, timeout=timeout) req.raise_for_status() response = req.json() if 'error' in response: name = response['error']['data'].get('name').rpartition('.')[-1] message = response['error']['data'].get('message') if name == 'InsufficientCreditError': e_class = InsufficientCreditError elif name == 'AccessError': e_class = exceptions.AccessError elif name == 'UserError': e_class = exceptions.UserError else: raise requests.exceptions.ConnectionError() e = e_class(message) e.data = response['error']['data'] raise e return response.get('result') except (ValueError, requests.exceptions.ConnectionError, requests.exceptions.MissingSchema, requests.exceptions.Timeout, requests.exceptions.HTTPError) as e: raise exceptions.AccessError( _('The url that this service requested returned an error. Please contact the author of the app. The url it tried to contact was %s' ) % url)
def schedule_exam(self): attendance = self.env['op.exam.attendees'] for exam in self: if exam.total_student > exam.room_capacity: raise exceptions.AccessError( _("Room capacity must be greater than total number \ of student")) student_ids = exam.student_ids.ids for room in exam.room_ids: for i in range(room.capacity): if not student_ids: continue attendance.create({ 'exam_id': exam.exam_id.id, 'student_id': student_ids[0], 'status': 'present', 'course_id': exam.course_id.id, 'batch_id': exam.batch_id.id, 'room_id': room.id }) student_ids.remove(student_ids[0]) exam.exam_id.state = 'schedule' return True