def fix_customers(): customers = session.query(Customer).all() for customer in customers: as_dict = customer.__dict__ if customer.customer_type == 1: as_dict.update({ 'customer_first_name': customer.priv_customer[0].private_customer_first_name }) as_dict.update({ 'customer_last_name': customer.priv_customer[0].private_customer_last_name }) as_dict.update({ 'customer_phone': customer.priv_customer[0].private_customer_phone }) as_dict.update({ 'customer_email': customer.priv_customer[0].private_customer_email }) del as_dict['priv_customer'] else: as_dict.update({ 'company_name': customer.comp_customer[0].company_customer_company_name }) as_dict.update({ 'customer_first_name': customer.comp_customer[0].company_customer_first_name }) as_dict.update({ 'customer_last_name': customer.comp_customer[0].company_customer_last_name }) as_dict.update({ 'customer_phone': customer.comp_customer[0].company_customer_phone }) as_dict.update({ 'customer_email': customer.comp_customer[0].company_customer_email }) del as_dict['comp_customer'] customer_cars = [] for car in customer.cars: customer_cars.append({ 'customer_registration_nr': car.customer_registration_nr, 'customer_car_brand': car.customer_car_brand, 'customer_car_model': car.customer_car_model, 'customer_car_model_year': car.customer_car_model_year, 'customer_car_color': car.customer_car_color }) as_dict.update({'cars': customer_cars}) del as_dict['_sa_instance_state'] del as_dict['customer_type'] mongo_customer = MongoCustomer(as_dict) mongo_customer.save()
def steal_car(): customer_cars = Customer.all() stolen_car = random.choice(customer_cars) grand_theft_auto = Customer.find(_id=stolen_car._id).first_or_none() grand_theft_auto.delete_field("cars") return stolen_car
def cleaning_ids(): customers = MongoCustomer.all() for customer in customers: customer.delete_field("customer_id") employees = MongoEmployee.all() for employee in employees: employee.delete_field("employee_id") manufacturers = MongoManufacturer.all() for man in manufacturers: man.delete_field("manufacturer_id") orders = MongoOrder.all() for order in orders: order.delete_field("order_id") spare_parts = MongoSparePart.all() for spare in spare_parts: spare.delete_field("spare_part_id") stores = MongoStore.all() for store in stores: store.delete_field("store_id") suppliers = MongoSupplier.all() for supplier in suppliers: supplier.delete_field("supplier_id")
def fix_orders(): orders = session.query(Order).all() for order in orders: as_dict = order.__dict__ as_dict["employee_id"] = MongoEmployee.find( employee_id=order.employee_id).first_or_none()._id as_dict["customer_id"] = MongoCustomer.find( customer_id=order.customer_id).first_or_none()._id as_dict["store_id"] = MongoStore.find( store_id=order.store_id).first_or_none()._id order_line = [{ "spare_part_id": MongoSparePart.find( spare_part_id=ol.spare_part_id).first_or_none()._id, "quantity": ol.quantity } for ol in order.order_lines] as_dict.update({"order_detail": order_line}) del as_dict["order_lines"] del as_dict["_sa_instance_state"] mongo_order = MongoOrder(as_dict) for ol in mongo_order.order_detail: del ol["spare_part"] mongo_order.save()
def add_private_customer(customer_type, order=False): while True: print("Private Customer".center(30, " ")) print("".center(30, "=")) # ---MYSQL STUFF--- # priv_customer_dict = {f"private_customer_{i.replace(' ', '_').lower()}": input(f"{i}: ") for i in # ["First name", "Last name", "Phone", "Email"]} priv_customer_dict = { f"customer_{i.replace(' ', '_').lower()}": input(f"{i}: ") for i in ["First name", "Last name", "Phone", "Email"] } customer_car_dict = add_customer_car() verify_information(priv_customer_dict, customer_car_dict) priv_customer_dict.update({"cars": [customer_car_dict]}) verification = input( "Is the information entered correct?\n(1) YES\n(2) NO\n:> ") if verification == "1": private_customer = Customer(priv_customer_dict) # ---MYSQL STUFF--- # private_customer = PrivateCustomer(**priv_customer_dict) # private_customer.customer = Customer(customer_type=customer_type) # private_customer.customer.cars.append(CustomerCar(**customer_car_dict)) if order: cc.add_private_customer(private_customer) return private_customer else: cc.add_private_customer(private_customer) print("Customer saved!".center(30, "-")) break elif verification == "2": print("Save cancelled!".center(30, "-")) break else: print(f"{ERROR_MESSAGE_TWO}. Data wasn't saved!") continue
def add_company_customer(customer_type, order=False): while True: print("Company Customers".center(30, " ")) print("".center(30, "=")) comp_customer_dict = { f"company_customer_{i.replace(' ', '_').lower()}": input(f"{i}: ") for i in ["Company Name", "First name", "Last Name", "Email", "Phone"] } customer_car_dict = add_customer_car() verify_information(comp_customer_dict, customer_car_dict) verification = input( "Is the information entered correct?\n(1) YES\n(2) NO\n:> ") if verification == "1": company_customer = CompanyCustomer(**comp_customer_dict) company_customer.customer = Customer(customer_type=customer_type) company_customer.customer.cars.append( CustomerCar(**customer_car_dict)) if order: cc.add_company_customer(company_customer) return company_customer else: cc.add_company_customer(company_customer) print("Customer saved!".center(30, "-")) break elif verification == "2": print("Save cancelled!".center(30, "-")) break else: print(f"{ERROR_MESSAGE_TWO}. Data wasn't saved!") continue
def add_customer(customer: Customer): customer.save()
def customer(self): return Customer.find(_id=self.customer_id).first_or_none()