Fix references to removed concepts

This will probably not work but it's a start and it was needed to get
the DB migrations running
This commit is contained in:
Midgard 2020-01-26 02:52:45 +01:00
parent ecb0550fdd
commit e46d5e622e
Signed by: midgard
GPG key ID: 511C112F1331BBB4
2 changed files with 9 additions and 16 deletions

View file

@ -3,7 +3,6 @@ import typing
from datetime import datetime
from .database import db
from .location import Location
from .user import User
@ -19,12 +18,11 @@ class Order(db.Model):
items = db.relationship("OrderItem", backref="order", lazy="dynamic")
def configure(self, courier: User, location: Location,
def configure(self, courier: User,
starttime: db.DateTime, stoptime: db.DateTime,) -> None:
"Configure the Order"
# pylint: disable=W0201
self.courier = courier
self.location = location
self.starttime = starttime
self.stoptime = stoptime
@ -40,13 +38,13 @@ class Order(db.Model):
group: typing.Dict[str, typing.Any] = dict()
for item in self.items:
user = group.get(item.get_name(), dict())
user["total"] = user.get("total", 0) + item.product.price
user["total"] = user.get("total", 0) + item.price
user["to_pay"] = (
user.get("to_pay", 0) +
item.product.price if not item.paid else 0
item.price if not item.paid else 0
)
user["paid"] = user.get("paid", True) and item.paid
user["products"] = user.get("products", []) + [item.product]
user["products"] = user.get("products", []) + [item.dish_name]
group[item.get_name()] = user
return group
@ -55,11 +53,11 @@ class Order(db.Model):
"Group items of an Order by product"
group: typing.Dict[str, typing.Any] = dict()
for item in self.items:
product = group.get(item.product.name, dict())
product = group.get(item.dish_name, dict())
product["count"] = product.get("count", 0) + 1
if item.extra:
product["extras"] = product.get("extras", []) + [item.extra]
group[item.product.name] = product
product["extras"] = product.get("extras", []) + [item.comment]
group[item.dish_name] = product
return group

View file

@ -3,7 +3,6 @@ from datetime import datetime
from .database import db
from .order import Order
from .product import Product
from .user import User
@ -22,12 +21,11 @@ class OrderItem(db.Model):
comment = db.Column(db.String(254), nullable=True)
hlds_data_version = db.Column(db.String(40), nullable=True)
def configure(self, user: User, order: Order, product: Product) -> None:
def configure(self, user: User, order: Order) -> None:
"Configure the OrderItem"
# pylint: disable=W0201
self.user = user
self.order = order
self.product = product
def get_name(self) -> str:
"Get the name of the user which 'owns' the item"
@ -36,13 +34,10 @@ class OrderItem(db.Model):
return self.name
def __repr__(self) -> str:
product_name = None
if self.product:
product_name = self.product.name
return "Order %d: %s wants %s" % (
self.order_id or 0,
self.get_name(),
product_name or "None",
self.dish_name or "None",
)
# pylint: disable=W0613