mirror of
https://github.com/Steffo99/greed.git
synced 2024-11-25 15:24:17 +00:00
🔧 Remove unnecessary session parameter
This commit is contained in:
parent
0e1bf502ff
commit
6cf8a3d43e
2 changed files with 9 additions and 12 deletions
|
@ -253,8 +253,7 @@ class Order(DeferredReflection, 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 text(self, w: "worker.Worker", session, user=False):
|
def text(self, w: "worker.Worker", user=False):
|
||||||
joined_self = session.query(Order).filter_by(order_id=self.order_id).join(Transaction).one()
|
|
||||||
items = ""
|
items = ""
|
||||||
for item in self.items:
|
for item in self.items:
|
||||||
items += item.text(w) + "\n"
|
items += item.text(w) + "\n"
|
||||||
|
@ -273,7 +272,7 @@ class Order(DeferredReflection, TableDeclarativeBase):
|
||||||
status_text=status_text,
|
status_text=status_text,
|
||||||
items=items,
|
items=items,
|
||||||
notes=self.notes,
|
notes=self.notes,
|
||||||
value=str(w.Price(-joined_self.transaction.value))) + \
|
value=str(w.Price(-self.transaction.value))) + \
|
||||||
(w.loc.get("refund_reason", reason=self.refund_reason) if self.refund_date is not None else "")
|
(w.loc.get("refund_reason", reason=self.refund_reason) if self.refund_date is not None else "")
|
||||||
else:
|
else:
|
||||||
return status_emoji + " " + \
|
return status_emoji + " " + \
|
||||||
|
@ -283,7 +282,7 @@ class Order(DeferredReflection, 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(w.Price(-joined_self.transaction.value))) + \
|
value=str(w.Price(-self.transaction.value))) + \
|
||||||
(w.loc.get("refund_reason", reason=self.refund_reason) if self.refund_date is not None else "")
|
(w.loc.get("refund_reason", reason=self.refund_reason) if self.refund_date is not None else "")
|
||||||
|
|
||||||
|
|
||||||
|
|
14
worker.py
14
worker.py
|
@ -709,7 +709,6 @@ class Worker(threading.Thread):
|
||||||
def __order_notify_admins(self, order):
|
def __order_notify_admins(self, order):
|
||||||
# Notify the user of the order result
|
# Notify the user of the order result
|
||||||
self.bot.send_message(self.chat.id, self.loc.get("success_order_created", order=order.text(w=self,
|
self.bot.send_message(self.chat.id, self.loc.get("success_order_created", order=order.text(w=self,
|
||||||
session=self.session,
|
|
||||||
user=True)))
|
user=True)))
|
||||||
# Notify the admins (in Live Orders mode) of the new order
|
# Notify the admins (in Live Orders mode) of the new order
|
||||||
admins = self.session.query(db.Admin).filter_by(live_mode=True).all()
|
admins = self.session.query(db.Admin).filter_by(live_mode=True).all()
|
||||||
|
@ -723,7 +722,7 @@ class Worker(threading.Thread):
|
||||||
for admin in admins:
|
for admin in admins:
|
||||||
self.bot.send_message(admin.user_id,
|
self.bot.send_message(admin.user_id,
|
||||||
self.loc.get('notification_order_placed',
|
self.loc.get('notification_order_placed',
|
||||||
order=order.text(w=self, session=self.session)),
|
order=order.text(w=self)),
|
||||||
reply_markup=order_keyboard)
|
reply_markup=order_keyboard)
|
||||||
|
|
||||||
def __order_status(self):
|
def __order_status(self):
|
||||||
|
@ -740,7 +739,7 @@ class Worker(threading.Thread):
|
||||||
self.bot.send_message(self.chat.id, self.loc.get("error_no_orders"))
|
self.bot.send_message(self.chat.id, self.loc.get("error_no_orders"))
|
||||||
# Display the order status to the user
|
# Display the order status to the user
|
||||||
for order in orders:
|
for order in orders:
|
||||||
self.bot.send_message(self.chat.id, order.text(w=self, session=self.session, user=True))
|
self.bot.send_message(self.chat.id, order.text(w=self, user=True))
|
||||||
# TODO: maybe add a page displayer instead of showing the latest 5 orders
|
# TODO: maybe add a page displayer instead of showing the latest 5 orders
|
||||||
|
|
||||||
def __add_credit_menu(self):
|
def __add_credit_menu(self):
|
||||||
|
@ -1136,7 +1135,7 @@ class Worker(threading.Thread):
|
||||||
# Create a message for every one of them
|
# Create a message for every one of them
|
||||||
for order in orders:
|
for order in orders:
|
||||||
# Send the created message
|
# Send the created message
|
||||||
self.bot.send_message(self.chat.id, order.text(w=self, session=self.session),
|
self.bot.send_message(self.chat.id, order.text(w=self),
|
||||||
reply_markup=order_keyboard)
|
reply_markup=order_keyboard)
|
||||||
# Set the Live mode flag to True
|
# Set the Live mode flag to True
|
||||||
self.admin.live_mode = True
|
self.admin.live_mode = True
|
||||||
|
@ -1165,12 +1164,12 @@ class Worker(threading.Thread):
|
||||||
# Commit the transaction
|
# Commit the transaction
|
||||||
self.session.commit()
|
self.session.commit()
|
||||||
# Update order message
|
# Update order message
|
||||||
self.bot.edit_message_text(order.text(w=self, session=self.session), chat_id=self.chat.id,
|
self.bot.edit_message_text(order.text(w=self), chat_id=self.chat.id,
|
||||||
message_id=update.message.message_id)
|
message_id=update.message.message_id)
|
||||||
# Notify the user of the completition
|
# Notify the user of the completition
|
||||||
self.bot.send_message(order.user_id,
|
self.bot.send_message(order.user_id,
|
||||||
self.loc.get("notification_order_completed",
|
self.loc.get("notification_order_completed",
|
||||||
order=order.text(w=self, session=self.session, user=True)))
|
order=order.text(w=self, user=True)))
|
||||||
# If the user pressed the refund order button, refund the order...
|
# If the user pressed the refund order button, refund the order...
|
||||||
elif update.data == "order_refund":
|
elif update.data == "order_refund":
|
||||||
# Ask for a refund reason
|
# Ask for a refund reason
|
||||||
|
@ -1194,13 +1193,12 @@ class Worker(threading.Thread):
|
||||||
# Commit the changes
|
# Commit the changes
|
||||||
self.session.commit()
|
self.session.commit()
|
||||||
# Update the order message
|
# Update the order message
|
||||||
self.bot.edit_message_text(order.text(w=self, session=self.session),
|
self.bot.edit_message_text(order.text(w=self),
|
||||||
chat_id=self.chat.id,
|
chat_id=self.chat.id,
|
||||||
message_id=update.message.message_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,
|
self.bot.send_message(order.user_id,
|
||||||
self.loc.get("notification_order_refunded", order=order.text(w=self,
|
self.loc.get("notification_order_refunded", order=order.text(w=self,
|
||||||
session=self.session,
|
|
||||||
user=True)))
|
user=True)))
|
||||||
# Notify the admin of the refund
|
# Notify the admin of the refund
|
||||||
self.bot.send_message(self.chat.id, self.loc.get("success_order_refunded", order_id=order.order_id))
|
self.bot.send_message(self.chat.id, self.loc.get("success_order_refunded", order_id=order.order_id))
|
||||||
|
|
Loading…
Reference in a new issue