Пример #1
0
    def test_get_active_role_history(self):
        employee = self.create_employee()

        # creating 2 active role history, asserting it fails
        EmployeeRoleHistory(role=employee.role,
                            employee=employee,
                            store=self.store,
                            salary=currency(230))
        EmployeeRoleHistory(role=employee.role,
                            employee=employee,
                            store=self.store,
                            salary=currency(320))
        self.assertRaises(NotOneError, employee.get_active_role_history)
Пример #2
0
 def test_role_history(self):
     # this test depends bug 2457
     employee = self.create_employee()
     EmployeeRoleHistory(role=employee.role,
                         employee=employee,
                         store=self.store,
                         salary=currency(500),
                         is_active=False)
     old_count = employee.get_role_history().count()
     EmployeeRoleHistory(role=employee.role,
                         employee=employee,
                         store=self.store,
                         salary=currency(900))
     new_count = employee.get_role_history().count()
     self.assertEquals(old_count + 1, new_count)
Пример #3
0
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)
Пример #4
0
    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)
Пример #5
0
 def create_model(self, store):
     return EmployeeRoleHistory(store=store,
                                salary=self.employee.salary,
                                role=self.employee.role,
                                employee=self.employee)