mirror of
https://github.com/Steffo99/greed.git
synced 2024-11-22 05:54:18 +00:00
Unfinished order representation
This commit is contained in:
parent
ea02db4786
commit
b056343855
4 changed files with 43 additions and 1 deletions
22
database.py
22
database.py
|
@ -54,6 +54,13 @@ class User(TableDeclarativeBase):
|
||||||
else:
|
else:
|
||||||
return self.first_name
|
return self.first_name
|
||||||
|
|
||||||
|
def mention(self):
|
||||||
|
"""Mention the user in the best way possible given the available data."""
|
||||||
|
if self.username is not None:
|
||||||
|
return f"@{self.username}"
|
||||||
|
else:
|
||||||
|
return f"[{self.first_name}](tg://user?id={self.user_id})"
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<User {self} having {self.credit} credit>"
|
return f"<User {self} having {self.credit} credit>"
|
||||||
|
|
||||||
|
@ -182,6 +189,7 @@ class Admin(TableDeclarativeBase):
|
||||||
user_id = Column(BigInteger, ForeignKey("users.user_id"), primary_key=True)
|
user_id = Column(BigInteger, ForeignKey("users.user_id"), primary_key=True)
|
||||||
user = relationship("User")
|
user = relationship("User")
|
||||||
# Permissions
|
# Permissions
|
||||||
|
receive_orders = Column(Boolean, default=True)
|
||||||
# TODO: unfinished
|
# TODO: unfinished
|
||||||
|
|
||||||
# Extra table parameters
|
# Extra table parameters
|
||||||
|
@ -215,6 +223,17 @@ class Order(TableDeclarativeBase):
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<Order {self.order_id} placed by User {self.user_id}>"
|
return f"<Order {self.order_id} placed by User {self.user_id}>"
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
items = ""
|
||||||
|
for item in self.items:
|
||||||
|
items += str(item) + "\n"
|
||||||
|
return strings.order_format_string.format(id=self.order_id,
|
||||||
|
user=self.user.mention(),
|
||||||
|
date=self.creation_date.isoformat(),
|
||||||
|
items=items,
|
||||||
|
notes=self.notes if self.notes is not None else "",
|
||||||
|
value=#TODO)
|
||||||
|
|
||||||
|
|
||||||
class OrderItem(TableDeclarativeBase):
|
class OrderItem(TableDeclarativeBase):
|
||||||
"""A product that has been purchased as part of an order."""
|
"""A product that has been purchased as part of an order."""
|
||||||
|
@ -230,6 +249,9 @@ class OrderItem(TableDeclarativeBase):
|
||||||
# Extra table parameters
|
# Extra table parameters
|
||||||
__tablename__ = "orderitems"
|
__tablename__ = "orderitems"
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.product.name} - {self.product.price}"
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<OrderItem {self.item_id}>"
|
return f"<OrderItem {self.item_id}>"
|
||||||
|
|
||||||
|
|
14
strings.py
14
strings.py
|
@ -14,6 +14,16 @@ in_stock_format_string = "{quantity} disponibili"
|
||||||
# Copies of a product in cart
|
# Copies of a product in cart
|
||||||
in_cart_format_string = "{quantity} nel carrello"
|
in_cart_format_string = "{quantity} nel carrello"
|
||||||
|
|
||||||
|
# Order info displayed string
|
||||||
|
order_format_string = "Ordine #{id}\n" \
|
||||||
|
"di {user}\n" \
|
||||||
|
"{value}\n" \
|
||||||
|
"Creato {date}\n" \
|
||||||
|
"\n" \
|
||||||
|
"{items}\n" \
|
||||||
|
"\n" \
|
||||||
|
"{notes}"
|
||||||
|
|
||||||
# Conversation: the start command was sent and the bot should welcome the user
|
# Conversation: the start command was sent and the bot should welcome the user
|
||||||
conversation_after_start = "Ciao!\n" \
|
conversation_after_start = "Ciao!\n" \
|
||||||
"Benvenuto su greed!"
|
"Benvenuto su greed!"
|
||||||
|
@ -150,6 +160,10 @@ payment_invoice_label = "Ricarica"
|
||||||
# Payment: label of the labeled price on the invoice
|
# Payment: label of the labeled price on the invoice
|
||||||
payment_invoice_fee_label = "Supplemento carta"
|
payment_invoice_fee_label = "Supplemento carta"
|
||||||
|
|
||||||
|
# Notification: order has been placed
|
||||||
|
notification_order_placed = "*️⃣ E' stato piazzato un nuovo ordine:\n" \
|
||||||
|
"{order}"
|
||||||
|
|
||||||
# Info: informazioni sul bot
|
# Info: informazioni sul bot
|
||||||
bot_info = 'Questo bot utilizza <a href="https://github.com/Steffo99/greed">greed</a>,' \
|
bot_info = 'Questo bot utilizza <a href="https://github.com/Steffo99/greed">greed</a>,' \
|
||||||
' un framework di @Steffo per i pagamenti su Telegram rilasciato sotto la' \
|
' un framework di @Steffo per i pagamenti su Telegram rilasciato sotto la' \
|
||||||
|
|
3
utils.py
3
utils.py
|
@ -1,3 +1,5 @@
|
||||||
|
import time
|
||||||
|
|
||||||
from configloader import config
|
from configloader import config
|
||||||
from strings import currency_format_string, currency_symbol
|
from strings import currency_format_string, currency_symbol
|
||||||
import typing
|
import typing
|
||||||
|
@ -77,4 +79,3 @@ class Price:
|
||||||
def __ifloordiv__(self, other):
|
def __ifloordiv__(self, other):
|
||||||
self.value //= Price(other).value
|
self.value //= Price(other).value
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
|
@ -371,6 +371,11 @@ class ChatWorker(threading.Thread):
|
||||||
self.session.commit()
|
self.session.commit()
|
||||||
# Notify the user of the order result
|
# Notify the user of the order result
|
||||||
self.bot.send_message(self.chat.id, strings.success_order_created)
|
self.bot.send_message(self.chat.id, strings.success_order_created)
|
||||||
|
# Notify the admins (with Order Notifications enabled) of the new order created
|
||||||
|
admins = self.session.query(db.Admin).filter_by(receive_orders=True).all()
|
||||||
|
# Notify them of the new placed order
|
||||||
|
for admin in admins:
|
||||||
|
self.bot.send_message(admin.user_id, f"{strings.notification_order_placed.format(order=str(order))}")
|
||||||
|
|
||||||
def __order_status(self):
|
def __order_status(self):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
Loading…
Reference in a new issue