From 94455b810c135194251ad9c5e1c1c28eff2f8fb1 Mon Sep 17 00:00:00 2001 From: diegocaspi <55052203+diegocaspi@users.noreply.github.com> Date: Sun, 23 Jun 2024 10:09:20 +0200 Subject: [PATCH] fix: minor fixes for demo Co-authored-by: Diego Caspi --- app/modules/carts/handlers.py | 1 - app/modules/orders/handlers.py | 1 - app/modules/products/models.py | 1 + app/templates/carts/macros/cart_list.html | 1 - app/templates/layouts/base.html | 18 +++--- app/templates/orders/buyer_order_info.html | 7 ++- .../orders/macros/buyer_orders_list.html | 1 - .../orders/macros/seller_orders_list.html | 1 - app/templates/products/index.html | 2 +- .../50d9a9739e0f_products_locked_stock.py | 2 - ...bde8be828c_product_history_locked_stock.py | 63 +++++++++++++++++++ 11 files changed, 79 insertions(+), 19 deletions(-) create mode 100644 migrations/versions/f2bde8be828c_product_history_locked_stock.py diff --git a/app/modules/carts/handlers.py b/app/modules/carts/handlers.py index 389fcfc..abae746 100644 --- a/app/modules/carts/handlers.py +++ b/app/modules/carts/handlers.py @@ -95,7 +95,6 @@ def update_cart(buyer_id: int, product: Product, quantity: int) -> (Cart | None, # if the product sequence is different from the reservation sequence, delete the reservation and return None, product if product.sequence != product_reservation.product_sequence: product_reservation.deleted_at = db.func.now() - # TODO should create a new reservation? db.session.commit() return None, product diff --git a/app/modules/orders/handlers.py b/app/modules/orders/handlers.py index 26e4b10..bccce0f 100644 --- a/app/modules/orders/handlers.py +++ b/app/modules/orders/handlers.py @@ -114,7 +114,6 @@ def create_buyer_order(cart: Cart) -> ( if invalid_reservations: for r in invalid_reservations: r.deleted_at = db.func.now() - # TODO: should create a new reservation? db.session.commit() return None, invalid_reservations, OrderCreationErrorReason.INVALID_PRODUCTS diff --git a/app/modules/products/models.py b/app/modules/products/models.py index 85fe850..2ffa9a8 100644 --- a/app/modules/products/models.py +++ b/app/modules/products/models.py @@ -88,6 +88,7 @@ class ProductHistory(db.Model): price: Mapped[float] = mapped_column("price", db.Float, nullable=False) currency: Mapped[str] = mapped_column("currency", db.String(3), nullable=False) stock: Mapped[int] = mapped_column("stock", db.Integer, nullable=False) + locked_stock: Mapped[int] = mapped_column("locked_stock", db.Integer, nullable=False, default=0) product = db.relationship("Product", back_populates="history") diff --git a/app/templates/carts/macros/cart_list.html b/app/templates/carts/macros/cart_list.html index 2189e8a..28f2be0 100644 --- a/app/templates/carts/macros/cart_list.html +++ b/app/templates/carts/macros/cart_list.html @@ -45,7 +45,6 @@

{{ reservation.pr {{ reservation_editor(reservation) }} - {# TODO needs to be warned if product is invalid: is the stock is 0, is the sequence changed etc. #} {%- endmacro %} diff --git a/app/templates/layouts/base.html b/app/templates/layouts/base.html index b3bed8a..9ea0953 100644 --- a/app/templates/layouts/base.html +++ b/app/templates/layouts/base.html @@ -168,7 +168,7 @@ this.originalProfile = this.profile; this.profileEditMode = false; } else { - alert("Failed to update user"); // TODO find the will to do + alert("Failed to update user"); } } @@ -182,21 +182,21 @@ profileEditMode: false, editUser, profile: { - destination_address: "{{ current_user.buyers[0].destination_address }}", - card_number: "{{ current_user.buyers[0].card_number|string }}", + destination_address: {{ current_user.buyers[0].destination_address|tojson }}, + card_number: {{ current_user.buyers[0].card_number|tojson }}, {% if current_user.sellers %} - iban: "{{ current_user.sellers[0].iban }}", - show_soldout: "{{ current_user.sellers[0].show_soldout_products|string }}" === "True", + iban: {{ current_user.sellers[0].iban|tojson }}, + show_soldout: {{ current_user.sellers[0].show_soldout_products|tojson }}, {% endif %} }, originalProfile: { - destination_address: "{{ current_user.buyers[0].destination_address }}", - card_number: "{{ current_user.buyers[0].card_number }}", + destination_address: {{ current_user.buyers[0].destination_address|tojson }}, + card_number: {{ current_user.buyers[0].card_number|tojson }}, {% if current_user.sellers %} - iban: "{{ current_user.sellers[0].iban }}", - show_soldout: "{{ current_user.sellers[0].show_soldout_products|string }}" === "True", + iban: {{ current_user.sellers[0].iban|tojson }}, + show_soldout: {{ current_user.sellers[0].show_soldout_products|tojson }}, {% endif %} }, })); diff --git a/app/templates/orders/buyer_order_info.html b/app/templates/orders/buyer_order_info.html index 67c47c7..2bee6b0 100644 --- a/app/templates/orders/buyer_order_info.html +++ b/app/templates/orders/buyer_order_info.html @@ -75,10 +75,13 @@ - {% for reservation in order.cart.reservations %} + + {% for reservation in order.cart.reservations if reservation.deleted_at == None %} - {{ reservation.product.name }} + + {{ reservation.product.name }} + {{ reservation.product.seller.user.given_name }} {{ reservation.product.seller.user.family_name }} diff --git a/app/templates/orders/macros/buyer_orders_list.html b/app/templates/orders/macros/buyer_orders_list.html index 5459041..53df346 100644 --- a/app/templates/orders/macros/buyer_orders_list.html +++ b/app/templates/orders/macros/buyer_orders_list.html @@ -2,7 +2,6 @@ {% macro order_card(order, current_user) -%} {% set reservations = order.cart.reservations|selectattr('deleted_at', 'none')|list %} - {# TODO: account for currency differences between reservations #} {% set ns = namespace(total=0) %} {% for reservation in reservations %} {% set ns.total = ns.total + (reservation.quantity * reservation.product.price) %} diff --git a/app/templates/orders/macros/seller_orders_list.html b/app/templates/orders/macros/seller_orders_list.html index 3ce671a..893cf71 100644 --- a/app/templates/orders/macros/seller_orders_list.html +++ b/app/templates/orders/macros/seller_orders_list.html @@ -1,5 +1,4 @@ {% macro order_card(order, current_user) -%} - {# TODO: account for currency differences between reservations #} {% set ns = namespace(total=0) %} {% for product in order.ordered_products %} {% set ns.total = ns.total + (product.quantity * product.product.price) %} diff --git a/app/templates/products/index.html b/app/templates/products/index.html index dd4a2f9..8930c39 100644 --- a/app/templates/products/index.html +++ b/app/templates/products/index.html @@ -25,7 +25,7 @@ {% else %}
-
+
Your products