def create_employee_role(self, name=u'Role'): from stoqlib.domain.person import EmployeeRole role = self.store.find(EmployeeRole, name=name).one() if not role: role = EmployeeRole(name=name, store=self.store) if not self._role: self._role = role return role
def _set_sales_person_role_default(self, store): if self.has_object("DEFAULT_SALESPERSON_ROLE"): return from stoqlib.domain.person import EmployeeRole role = EmployeeRole(name=_(u'Salesperson'), store=store) self.set_object(store, "DEFAULT_SALESPERSON_ROLE", role, is_editable=False)
def _create_default_salesperson_role(self): from stoqlib.domain.person import EmployeeRole key = u"DEFAULT_SALESPERSON_ROLE" if self.get_parameter_by_field(key, EmployeeRole): return store = new_store() role = EmployeeRole(name=_(u'Salesperson'), store=store) store.commit(close=True) self._set_schema(key, role.id, is_editable=False)
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 _set_sales_person_role_default(self, store): if self.has_object("DEFAULT_SALESPERSON_ROLE"): return from stoqlib.domain.person import EmployeeRole role = EmployeeRole.get_or_create(store, name=_(u'Salesperson')) self.set_object(store, "DEFAULT_SALESPERSON_ROLE", role)
def create_model(self, store): return EmployeeRole(store=store, name=u'')
def test_has_role(self): role = EmployeeRole(store=self.store, name=u'role') self.failIf(role.has_other_role(u'Role')) role = EmployeeRole(store=self.store, name=u'Role') self.failUnless(role.has_other_role(u'role'))
def test_create(self): EmployeeRole(store=self.store, name=u'ajudante')