Beispiel #1
0
 def upsert_customer(self, customer_id: int, customer: Customer) -> None:
     with session_scope(self.get_session) as session:
         if customer_id:
             customer.id = customer_id
             customer.update(session)
         else:
             customer.add(session)
Beispiel #2
0
 def on_ok(self):
     customer = Customer(name=self.wgCustomerName.value,
                         birth=self.wgCustomerBirthday.value)
     if self.customer_id:
         customer.id = self.customer_id
         self.parentApp.database.upsert_customer(self.customer_id, customer)
     else:
         self.parentApp.database.upsert_customer(self.customer_id, customer)
     self.parentApp.switchFormPrevious()
Beispiel #3
0
 def generate_random_customers(self, customer_count: int) -> None:
     fake = Faker()
     with session_scope(self.get_session) as session:
         for i in range(customer_count):
             Customer(name=fake.first_name_male(),
                      birth=fake.date_of_birth(tzinfo=None,
                                               minimum_age=0,
                                               maximum_age=1)).add(session)
Beispiel #4
0
 def get_customer(self, customer_id: int) -> Customer:
     with self.get_cursor() as cur:
         cur.execute(
             'SELECT * FROM customer WHERE customer_id = {0}'.format(
                 customer_id))
         t = cur.fetchone()
     return Customer(id=t['customer_id'],
                     name=t['customer_name'],
                     birth=t['date_of_birth'])
Beispiel #5
0
 def get_customers(self) -> list:
     with self.get_cursor() as cur:
         cur.execute(
             'SELECT customer_id, customer_name, date_of_birth  FROM customer'
         )
         customers = cur.fetchall()
     return [
         Customer(id=t['customer_id'],
                  name=t['customer_name'],
                  birth=t['date_of_birth']) for t in customers
     ]
Beispiel #6
0
 def advanced_sales_search(self, min_date_of_birth, max_date_of_birth,
                           status: bool) -> list:
     script = """
         SELECT s.date, s.done, s.team_id, s.site_id, c.date_of_birth, c.customer_name
         FROM sales s 
         JOIN customer c
         ON s.customer_id = c.customer_id
         WHERE (c.date_of_birth BETWEEN %s AND %s) 
             AND (s.done = %s);"""
     with self.get_cursor() as cur:
         cur.execute(script, [min_date_of_birth, max_date_of_birth, status])
         rows = cur.fetchall()
     return [(Customer(name=r['customer_name'], birth=r['date_of_birth']),
              Sales(date=r['date'],
                    done=r['done'],
                    team_id=r['team_id'],
                    site_id=r['site_id'])) for r in rows]
def ingest(e, D):
    """
    Given event e, update data D
    :param e: an event
    :param D: new data
    :return: no need to return, will update values in place
    """
    if e['type'] == 'CUSTOMER':
        # if key is not exist, add new, else if not exist and verb equals to update, update object
        if e['key'] not in D['customer'].keys():
            D['customer'][e['key']] = Customer(e['type'], e['verb'], e['key'],
                                               e['event_time'], e['last_name'],
                                               e['adr_city'], e['adr_state'])
        elif e['key'] in D['customer'].keys() and e['verb'] == 'UPDATE':
            updateCustomer(e, D)
    elif e['type'] == 'IMAGE':
        # if key is not exist, add new, else update object
        if e['key'] not in D['image'].keys():
            D['image'][e['key']] = Image(e['type'], e['verb'], e['key'],
                                         e['event_time'], e['customer_id'],
                                         e['camera_make'], e['camera_model'])
        elif e['key'] in D['image'].keys():
            updateImage(e, D)
    elif e['type'] == 'ORDER':
        # if key is not exist, add new, else if not exist and verb equals to update, update object
        if e['key'] not in D['order'].keys():
            D['order'][e['key']] = Order(e['type'], e['verb'], e['key'],
                                         e['event_time'], e['customer_id'],
                                         e['total_amount'])
        elif e['key'] in D['order'].keys() and e['verb'] == 'UPDATE':
            updateOrder(e, D)
    elif e['type'] == 'SITE_VISIT':
        # if key is not exist, add new, else update object
        if e['key'] not in D['siteVisit'].keys():
            D['siteVisit'][e['key']] = SiteVisit(e['type'], e['verb'],
                                                 e['key'], e['event_time'],
                                                 e['customer_id'], e['tags'])
        elif e['key'] in D['siteVisit'].keys():
            updateSiteVisit(e, D)
Beispiel #8
0
 def delete_customer(self, customer_id: int) -> None:
     with session_scope(self.get_session) as session:
         Customer.delete(session, customer_id)
Beispiel #9
0
 def get_customers(self) -> list:
     return Customer.getAll(self.get_session())
Beispiel #10
0
 def get_customer(self, customer_id: int) -> Customer:
     return Customer.get(self.get_session(), customer_id)