def birthday_search(self, state): if isinstance(state, DateQueryState): if state.date: return Individual.get_birthday_query(state.date) elif isinstance(state, DateIntervalQueryState): if state.start and state.end: return Individual.get_birthday_query(state.start, state.end) else: raise AssertionError
def test_individual(self): person = self.create_person() individual = Individual(person=person, store=self.store) statuses = individual.get_marital_statuses() self.assertEqual(type(statuses), list) self.failUnless(len(statuses) > 0) self.assertEqual(type(statuses[0]), tuple) self.assertEqual(type(statuses[0][0]), unicode) self.assertEqual(type(statuses[0][1]), int)
def birthday_search(self, state): """ Returns a birthday query suitable for search filters. This should be assigned on search_column when you want to filter for birth day. e.g.: SearchColumn('birth_date', search_column=self.birthday_search) """ if isinstance(state, DateQueryState): if state.date: return Individual.get_birthday_query(state.date) elif isinstance(state, DateIntervalQueryState): if state.start and state.end: return Individual.get_birthday_query(state.start, state.end) else: raise AssertionError
def test_get_birthday_interval_query(self): start = localdatetime(2000, 3, 1) end = localdatetime(2000, 3, 25) query = Individual.get_birthday_query(start, end) start_year = DateTrunc(u'year', Date(start)) age_in_year = Age(Individual.birth_date, DateTrunc(u'year', Individual.birth_date)) test_query = ( start_year + age_in_year + Case(condition=age_in_year < Age(Date(start), start_year), result=Interval(u'1 year'), else_=Interval(u'0 year'))) test_query = And(test_query >= Date(start), test_query <= Date(end)) self.assertEquals(query, test_query) individuals = list(self.store.find(Individual, test_query)) self.assertEquals(len(individuals), 0) client1 = self.create_client(u'Junio C. Hamano') client1.person.individual.birth_date = localdate(1972, 10, 15) client2 = self.create_client(u'Richard Stallman') client2.person.individual.birth_date = localdate(1989, 3, 7) client3 = self.create_client(u'Linus Torvalds') client3.person.individual.birth_date = localdate(2000, 3, 4) client4 = self.create_client(u'Guido van Rossum') client4.person.individual.birth_date = localdate(2005, 3, 20) individuals = list(self.store.find(Individual, test_query)) self.assertEquals(len(individuals), 3) self.assertTrue(client2.person.individual in individuals) self.assertTrue(client3.person.individual in individuals) self.assertTrue(client4.person.individual in individuals)
def test_default_receiving_cfop(self): branch = self.create_branch() param = self.sparam.get_object(self.store, 'DEFAULT_RECEIVING_CFOP') person = Person(name=u'Craudinho', store=self.store) Individual(person=person, store=self.store) profile = UserProfile(name=u'profile', store=self.store) responsible = LoginUser(person=person, store=self.store, password=u'asdfgh', profile=profile, username=u'craudio') receiving_order = ReceivingOrder(responsible=responsible, branch=branch, store=self.store, invoice_number=876, supplier=None) param2 = self.sparam.get_object(self.store, 'DEFAULT_SALES_CFOP') receiving_order2 = ReceivingOrder(responsible=responsible, cfop=param2, branch=branch, store=self.store, invoice_number=1231, supplier=None) self.assertEqual(param, receiving_order.cfop) self.failIfEqual(param, receiving_order2.cfop)
def test_get_birthday_date_query(self): start = localdate(2000, 3, 4) query = Individual.get_birthday_query(start) start_year = DateTrunc(u'year', Date(start)) age_in_year = Age(Individual.birth_date, DateTrunc(u'year', Individual.birth_date)) test_query = ( start_year + age_in_year + Case(condition=age_in_year < Age(Date(start), start_year), result=Interval(u'1 year'), else_=Interval(u'0 year')) ) test_query = (test_query == Date(start)) self.assertEquals(query, test_query) individuals = list(self.store.find(Individual, test_query)) self.assertEquals(len(individuals), 0) client1 = self.create_client(u'Junio C. Hamano') client1.person.individual.birth_date = localdate(1972, 10, 15) client2 = self.create_client(u'Richard Stallman') client2.person.individual.birth_date = localdate(1989, 3, 4) client3 = self.create_client(u'Linus Torvalds') client3.person.individual.birth_date = localdate(2000, 3, 4) client4 = self.create_client(u'Guido van Rossum') client4.person.individual.birth_date = localdate(2005, 3, 4) individuals = list(self.store.find(Individual, test_query)) self.assertEquals(len(individuals), 3) self.assertTrue(client2.person.individual in individuals) self.assertTrue(client3.person.individual in individuals) self.assertTrue(client4.person.individual in individuals)
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 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) 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 ) Client(person=person, store=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 create_client(cls, store, name, cpf, address=None): # TODO: Add phone number person = Person(name=name, store=store) Individual(cpf=cpf, person=person, store=store) if address: cls.create_address(person, address) client = Client(person=person, store=store) return client
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_model(self, store): # XXX: Waiting fix for bug 2163. We should not need anymore to # provide empty values for mandatory attributes if not self.person: self.person = Person(name=u"", store=store) if not self.role_type in [Person.ROLE_INDIVIDUAL, Person.ROLE_COMPANY]: raise ValueError("Invalid value for role_type attribute, %r" % (self.role_type, )) if (self.role_type == Person.ROLE_INDIVIDUAL and not self.person.individual): Individual(person=self.person, store=store, cpf=self.document) elif (self.role_type == Person.ROLE_COMPANY and not self.person.company): Company(person=self.person, store=store, cnpj=self.document) else: pass return self.person
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 create_client(self, name=u'Client'): from stoqlib.domain.person import Client, Individual, Person person = Person(name=name, store=self.store) Individual(person=person, store=self.store) return Client(person=person, store=self.store)
def create_individual(self): from stoqlib.domain.person import Individual, Person person = Person(name=u'individual', store=self.store) return Individual(person=person, birth_date=localdatetime(1970, 1, 1), store=self.store)