Use order.is_closed()

This commit is contained in:
Midgard 2020-01-27 03:52:29 +01:00
parent aa63023383
commit 0e779e59b9
Signed by: midgard
GPG key ID: 511C112F1331BBB4
3 changed files with 5 additions and 6 deletions

View file

@ -70,7 +70,7 @@ class Order(db.Model):
return group
def is_closed(self) -> bool:
return datetime.now() > self.stoptime
return self.stoptime and datetime.now() > self.stoptime
def can_close(self, user_id: int) -> bool:
"Check if a user can close the Order"

View file

@ -63,7 +63,7 @@ class OrderItem(db.Model):
"Check if a user can delete an item"
if int(self.order_id) != int(order_id):
return False
if self.order.stoptime and self.order.stoptime < datetime.now():
if self.order.is_closed():
return False
if self.user is not None and self.user_id == user_id:
return True

View file

@ -58,7 +58,7 @@ def order_from_id(order_id: int, form: OrderForm = None) -> str:
form = AnonOrderItemForm() if current_user.is_anonymous() \
else OrderItemForm()
form.populate(order.location)
if order.stoptime and order.stoptime < datetime.now():
if order.is_closed():
form = None
total_price = sum([o.price for o in order.items])
debts = sum([o.price for o in order.items if not o.paid])
@ -108,7 +108,7 @@ def order_item_create(order_id: int) -> typing.Any:
current_order = Order.query.filter(Order.id == order_id).first()
if current_order is None:
abort(404)
if current_order.stoptime and current_order.stoptime < datetime.now():
if current_order.is_closed():
abort(404)
if current_user.is_anonymous() and not current_order.public:
flash("Please login to see this order.", "info")
@ -219,8 +219,7 @@ def close_order(order_id: int) -> typing.Optional[Response]:
order = Order.query.filter(Order.id == order_id).first()
if order is None:
abort(404)
if (current_user.id == order.courier_id or current_user.is_admin()) and (
order.stoptime is None or (order.stoptime > datetime.now())):
if (current_user.id == order.courier_id or current_user.is_admin()) and not order.is_closed():
order.stoptime = datetime.now()
if order.courier_id == 0 or order.courier_id is None:
courier = select_user(order.items)