1
Fork 0
mirror of https://github.com/Steffo99/greed.git synced 2024-11-22 05:54:18 +00:00

Recover corrupt git repo

This commit is contained in:
Steffo 2018-03-12 10:19:01 +01:00
parent b056343855
commit 3ba6916ffe
2 changed files with 13 additions and 7 deletions

View file

@ -163,7 +163,8 @@ class Transaction(TableDeclarativeBase):
payment_email = Column(String) payment_email = Column(String)
# Order ID # Order ID
order_id = Column(Integer) order_id = Column(Integer, ForeignKey("orders.order_id"))
order = relationship("Order")
# Extra table parameters # Extra table parameters
__tablename__ = "transactions" __tablename__ = "transactions"
@ -216,6 +217,8 @@ class Order(TableDeclarativeBase):
items = relationship("OrderItem") items = relationship("OrderItem")
# Extra details specified by the purchasing user # Extra details specified by the purchasing user
notes = Column(Text) notes = Column(Text)
# Linked transaction
transaction = relationship("Transaction", uselist=False)
# Extra table parameters # Extra table parameters
__tablename__ = "orders" __tablename__ = "orders"
@ -223,7 +226,8 @@ class Order(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 __str__(self): def get_text(self, session):
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 += str(item) + "\n" items += str(item) + "\n"
@ -232,7 +236,7 @@ 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=#TODO) value=str(Price(-joined_self.transaction.value)))
class OrderItem(TableDeclarativeBase): class OrderItem(TableDeclarativeBase):
@ -250,7 +254,7 @@ class OrderItem(TableDeclarativeBase):
__tablename__ = "orderitems" __tablename__ = "orderitems"
def __str__(self): def __str__(self):
return f"{self.product.name} - {self.product.price}" return f"{self.product.name} - {str(Price(self.product.price))}"
def __repr__(self): def __repr__(self):
return f"<OrderItem {self.item_id}>" return f"<OrderItem {self.item_id}>"

View file

@ -363,7 +363,8 @@ class ChatWorker(threading.Thread):
return return
# Create a new transaction and add it to the session # Create a new transaction and add it to the session
transaction = db.Transaction(user=self.user, transaction = db.Transaction(user=self.user,
value=value) value=value,
order_id=order.order_id)
self.session.add(transaction) self.session.add(transaction)
# Subtract credit from the user # Subtract credit from the user
self.user.credit += value self.user.credit += value
@ -375,7 +376,7 @@ class ChatWorker(threading.Thread):
admins = self.session.query(db.Admin).filter_by(receive_orders=True).all() admins = self.session.query(db.Admin).filter_by(receive_orders=True).all()
# Notify them of the new placed order # Notify them of the new placed order
for admin in admins: for admin in admins:
self.bot.send_message(admin.user_id, f"{strings.notification_order_placed.format(order=str(order))}") self.bot.send_message(admin.user_id, f"{strings.notification_order_placed.format(order=order.get_text(self.session))}")
def __order_status(self): def __order_status(self):
raise NotImplementedError() raise NotImplementedError()
@ -457,7 +458,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
fee_percentage = Price(configloader.config["Credit Card"]["fee_percentage"]) // 100 # 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 = Price(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: