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

Fix some price bugs

This commit is contained in:
Steffo 2018-03-22 10:33:50 +01:00
parent c28675f395
commit 214401a509
3 changed files with 23 additions and 12 deletions

View file

@ -92,6 +92,9 @@ menu_products = "📝️ Prodotti"
# Admin menu: orders
menu_orders = "📦 Ordini"
# Menu: transactions
menu_transactions = "💳 Transazioni"
# Admin menu: go to user mode
menu_user_mode = "👤 Passa alla modalità utente"

View file

@ -19,6 +19,9 @@ class Price:
# Copy self
self.value = value.value
def __repr__(self):
return f"<Price of value {self.value}>"
def __str__(self):
return currency_format_string.format(symbol=currency_symbol, value="{0:.2f}".format(self.value / (10 ** int(config["Payments"]["currency_exp"]))))
@ -50,19 +53,19 @@ class Price:
return Price(self.value - Price(other).value)
def __mul__(self, other):
return Price(self.value * Price(other).value)
return Price(int(self.value * other))
def __floordiv__(self, other):
return Price(self.value // Price(other).value)
return Price(int(self.value // other))
def __radd__(self, other):
self.__add__(other)
return self.__add__(other)
def __rsub__(self, other):
return Price(Price(other).value - self.value)
def __rmul__(self, other):
self.__mul__(other)
return self.__mul__(other)
def __iadd__(self, other):
self.value += Price(other).value
@ -73,9 +76,10 @@ class Price:
return self
def __imul__(self, other):
self.value *= Price(other).value
self.value *= other
self.value = int(self.value)
return self
def __ifloordiv__(self, other):
self.value //= Price(other).value
self.value //= other
return self

View file

@ -465,9 +465,8 @@ class ChatWorker(threading.Thread):
# Create the price array
prices = [telegram.LabeledPrice(label=strings.payment_invoice_label, amount=int(value))]
# If the user has to pay a fee when using the credit card, add it to the prices list
# TODO: there's a bug here
fee_percentage = float(configloader.config["Credit Card"]["fee_percentage"]) / 100
fee_fixed = Price(configloader.config["Credit Card"]["fee_fixed"])
fee_fixed = int(configloader.config["Credit Card"]["fee_fixed"])
total_fee = value * fee_percentage + fee_fixed
if total_fee > 0:
prices.append(telegram.LabeledPrice(label=strings.payment_invoice_fee_label, amount=int(total_fee)))
@ -525,10 +524,14 @@ class ChatWorker(threading.Thread):
Administrative bot actions should be placed here."""
# Loop used to return to the menu after executing a command
while True:
# Create a keyboard with the admin main menu
keyboard = [[telegram.KeyboardButton(strings.menu_products)],
[telegram.KeyboardButton(strings.menu_orders)],
[telegram.KeyboardButton(strings.menu_user_mode)]]
# Create a keyboard with the admin main menu based on the admin permissions specified in the db
keyboard = [[strings.menu_user_mode]]
if self.admin.edit_products:
keyboard.append([strings.menu_products])
if self.admin.receive_orders:
keyboard.append([strings.menu_orders])
if self.admin.view_transactions:
keyboard.append([strings.menu_transactions])
# 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_admin_menu,
reply_markup=telegram.ReplyKeyboardMarkup(keyboard, one_time_keyboard=True))
@ -716,6 +719,7 @@ class ChatWorker(threading.Thread):
if isinstance(update, CancelSignal):
# Stop the listening mode
self.listening_mode = False
break
# If the user pressed the complete order button, complete the order
elif update.data == "order_complete":
# Find the order