Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full order info #119

Closed
wants to merge 11 commits into from
35 changes: 20 additions & 15 deletions database.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


# Define all the database tables using the sqlalchemy declarative base
class User(DeferredReflection, TableDeclarativeBase):
class User(TableDeclarativeBase):
"""A Telegram user who used the bot at least once."""

# Telegram data
Expand Down Expand Up @@ -87,7 +87,7 @@ def __repr__(self):
return f"<User {self.mention()} having {self.credit} credit>"


class Product(DeferredReflection, TableDeclarativeBase):
class Product(TableDeclarativeBase):
"""A purchasable product."""

# Product id
Expand Down Expand Up @@ -151,7 +151,7 @@ def set_image(self, file: telegram.File):
self.image = r.content


class Transaction(DeferredReflection, TableDeclarativeBase):
class Transaction(TableDeclarativeBase):
"""A greed wallet transaction.
Wallet credit ISN'T calculated from these, but they can be used to recalculate it."""
# TODO: split this into multiple tables
Expand Down Expand Up @@ -193,6 +193,12 @@ def text(self, w: "worker.Worker"):
string += f" | {w.loc.get('emoji_refunded')}"
if self.provider:
string += f" | {self.provider}"
if self.payment_name:
string += f" | {self.payment_name}"
if self.payment_phone:
string += f" | {self.payment_phone}"
if self.payment_email:
string += f" | {self.payment_email}"
if self.notes:
string += f" | {self.notes}"
return string
Expand All @@ -201,7 +207,7 @@ def __repr__(self):
return f"<Transaction {self.transaction_id} for User {self.user_id}>"


class Admin(DeferredReflection, TableDeclarativeBase):
class Admin(TableDeclarativeBase):
"""A greed administrator with his permissions."""

# The telegram id
Expand All @@ -223,7 +229,7 @@ def __repr__(self):
return f"<Admin {self.user_id}>"


class Order(DeferredReflection, TableDeclarativeBase):
class Order(TableDeclarativeBase):
"""An order which has been placed by an user.
It may include multiple products, available in the OrderItem table."""

Expand All @@ -241,7 +247,7 @@ class Order(DeferredReflection, TableDeclarativeBase):
# Refund reason: if null, product hasn't been refunded
refund_reason = Column(Text)
# List of items in the order
items: typing.List["OrderItem"] = relationship("OrderItem")
items: typing.List["OrderItem"] = relationship("OrderItem", back_populates="order")
# Extra details specified by the purchasing user
notes = Column(Text)
# Linked transaction
Expand All @@ -253,8 +259,7 @@ class Order(DeferredReflection, TableDeclarativeBase):
def __repr__(self):
return f"<Order {self.order_id} placed by User {self.user_id}>"

def text(self, w: "worker.Worker", session, user=False):
joined_self = session.query(Order).filter_by(order_id=self.order_id).join(Transaction).one()
def text(self, w: "worker.Worker", user=False):
items = ""
for item in self.items:
items += item.text(w) + "\n"
Expand All @@ -273,21 +278,21 @@ def text(self, w: "worker.Worker", session, user=False):
status_text=status_text,
items=items,
notes=self.notes,
value=str(w.Price(-joined_self.transaction.value))) + \
(w.loc.get("refund_reason", reason=self.refund_reason) if self.refund_date is not None else "")
value=str(w.Price(-self.transaction.value))) + \
w.loc.get("refund_reason", reason=self.refund_reason) if self.refund_date is not None else ""
else:
return status_emoji + " " + \
w.loc.get("order_number", id=self.order_id) + "\n" + \
w.loc.get("order_number", id=self.order_id) + "\n\n" + \
w.loc.get("order_format_string",
user=self.user.mention(),
date=self.creation_date.isoformat(),
items=items,
notes=self.notes if self.notes is not None else "",
value=str(w.Price(-joined_self.transaction.value))) + \
(w.loc.get("refund_reason", reason=self.refund_reason) if self.refund_date is not None else "")
value=str(w.Price(-self.transaction.value))) + \
w.loc.get("refund_reason", reason=self.refund_reason) if self.refund_date is not None else ""


class OrderItem(DeferredReflection, TableDeclarativeBase):
class OrderItem(TableDeclarativeBase):
"""A product that has been purchased as part of an order."""

# The unique item id
Expand All @@ -297,7 +302,7 @@ class OrderItem(DeferredReflection, TableDeclarativeBase):
product = relationship("Product")
# The order in which this item is being purchased
order_id = Column(Integer, ForeignKey("orders.order_id"), nullable=False)
order = relationship("Order")
order = relationship("Order", back_populates="items")

# Extra table parameters
__tablename__ = "orderitems"
Expand Down
13 changes: 6 additions & 7 deletions strings/en.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,12 @@
"Created on {date}\n" \
"\n" \
"{items}\n" \
"TOTAL: <b>{value}</b>\n" \
"\n" \
"Customer notes: {notes}\n"
"TOTAL: <b>{value}</b>\n"

# Order info string, shown to the user
user_order_format_string = "{status_emoji} <b>Order {status_text}</b>\n" \
"{items}\n" \
"TOTAL: <b>{value}</b>\n" \
"\n" \
"Notes: {notes}\n"
"TOTAL: <b>{value}</b>\n"

# Transaction page is loading
loading_transactions = "<i>Loading transactions...\n" \
Expand Down Expand Up @@ -333,14 +329,17 @@

# Notification: order has been placed
notification_order_placed = "A new order was placed:\n" \
"\n" \
"{order}"

# Notification: order has been completed
notification_order_completed = "Your order has been completed!\n" \
"\n" \
"{order}"

# Notification: order has been refunded
notification_order_refunded = "Your order has been refunded!\n" \
"\n" \
"{order}"

# Notification: a manual transaction was applied
Expand All @@ -359,7 +358,7 @@

# Help: guide
help_msg = "greed's guide is available at this address:\n" \
"https://docs.google.com/document/d/1f4MKVr0B7RSQfWTSa_6ZO0LM4nPpky_GX_qdls3EHtQ/"
"https://github.com/Steffo99/greed/wiki"

# Help: contact shopkeeper
contact_shopkeeper = "Currently, the staff available to provide user assistance is composed of:\n" \
Expand Down
13 changes: 6 additions & 7 deletions strings/es_mx.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,12 @@
"Creado en {date}\n" \
"\n" \
"{items}\n" \
"TOTAL: <b>{value}</b>\n" \
"\n" \
"Notas del Cliente: {notes}\n"
"TOTAL: <b>{value}</b>\n"

# Order info string, shown to the user
user_order_format_string = "{status_emoji} <b>Orden {status_text}</b>\n" \
"{items}\n" \
"TOTAL: <b>{value}</b>\n" \
"\n" \
"Notas: {notes}\n"
"TOTAL: <b>{value}</b>\n"

# Transaction page is loading
loading_transactions = "<i>Cargando transacciones...\n" \
Expand Down Expand Up @@ -332,14 +328,17 @@

# Notification: order has been placed
notification_order_placed = "Se realizó una nueva orden:\n" \
"\n" \
"{order}"

# Notification: order has been completed
notification_order_completed = "¡Tu orden ha sido completada!\n" \
"\n" \
"{order}"

# Notification: order has been refunded
notification_order_refunded = "¡Tu orden ha sido reembolsada!\n" \
"\n" \
"{order}"

# Notification: a manual transaction was applied
Expand All @@ -358,7 +357,7 @@

# Help: guide
help_msg = "La guía de greed está disponible en este enlace:\n" \
"https://docs.google.com/document/d/1f4MKVr0B7RSQfWTSa_6ZO0LM4nPpky_GX_qdls3EHtQ/"
"https://github.com/Steffo99/greed/wiki"

# Help: contact shopkeeper
contact_shopkeeper = "Actualmente, el personal disponible para brindar asistencia al cliente está compuesto por:\n" \
Expand Down
13 changes: 6 additions & 7 deletions strings/he.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,12 @@
"{date} נוצר בתאריך\n" \
"\n" \
"{items}\n" \
"<b>{value}</b>: סך הכל\n" \
"\n" \
"{notes}: הערות הקונה\n"
"<b>{value}</b>: סך הכל\n"

# Order info string, shown to the user
user_order_format_string = "{status_emoji} <b>הזמנה {status_text}</b>\n" \
"{items}\n" \
"סך הכל: <b>{value}</b>\n" \
"\n" \
"הערות: {notes}\n"
"סך הכל: <b>{value}</b>\n"

# Transaction page is loading
loading_transactions = "<i>טוען הזמנות...\n" \
Expand Down Expand Up @@ -327,14 +323,17 @@

# Notification: order has been placed
notification_order_placed = "נוצרה הזמנה חדשה:\n" \
"\n" \
"{order}"

# Notification: order has been completed
notification_order_completed = "ההזמנה הוצרה בהצלחה\n" \
"\n" \
"{order}"

# Notification: order has been refunded
notification_order_refunded = "הכסף על ההזמנה הבא הוחזר בהצלחה\n" \
"\n" \
"{order}"

# Notification: a manual transaction was applied
Expand All @@ -353,7 +352,7 @@

# Help: guide
help_msg = "greed's guide is available at this address:\n" \
"https://docs.google.com/document/d/1f4MKVr0B7RSQfWTSa_6ZO0LM4nPpky_GX_qdls3EHtQ/"
"https://github.com/Steffo99/greed/wiki"

# Help: contact shopkeeper
contact_shopkeeper = "המשתמשים שיכולים לספק תמיכה הם\n" \
Expand Down
13 changes: 6 additions & 7 deletions strings/it.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,12 @@
"Creato {date}\n" \
"\n" \
"{items}\n" \
"TOTALE: <b>{value}</b>\n" \
"\n" \
"Note del cliente: {notes}\n"
"TOTALE: <b>{value}</b>\n"

# Order info string, shown to the user
user_order_format_string = "{status_emoji} <b>Ordine {status_text}</b>\n" \
"{items}\n" \
"TOTALE: <b>{value}</b>\n" \
"\n" \
"Note: {notes}\n"
"TOTALE: <b>{value}</b>\n"

# Transaction page is loading
loading_transactions = "<i>Caricamento delle transazioni in corso...\n" \
Expand Down Expand Up @@ -335,14 +331,17 @@

# Notification: order has been placed
notification_order_placed = "E' stato piazzato un nuovo ordine:\n" \
"\n" \
"{order}"

# Notification: order has been completed
notification_order_completed = "Un tuo ordine è stato completato!\n" \
"\n" \
"{order}"

# Notification: order has been refunded
notification_order_refunded = "Un tuo ordine è stato rimborsato!\n" \
"\n" \
"{order}"

# Notification: a manual transaction was applied
Expand All @@ -361,7 +360,7 @@

# Help: guide
help_msg = "La guida del bot è disponibile a questo indirizzo:\n" \
"https://docs.google.com/document/d/1f4MKVr0B7RSQfWTSa_6ZO0LM4nPpky_GX_qdls3EHtQ/"
"https://github.com/Steffo99/greed/wiki"

# Help: contact shopkeeper
contact_shopkeeper = "Attualmente, il personale disponibile ad offrire assistenza agli utenti è composto da:\n" \
Expand Down
13 changes: 6 additions & 7 deletions strings/ru.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,12 @@
"Создано {date}\n" \
"\n" \
"{items}\n" \
"ИТОГО: <b>{value}</b>\n" \
"\n" \
"Сообщение: {notes}\n"
"ИТОГО: <b>{value}</b>\n"

# Order info string, shown to the user
user_order_format_string = "{status_emoji} <b>Заказ {status_text}</b>\n" \
"{items}\n" \
"Итого: <b>{value}</b>\n" \
"\n" \
"Сообщение: {notes}\n"
"Итого: <b>{value}</b>\n"

# Transaction page is loading
loading_transactions = "<i>Загружаю транзакции...\n" \
Expand Down Expand Up @@ -330,14 +326,17 @@

# Notification: order has been placed
notification_order_placed = "Получен новый заказ:\n" \
"\n" \
"{order}"

# Notification: order has been completed
notification_order_completed = "Ваш заказ успешно выполнен!\n" \
"\n" \
"{order}"

# Notification: order has been refunded
notification_order_refunded = "Ваш заказ отменен. Средства возвращены в Ваш кошелек!\n" \
"\n" \
"{order}"

# Notification: a manual transaction was applied
Expand All @@ -356,7 +355,7 @@

# Help: guide
help_msg = "Инструкция к greed доступна по этому адресу:\n" \
"https://docs.google.com/document/d/1f4MKVr0B7RSQfWTSa_6ZO0LM4nPpky_GX_qdls3EHtQ/"
"https://github.com/Steffo99/greed/wiki"

# Help: contact shopkeeper
contact_shopkeeper = "Следующие сотрудники доступны сейчас и могут помочь:\n" \
Expand Down
13 changes: 6 additions & 7 deletions strings/uk.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,12 @@
"Створено {date}\n" \
"\n" \
"{items}\n" \
"ЗАГАЛОМ: <b>{value}</b>\n" \
"\n" \
"Нотатка: {notes}\n"
"ЗАГАЛОМ: <b>{value}</b>\n"

# Order info string, shown to the user
user_order_format_string = "{status_emoji} <b>Замовлення {status_text}</b>\n" \
"{items}\n" \
"Загалом: <b>{value}</b>\n" \
"\n" \
"Нотатка: {notes}\n"
"Загалом: <b>{value}</b>\n"

# Transaction page is loading
loading_transactions = "<i>Завантажую транзакції...\n" \
Expand Down Expand Up @@ -325,14 +321,17 @@

# Notification: order has been placed
notification_order_placed = "Отримано нове замовлення:\n" \
"\n" \
"{order}"

# Notification: order has been completed
notification_order_completed = "Ваше замовнення успішно завершено!\n" \
"\n" \
"{order}"

# Notification: order has been refunded
notification_order_refunded = "Ваше замовлення відмінено. Кошти повернуто!\n" \
"\n" \
"{order}"

# Notification: a manual transaction was applied
Expand All @@ -351,7 +350,7 @@

# Help: guide
help_msg = "Інструкція по greed доступна за цією адресою:\n" \
"https://docs.google.com/document/d/1f4MKVr0B7RSQfWTSa_6ZO0LM4nPpky_GX_qdls3EHtQ/"
"https://github.com/Steffo99/greed/wiki"

# Help: contact shopkeeper
contact_shopkeeper = "Наразі наступні працівники доступні і зможуть допомогти:\n" \
Expand Down