import os from dotenv import load_dotenv from peewee import * load_dotenv() DATABASE = os.getenv("DATABASE") DB_HOST = os.getenv("DB_HOST") USERS = os.getenv("USERS") PASSW = os.getenv("PASSW") db = MySQLDatabase( database=DATABASE, user=USERS, password=PASSW, host=DB_HOST, port=3306 ) class Product(Model): product_id = AutoField(primary_key=True) name = CharField() sku = CharField(unique=True) price = DecimalField() class Meta: database = db class EpicenterOrder(Model): order_number = CharField(unique=True) order_id = CharField(unique=True) products = ManyToManyField(Product, backref="epicenter_orders") order_status = CharField() order_creation_date = DateTimeField() full_name = CharField() email = CharField() phone_number = CharField() delivery_address = CharField() delivery_post_number = CharField() delivery_ref = CharField() settlement = CharField() amount = DecimalField() ttn = CharField(null=True) class Meta: database = db class EpicenterOrderProduct(Model): epicenter_order = ForeignKeyField(EpicenterOrder) product = ForeignKeyField(Product) quantity = IntegerField() class Meta: database = db class CancelReason(Model): name = CharField() ukr_description = CharField() class Meta: database = db # db.create_tables([EpicenterOrder, Product, EpicenterOrderProduct, CancelReason]) # db.close() # run when you lost cancelreason table def insert_cancel_reasons(reasons_dict): try: # Connect to the database db.connect() # Create the table if it doesn't exist db.create_tables([CancelReason]) # Insert data into the table with db.atomic(): for key, value in reasons_dict.items(): CancelReason.create(name=key, ukr_description=value) # Close the database connection db.close() print("Data insertion successful.") except Exception as e: print(f"Error: {e}") # customer_cancel_reasons = { # "customer_account_payment_with_vat_is_preferred": "Хотів сплатити на Р/Р (з ПДВ)", # "customer_account_payment_without_vat_is_preferred": "Хотів сплатити на Р/Р (без ПДВ)", # "customer_bought_elsewhere_as_a_gift": "Купив в іншому місці/подарували", # "customer_canceled_at_delivery_office": "Відмова у відділенні", # "customer_changed_mind": "Потрібна була консультація", # "customer_credit_card_payment_is_preferred": "Хотів сплатити карткою", # "customer_delivery_speed_too_slow": "Не влаштували терміни доставки", # "customer_dissatisfied_with_the_shipping_cost": "Не влаштувала ціна доставки", # "customer_epic_warranty_is_preferred": "Вже купив в Епіцентрі", # "customer_found_cheaper": "Не влаштувала ціна товару", # "customer_get_loan_is_preferred_payment_type": "Хотів оформити розтермінування/кредит", # "customer_long_merchant_confirmation": "Тривале підтвердження", # "customer_no_payment": "Не вдалося оплатити на сайті", # "customer_not_timely_confirmation_of_the_availability_of_goods": "Немає в наявності", # "customer_order_duplicate": "Помилково оформив кілька замовлень", # "customer_prepayment_required": "Потрібна передоплата", # "customer_price_obsoleted": "Ціна неактуальна", # "customer_product_characteristics_are_not_suitable": "Товар не підходить за характеристиками", # "customer_requires_advance_payment_which_is_not_indicated_on_the_website": "Вимагають передоплату, про яку не інформує сайт", # "customer_several_packages_delivery_payment_is_not_suitable": "Хотів доставку одним замовленням", # "customer_shop_pickup_preferred_delivery_price_too_high": "Хотів забрати з пунктів самовивозу", # "customer_test": "Тест", # } # insert_cancel_reasons(customer_cancel_reasons)