1
Fork 0
mirror of https://github.com/Steffo99/greed.git synced 2024-11-21 13:34:18 +00:00

Add order status

This commit is contained in:
Steffo 2018-04-05 09:30:32 +02:00
parent aa96ac0f73
commit 410aa99018
4 changed files with 36 additions and 14 deletions

View file

@ -253,7 +253,8 @@ class Order(TableDeclarativeBase):
date=self.creation_date.isoformat(),
items=items,
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):

View file

@ -31,7 +31,8 @@ conversation_after_start = "Ciao!\n" \
"Benvenuto su greed!"
# 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_open_user_menu_multiple = "Hai bisogno di qualcos'altro?"
@ -192,7 +193,7 @@ payment_invoice_label = "Ricarica"
payment_invoice_fee_label = "Supplemento carta"
# 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}"
# 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_refunded = "Un tuo ordine è stato rimborsato!\n" \
"{order}\n" \
"\n" \
"Motivazione data dal negoziante:\n" \
"{reason}"
"{order}"
# Refund reason
refund_reason = "Motivazione del rimborso:\n" \
"{reason}"
# Info: informazioni sul bot
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: 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!"

View file

@ -1,4 +1,5 @@
import time
import telegram
import telegram.error
from configloader import config
from strings import currency_format_string, currency_symbol
@ -83,3 +84,4 @@ class Price:
def __ifloordiv__(self, other):
self.value //= other
return self

View file

@ -64,6 +64,11 @@ class ChatWorker(threading.Thread):
self.__user_menu()
# If the user is an admin, send him to the admin menu
else:
# Clear the live orders flag
self.admin.live_mode = False
# Commit the change
self.session.commit()
# Open the admin menu
self.__admin_menu()
def stop(self, reason: str=""):
@ -210,8 +215,10 @@ class ChatWorker(threading.Thread):
[telegram.KeyboardButton(strings.menu_add_credit)],
[telegram.KeyboardButton(strings.menu_bot_info)]]
# 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,
reply_markup=telegram.ReplyKeyboardMarkup(keyboard, one_time_keyboard=True))
self.bot.send_message(self.chat.id,
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
selection = self.__wait_for_specific_message([strings.menu_order, strings.menu_order_status,
strings.menu_add_credit, strings.menu_bot_info])
@ -392,7 +399,15 @@ class ChatWorker(threading.Thread):
def __order_status(self):
"""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):
"""Add more credit to the account."""
@ -766,8 +781,7 @@ class ChatWorker(threading.Thread):
# 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)
# 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):
"""Handle the graceful stop of the thread."""