Use order.is_closed()
This commit is contained in:
parent
aa63023383
commit
0e779e59b9
3 changed files with 5 additions and 6 deletions
|
@ -70,7 +70,7 @@ class Order(db.Model):
|
||||||
return group
|
return group
|
||||||
|
|
||||||
def is_closed(self) -> bool:
|
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:
|
def can_close(self, user_id: int) -> bool:
|
||||||
"Check if a user can close the Order"
|
"Check if a user can close the Order"
|
||||||
|
|
|
@ -63,7 +63,7 @@ class OrderItem(db.Model):
|
||||||
"Check if a user can delete an item"
|
"Check if a user can delete an item"
|
||||||
if int(self.order_id) != int(order_id):
|
if int(self.order_id) != int(order_id):
|
||||||
return False
|
return False
|
||||||
if self.order.stoptime and self.order.stoptime < datetime.now():
|
if self.order.is_closed():
|
||||||
return False
|
return False
|
||||||
if self.user is not None and self.user_id == user_id:
|
if self.user is not None and self.user_id == user_id:
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -58,7 +58,7 @@ def order_from_id(order_id: int, form: OrderForm = None) -> str:
|
||||||
form = AnonOrderItemForm() if current_user.is_anonymous() \
|
form = AnonOrderItemForm() if current_user.is_anonymous() \
|
||||||
else OrderItemForm()
|
else OrderItemForm()
|
||||||
form.populate(order.location)
|
form.populate(order.location)
|
||||||
if order.stoptime and order.stoptime < datetime.now():
|
if order.is_closed():
|
||||||
form = None
|
form = None
|
||||||
total_price = sum([o.price for o in order.items])
|
total_price = sum([o.price for o in order.items])
|
||||||
debts = sum([o.price for o in order.items if not o.paid])
|
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()
|
current_order = Order.query.filter(Order.id == order_id).first()
|
||||||
if current_order is None:
|
if current_order is None:
|
||||||
abort(404)
|
abort(404)
|
||||||
if current_order.stoptime and current_order.stoptime < datetime.now():
|
if current_order.is_closed():
|
||||||
abort(404)
|
abort(404)
|
||||||
if current_user.is_anonymous() and not current_order.public:
|
if current_user.is_anonymous() and not current_order.public:
|
||||||
flash("Please login to see this order.", "info")
|
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()
|
order = Order.query.filter(Order.id == order_id).first()
|
||||||
if order is None:
|
if order is None:
|
||||||
abort(404)
|
abort(404)
|
||||||
if (current_user.id == order.courier_id or current_user.is_admin()) and (
|
if (current_user.id == order.courier_id or current_user.is_admin()) and not order.is_closed():
|
||||||
order.stoptime is None or (order.stoptime > datetime.now())):
|
|
||||||
order.stoptime = datetime.now()
|
order.stoptime = datetime.now()
|
||||||
if order.courier_id == 0 or order.courier_id is None:
|
if order.courier_id == 0 or order.courier_id is None:
|
||||||
courier = select_user(order.items)
|
courier = select_user(order.items)
|
||||||
|
|
Loading…
Reference in a new issue