Skip to content

Commit

Permalink
fix: sat delivery total_amount validation
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoBurgos committed May 3, 2024
1 parent 1c1be5e commit f4017cc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/orders/order_modules/models/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions src/orders/order_modules/utils/delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down

0 comments on commit f4017cc

Please sign in to comment.