mirror of
https://github.com/Steffo99/greed.git
synced 2024-11-22 05:54:18 +00:00
Add order status
This commit is contained in:
parent
aa96ac0f73
commit
410aa99018
4 changed files with 36 additions and 14 deletions
|
@ -253,7 +253,8 @@ class Order(TableDeclarativeBase):
|
||||||
date=self.creation_date.isoformat(),
|
date=self.creation_date.isoformat(),
|
||||||
items=items,
|
items=items,
|
||||||
notes=self.notes if self.notes is not None else "",
|
notes=self.notes if self.notes is not None else "",
|
||||||
value=str(Price(-joined_self.transaction.value)))
|
value=str(Price(-joined_self.transaction.value))) + \
|
||||||
|
(strings.refund_reason.format(reason=self.refund_reason) if self.refund_date is not None else "")
|
||||||
|
|
||||||
|
|
||||||
class OrderItem(TableDeclarativeBase):
|
class OrderItem(TableDeclarativeBase):
|
||||||
|
|
19
strings.py
19
strings.py
|
@ -31,7 +31,8 @@ conversation_after_start = "Ciao!\n" \
|
||||||
"Benvenuto su greed!"
|
"Benvenuto su greed!"
|
||||||
|
|
||||||
# Conversation: to send an inline keyboard you need to send a message with it
|
# Conversation: to send an inline keyboard you need to send a message with it
|
||||||
conversation_open_user_menu = "Cosa vorresti fare?"
|
conversation_open_user_menu = "Cosa vorresti fare?\n" \
|
||||||
|
"Hai <b>{credit}</b> sul portafoglio."
|
||||||
|
|
||||||
# Conversation: the same message as above but when the first has already been sent
|
# Conversation: the same message as above but when the first has already been sent
|
||||||
conversation_open_user_menu_multiple = "Hai bisogno di qualcos'altro?"
|
conversation_open_user_menu_multiple = "Hai bisogno di qualcos'altro?"
|
||||||
|
@ -192,7 +193,7 @@ payment_invoice_label = "Ricarica"
|
||||||
payment_invoice_fee_label = "Supplemento carta"
|
payment_invoice_fee_label = "Supplemento carta"
|
||||||
|
|
||||||
# Notification: order has been placed
|
# Notification: order has been placed
|
||||||
notification_order_placed = "*️⃣ E' stato piazzato un nuovo ordine:\n" \
|
notification_order_placed = "E' stato piazzato un nuovo ordine:\n" \
|
||||||
"{order}"
|
"{order}"
|
||||||
|
|
||||||
# Notification: order has been completed
|
# Notification: order has been completed
|
||||||
|
@ -201,10 +202,11 @@ notification_order_completed = "Un tuo ordine è stato completato!\n" \
|
||||||
|
|
||||||
# Notification: order has been refunded
|
# Notification: order has been refunded
|
||||||
notification_order_refunded = "Un tuo ordine è stato rimborsato!\n" \
|
notification_order_refunded = "Un tuo ordine è stato rimborsato!\n" \
|
||||||
"{order}\n" \
|
"{order}"
|
||||||
"\n" \
|
|
||||||
"Motivazione data dal negoziante:\n" \
|
# Refund reason
|
||||||
"{reason}"
|
refund_reason = "Motivazione del rimborso:\n" \
|
||||||
|
"{reason}"
|
||||||
|
|
||||||
# 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>,' \
|
||||||
|
@ -250,4 +252,7 @@ error_duplicate_name = "️⚠️ Esiste già un prodotto con questo nome."
|
||||||
error_not_enough_credit = "⚠️ Non hai credito sufficiente per effettuare l'ordine."
|
error_not_enough_credit = "⚠️ Non hai credito sufficiente per effettuare l'ordine."
|
||||||
|
|
||||||
# Error: order has already been cleared
|
# Error: order has already been cleared
|
||||||
error_order_already_cleared = "⚠️ Questo ordine è già stato processato."
|
error_order_already_cleared = "⚠️ Questo ordine è già stato processato."
|
||||||
|
|
||||||
|
# Error: no orders have been placed, so none can be shown
|
||||||
|
error_no_orders = "⚠️ Non hai ancora piazzato ordini, quindi non c'è niente da visualizzare!"
|
4
utils.py
4
utils.py
|
@ -1,4 +1,5 @@
|
||||||
import time
|
import telegram
|
||||||
|
import telegram.error
|
||||||
|
|
||||||
from configloader import config
|
from configloader import config
|
||||||
from strings import currency_format_string, currency_symbol
|
from strings import currency_format_string, currency_symbol
|
||||||
|
@ -83,3 +84,4 @@ class Price:
|
||||||
def __ifloordiv__(self, other):
|
def __ifloordiv__(self, other):
|
||||||
self.value //= other
|
self.value //= other
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
24
worker.py
24
worker.py
|
@ -64,6 +64,11 @@ class ChatWorker(threading.Thread):
|
||||||
self.__user_menu()
|
self.__user_menu()
|
||||||
# If the user is an admin, send him to the admin menu
|
# If the user is an admin, send him to the admin menu
|
||||||
else:
|
else:
|
||||||
|
# Clear the live orders flag
|
||||||
|
self.admin.live_mode = False
|
||||||
|
# Commit the change
|
||||||
|
self.session.commit()
|
||||||
|
# Open the admin menu
|
||||||
self.__admin_menu()
|
self.__admin_menu()
|
||||||
|
|
||||||
def stop(self, reason: str=""):
|
def stop(self, reason: str=""):
|
||||||
|
@ -210,8 +215,10 @@ class ChatWorker(threading.Thread):
|
||||||
[telegram.KeyboardButton(strings.menu_add_credit)],
|
[telegram.KeyboardButton(strings.menu_add_credit)],
|
||||||
[telegram.KeyboardButton(strings.menu_bot_info)]]
|
[telegram.KeyboardButton(strings.menu_bot_info)]]
|
||||||
# Send the previously created keyboard to the user (ensuring it can be clicked only 1 time)
|
# Send the previously created keyboard to the user (ensuring it can be clicked only 1 time)
|
||||||
self.bot.send_message(self.chat.id, strings.conversation_open_user_menu,
|
self.bot.send_message(self.chat.id,
|
||||||
reply_markup=telegram.ReplyKeyboardMarkup(keyboard, one_time_keyboard=True))
|
strings.conversation_open_user_menu.format(credit=Price(self.user.credit)),
|
||||||
|
reply_markup=telegram.ReplyKeyboardMarkup(keyboard, one_time_keyboard=True),
|
||||||
|
parse_mode="HTML")
|
||||||
# Wait for a reply from the user
|
# Wait for a reply from the user
|
||||||
selection = self.__wait_for_specific_message([strings.menu_order, strings.menu_order_status,
|
selection = self.__wait_for_specific_message([strings.menu_order, strings.menu_order_status,
|
||||||
strings.menu_add_credit, strings.menu_bot_info])
|
strings.menu_add_credit, strings.menu_bot_info])
|
||||||
|
@ -392,7 +399,15 @@ class ChatWorker(threading.Thread):
|
||||||
|
|
||||||
def __order_status(self):
|
def __order_status(self):
|
||||||
"""Display the status of the sent orders."""
|
"""Display the status of the sent orders."""
|
||||||
pass
|
# Find the latest orders
|
||||||
|
orders = self.session.query(db.Order).filter(db.Order.user == self.user).order_by(db.Order.creation_date.desc()).limit(5).all()
|
||||||
|
# Ensure there is at least one order to display
|
||||||
|
if len(orders) == 0:
|
||||||
|
self.bot.send_message(self.chat.id, strings.error_no_orders)
|
||||||
|
# Display the order status to the user
|
||||||
|
for order in orders:
|
||||||
|
self.bot.send_message(self.chat.id, order.get_text(self.session))
|
||||||
|
# TODO: maybe add a page displayer instead of showing the latest 5 orders
|
||||||
|
|
||||||
def __add_credit_menu(self):
|
def __add_credit_menu(self):
|
||||||
"""Add more credit to the account."""
|
"""Add more credit to the account."""
|
||||||
|
@ -766,8 +781,7 @@ class ChatWorker(threading.Thread):
|
||||||
# Update the order message
|
# Update the order message
|
||||||
self.bot.edit_message_text(order.get_text(session=self.session), chat_id=self.chat.id, message_id=update.message.message_id)
|
self.bot.edit_message_text(order.get_text(session=self.session), chat_id=self.chat.id, message_id=update.message.message_id)
|
||||||
# Notify the user of the refund
|
# Notify the user of the refund
|
||||||
self.bot.send_message(order.user_id, strings.notification_order_refunded.format(order=order.get_text(self.session), reason=reply))
|
self.bot.send_message(order.user_id, strings.notification_order_refunded.format(order=order.get_text(self.session)))
|
||||||
|
|
||||||
|
|
||||||
def __graceful_stop(self):
|
def __graceful_stop(self):
|
||||||
"""Handle the graceful stop of the thread."""
|
"""Handle the graceful stop of the thread."""
|
||||||
|
|
Loading…
Reference in a new issue