From f4017cc3ab3d8de4747c354984d406e24b599ec8 Mon Sep 17 00:00:00 2001 From: Marco Burgos Date: Fri, 3 May 2024 15:08:55 -0500 Subject: [PATCH] fix: sat delivery total_amount validation --- src/orders/order_modules/models/order.py | 6 +++++- src/orders/order_modules/utils/delivery.py | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/orders/order_modules/models/order.py b/src/orders/order_modules/models/order.py index 9510c06..4e73006 100644 --- a/src/orders/order_modules/models/order.py +++ b/src/orders/order_modules/models/order.py @@ -45,19 +45,23 @@ class HIBerryOrder(DeliveryDateMixin): delivery_address: StrictStr phone_number: StrictStr cart_items: List[HIBerryProduct] + discount: StrictStr | None = None total_amount: confloat(ge=0.0) payment_method: StrictStr geolocation: Geolocation | None = None status: OrderStatus = OrderStatus.CREATED source: OrderSource = OrderSource.HIBERRYAPP notes: StrictStr | None = None - discount: StrictStr | None = None @validator("total_amount", pre=True, always=True) def calculate_total_amount(cls, value, values): calculated_total = sum( item.price * item.quantity for item in values.get("cart_items", []) ) + if values["discount"] and values["discount"] == "5": + calculated_total *= 0.95 + elif values["discount"] and values["discount"] == "10": + calculated_total *= 0.90 if value is not None and calculated_total != value: raise ValueError( diff --git a/src/orders/order_modules/utils/delivery.py b/src/orders/order_modules/utils/delivery.py index c8f54e3..2d47c04 100644 --- a/src/orders/order_modules/utils/delivery.py +++ b/src/orders/order_modules/utils/delivery.py @@ -180,6 +180,10 @@ def assign_driver_for_delivery( if driver_assigned == 0: return 0 + # Saturday is day 5, in sat only one schedule is running, so all sector are available + if day_of_week == 5: + return driver_assigned + west_sectors = [1, 2] east_sectors = [3, 4]