def create_company(self): company = Company(creator_user_id=current_user.id, name=self.name, about=self.about, corporation_id=self.corporation_id) add_commit(company) return company
def create_group_client_places(self): group_client_places = GroupClientPlaces(creator_user_id=current_user.id, name=self.name, about=self.about, company_id=self.company_id) add_commit(group_client_places) return group_client_places
def edit_model_object(self, **kwargs): for key, value in kwargs.items(): if value != '' or value is not None: setattr(self._obj, key, value) else: setattr(self._obj, key, None) add_commit(self._obj) return self._obj
def create_admin(self): admin = Admin(creator_user_id=current_user.id, about=self.about, email=self.email, phone=self.phone, role_id=self.role_id, corporation_id=self.corporation_id, active=False) add_commit(admin) return admin
def create_client_place(self): if self.group_client_places_id.isdigit(): client_place = ClientPlace( group_client_places_id=self.group_client_places_id, name=self.name, creator_user_id=current_user.id, company_id=self.company_id) else: client_place = ClientPlace(name=self.name, creator_user_id=current_user.id, company_id=self.company_id) add_commit(client_place) return client_place
def create_relationship_employee_to_user(self): employee = Employee.query.filter_by(slug=self.slug, active=False, archived=False, user_id=None, email=current_user.email).first() if employee and current_user.archived is False and current_user.active: current_user_employee_corporation = current_user.employees. \ filter_by(corporation_id=employee.corporation_id).first() if current_user_employee_corporation is None: employee.user_id = current_user.id employee.active = True add_commit(employee) return employee return None
def create_employee(self): corporation_id = self.corporation_id \ if self.corporation_id is not None \ else CompanyAccess(id=self.id).object_by_id().corporation_id employee = Employee(creator_user_id=current_user.id, active=False, first_name=self.first_name, last_name=self.last_name, about=self.about, email=self.email, phone=self.phone, role_id=self.role_id, corporation_id=corporation_id, company_id=self.company_id) add_commit(employee) return employee
def create_relationship_admin_to_user(self): admin = Admin.query.filter_by(slug=self.slug, active=False, archived=False, user_id=None, email=current_user.email).first() if admin and current_user.archived is False and current_user.active: current_user_admin_corporation = current_user.admins.filter_by( corporation_id=admin.corporation_id).first() if current_user_admin_corporation is None: admin.user_id = current_user.id admin.active = True add_commit(admin) return admin return None
def remove_relationship_obj_to_another_obj(self): relationship_info = self.is_relationship_obj_to_another_obj() is_relationship = relationship_info['is_relationship'] is_iter = relationship_info['is_iter'] _obj_attr_another_obj = relationship_info['_obj_attr_another_obj'] if is_relationship: if is_iter: getattr(self._obj, _obj_attr_another_obj). \ remove(self.another_obj) else: setattr(self._obj, _obj_attr_another_obj, None) add_commit(self._obj) return True, 'The relationship successfully removed' elif is_relationship: return False, 'There was no relationship before' else: return None, 'error'
def create_relationship_in_company_obj_to_another_obj(self): relationship_info = self.is_relationship_obj_to_another_obj() is_relationship = relationship_info['is_relationship'] is_iter = relationship_info['is_iter'] _obj_attr_another_obj = relationship_info['_obj_attr_another_obj'] if is_relationship is False: if is_iter: getattr(self._obj, _obj_attr_another_obj). \ append(self.another_obj) else: setattr(self._obj, _obj_attr_another_obj, self.another_obj) add_commit(self._obj) return True, 'The relationship successfully created' elif is_relationship: return False, 'The relationship already existed' else: return None, 'error'
def create_user(self): user = User(username=self.username, email=self.email) user.set_password(self.password) add_commit(user) return user
def add_telegram_chat_id(self): employee = Employee.query.filter_by(slug=self.slug).first() employee.telegram_chat_id = self.telegram_chat_id add_commit(employee) return True