mirror of
https://github.com/Steffo99/greed.git
synced 2024-11-22 05:54:18 +00:00
Fix some price bugs
This commit is contained in:
parent
c28675f395
commit
214401a509
3 changed files with 23 additions and 12 deletions
|
@ -92,6 +92,9 @@ menu_products = "📝️ Prodotti"
|
||||||
# Admin menu: orders
|
# Admin menu: orders
|
||||||
menu_orders = "📦 Ordini"
|
menu_orders = "📦 Ordini"
|
||||||
|
|
||||||
|
# Menu: transactions
|
||||||
|
menu_transactions = "💳 Transazioni"
|
||||||
|
|
||||||
# Admin menu: go to user mode
|
# Admin menu: go to user mode
|
||||||
menu_user_mode = "👤 Passa alla modalità utente"
|
menu_user_mode = "👤 Passa alla modalità utente"
|
||||||
|
|
||||||
|
|
16
utils.py
16
utils.py
|
@ -19,6 +19,9 @@ class Price:
|
||||||
# Copy self
|
# Copy self
|
||||||
self.value = value.value
|
self.value = value.value
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"<Price of value {self.value}>"
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return currency_format_string.format(symbol=currency_symbol, value="{0:.2f}".format(self.value / (10 ** int(config["Payments"]["currency_exp"]))))
|
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)
|
return Price(self.value - Price(other).value)
|
||||||
|
|
||||||
def __mul__(self, other):
|
def __mul__(self, other):
|
||||||
return Price(self.value * Price(other).value)
|
return Price(int(self.value * other))
|
||||||
|
|
||||||
def __floordiv__(self, other):
|
def __floordiv__(self, other):
|
||||||
return Price(self.value // Price(other).value)
|
return Price(int(self.value // other))
|
||||||
|
|
||||||
def __radd__(self, other):
|
def __radd__(self, other):
|
||||||
self.__add__(other)
|
return self.__add__(other)
|
||||||
|
|
||||||
def __rsub__(self, other):
|
def __rsub__(self, other):
|
||||||
return Price(Price(other).value - self.value)
|
return Price(Price(other).value - self.value)
|
||||||
|
|
||||||
def __rmul__(self, other):
|
def __rmul__(self, other):
|
||||||
self.__mul__(other)
|
return self.__mul__(other)
|
||||||
|
|
||||||
def __iadd__(self, other):
|
def __iadd__(self, other):
|
||||||
self.value += Price(other).value
|
self.value += Price(other).value
|
||||||
|
@ -73,9 +76,10 @@ class Price:
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __imul__(self, other):
|
def __imul__(self, other):
|
||||||
self.value *= Price(other).value
|
self.value *= other
|
||||||
|
self.value = int(self.value)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __ifloordiv__(self, other):
|
def __ifloordiv__(self, other):
|
||||||
self.value //= Price(other).value
|
self.value //= other
|
||||||
return self
|
return self
|
||||||
|
|
16
worker.py
16
worker.py
|
@ -465,9 +465,8 @@ class ChatWorker(threading.Thread):
|
||||||
# Create the price array
|
# Create the price array
|
||||||
prices = [telegram.LabeledPrice(label=strings.payment_invoice_label, amount=int(value))]
|
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
|
# 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_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
|
total_fee = value * fee_percentage + fee_fixed
|
||||||
if total_fee > 0:
|
if total_fee > 0:
|
||||||
prices.append(telegram.LabeledPrice(label=strings.payment_invoice_fee_label, amount=int(total_fee)))
|
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."""
|
Administrative bot actions should be placed here."""
|
||||||
# Loop used to return to the menu after executing a command
|
# Loop used to return to the menu after executing a command
|
||||||
while True:
|
while True:
|
||||||
# Create a keyboard with the admin main menu
|
# Create a keyboard with the admin main menu based on the admin permissions specified in the db
|
||||||
keyboard = [[telegram.KeyboardButton(strings.menu_products)],
|
keyboard = [[strings.menu_user_mode]]
|
||||||
[telegram.KeyboardButton(strings.menu_orders)],
|
if self.admin.edit_products:
|
||||||
[telegram.KeyboardButton(strings.menu_user_mode)]]
|
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)
|
# 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,
|
self.bot.send_message(self.chat.id, strings.conversation_open_admin_menu,
|
||||||
reply_markup=telegram.ReplyKeyboardMarkup(keyboard, one_time_keyboard=True))
|
reply_markup=telegram.ReplyKeyboardMarkup(keyboard, one_time_keyboard=True))
|
||||||
|
@ -716,6 +719,7 @@ class ChatWorker(threading.Thread):
|
||||||
if isinstance(update, CancelSignal):
|
if isinstance(update, CancelSignal):
|
||||||
# Stop the listening mode
|
# Stop the listening mode
|
||||||
self.listening_mode = False
|
self.listening_mode = False
|
||||||
|
break
|
||||||
# If the user pressed the complete order button, complete the order
|
# If the user pressed the complete order button, complete the order
|
||||||
elif update.data == "order_complete":
|
elif update.data == "order_complete":
|
||||||
# Find the order
|
# Find the order
|
||||||
|
|
Loading…
Reference in a new issue