def create_employee(self, name=u"SalesPerson"): from stoqlib.domain.person import Employee, Individual, Person person = Person(name=name, store=self.store) Individual(person=person, store=self.store) return Employee(person=person, role=self.create_employee_role(), store=self.store)
def create_model(self, store): person = BasePersonRoleEditor.create_model(self, store) if not person.individual: Individual(person=person, store=self.store) employee = person.employee if not employee: employee = Employee(person=person, store=store, role=None) return employee
def ensure_admin_user(administrator_password): log.info("Creating administrator user") default_store = get_default_store() user = get_admin_user(default_store) if user is None: store = new_store() person = Person(name=_(u'Administrator'), store=store) # Dependencies to create an user. role = EmployeeRole(name=_(u'System Administrator'), store=store) Individual(person=person, store=store) employee = Employee(person=person, role=role, store=store) EmployeeRoleHistory(store=store, role=role, employee=employee, is_active=True, salary=currency(800)) # This is usefull when testing a initial database. Admin user actually # must have all the facets. SalesPerson(person=person, store=store) profile = store.find(UserProfile, name=_(u'Administrator')).one() # Backwards compatibility. this profile used to be in english # FIXME: Maybe its safe to assume the first profile in the table is # the admin. if not profile: profile = store.find(UserProfile, name=u'Administrator').one() log.info("Attaching a LoginUser (%s)" % (USER_ADMIN_DEFAULT_NAME, )) LoginUser(person=person, username=USER_ADMIN_DEFAULT_NAME, password=administrator_password, profile=profile, store=store) store.commit(close=True) # Fetch the user again, this time from the right connection user = get_admin_user(default_store) assert user user.set_password(administrator_password) # We can't provide the utility until it's actually in the database log.info('providing utility ICurrentUser') provide_utility(ICurrentUser, user)
def process_one(self, data, fields, store): person = Person( store=store, name=data.name, phone_number=data.phone_number, mobile_number=data.mobile_number) Individual(person=person, store=store, cpf=data.cpf, rg_number=data.rg) role = EmployeeRole(store=store, name=data.role) employee = Employee(person=person, store=store, role=role, salary=int(data.salary), registry_number=data.employee_number) start = self.parse_date(data.start) EmployeeRoleHistory( store=store, role=role, employee=employee, is_active=True, began=start, salary=int(data.salary)) ctloc = CityLocation.get_or_create(store=store, city=data.city, state=data.state, country=data.country) streetnumber = data.streetnumber and int(data.streetnumber) or None Address(is_main_address=True, person=person, city_location=ctloc, store=store, street=data.street, streetnumber=streetnumber, district=data.district) if self.create_users: profile = store.find(UserProfile, name=data.profile).one() LoginUser(person=person, store=store, profile=profile, username=data.username, password=data.password) SalesPerson(person=person, store=store)
def _create_examples(self): person = Person(name=u'Jonas', store=self.store) Individual(person=person, store=self.store) role = EmployeeRole(store=self.store, name=u'desenvolvedor') Employee(person=person, store=self.store, role=role) self.salesperson = SalesPerson(person=person, store=self.store) Company(person=person, store=self.store) client = Client(person=person, store=self.store) self.branch = Branch(person=person, store=self.store) group = self.create_payment_group() self.sale = Sale(coupon_id=123, client=client, cfop_id=self.sparam.get_object_id('DEFAULT_SALES_CFOP'), group=group, branch=self.branch, salesperson=self.salesperson, store=self.store) self.storable = self.create_storable()
def on_confirm(self): if self.show_password_fields: self.model.set_password(self.password_slave.model.new_password) # FIXME: # 1) Move this hook into each instance of ProfileSettings # 2) Show some additional information in the user interface, which # are related to the facets the current profile will add profile = self.profile.get_selected() person = self.model.person employee = person.employee if employee is None: Employee(person=person, role=self.role.read(), store=self.store) else: employee.role = self.role.read() # If the user can access POS then he/she can perform sales too can_access_pos = profile.check_app_permission(u"pos") can_access_sales = profile.check_app_permission(u"sales") can_do_sales = can_access_pos or can_access_sales if can_do_sales and not person.salesperson: SalesPerson(person=person, store=self.store)
def _setup_manager_entry(self): employees = Employee.get_active_employees(self.store) self.manager.prefill(api.for_person_combo(employees))
def _fill_execution_responsible_combo(self): employees = Employee.get_active_employees(self.store) self.execution_responsible.prefill(api.for_person_combo(employees))