Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions App/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from .user import *
from .auth import *
from .owner import *
from .driver import *
from .customer import *
from .request_item import *
Expand All @@ -12,6 +11,5 @@
from .transaction import *
from .status import *
from .region import *
from .route_area import *
from .route_history import *
from .initialize import *
1 change: 0 additions & 1 deletion App/controllers/auth.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from flask_jwt_extended import (
create_access_token,
jwt_required,
JWTManager,
get_jwt_identity,
verify_jwt_in_request,
Expand Down
8 changes: 8 additions & 0 deletions App/controllers/customer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from App.controllers.region import get_region_by_id
from App.database import db
from App.models import Customer

Expand All @@ -14,6 +15,13 @@ def get_customers_by_region(region_id):
db.select(Customer).filter_by(region_id=region_id)
).all()

def get_customer_region(customer_id):
customer = get_customer_by_id(customer_id)

if customer:
return get_region_by_id(customer.region_id)
else:
return None

def update_customer_info(customer_id, name=None, address=None, phone=None, region_id=None):
"""
Expand Down
27 changes: 0 additions & 27 deletions App/controllers/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,33 +49,6 @@ def unassign_driver_from_route(driver_id, route_id):
db.session.commit()
return True


def assign_van_to_driver(van_id, driver_id):
"""
Set a driver as the current driver of a van.
Also updates Van.current_driver_id via the Van model helper.
Returns the updated Van, or None if either record is not found.
"""
van = db.session.get(Van, van_id)
driver = db.session.get(Driver, driver_id)
if not van or not driver:
return None
van.assign_driver(driver_id)
db.session.commit()
return van


def unassign_van_from_driver(van_id):
"""
Remove the driver assignment from a van.
"""
van = db.session.get(Van, van_id)
if not van:
return None
van.unassign_driver()
db.session.commit()
return van

def update_driver_info(driver_id, name=None, address=None, phone=None, owner_id=None):
"""
Partially update a driver's profile fields.
Expand Down
6 changes: 3 additions & 3 deletions App/controllers/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def initialize():
add_stop_to_route(
route_id=route_east.route_id, owner_id=owner.owner_id,
address="Bakery depot, St. Augustine",
lat=10.640908716845667, lng=-61.39593945274354, stop_order=1,
lat=10.640908716845667, lng=-61.39593945274354, stop_order=0,
)
stop_e1 = add_customer_stop_to_route(
route_id=route_east.route_id, customer_id=customer2.customer_id,
Expand All @@ -221,7 +221,7 @@ def initialize():
add_stop_to_route(
route_id=route_central.route_id, owner_id=owner.owner_id,
address="Bakery depot, Chaguanas",
lat=10.5167, lng=-61.4114, stop_order=1,
lat=10.5167, lng=-61.4114, stop_order=0,
)
stop_c1 = add_customer_stop_to_route(
route_id=route_central.route_id, customer_id=customer.customer_id,
Expand All @@ -240,7 +240,7 @@ def initialize():
add_stop_to_route(
route_id=route_south.route_id, owner_id=owner.owner_id,
address="Bakery depot, San Fernando",
lat=10.2796, lng=-61.4589, stop_order=1,
lat=10.2796, lng=-61.4589, stop_order=0,
)
stop_s1 = add_customer_stop_to_route(
route_id=route_south.route_id, customer_id=customer4.customer_id,
Expand Down
59 changes: 0 additions & 59 deletions App/controllers/owner.py

This file was deleted.

4 changes: 0 additions & 4 deletions App/controllers/region.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ def get_region_by_name(name):
db.select(Region).filter_by(name=name)
).scalar_one_or_none()


def get_all_regions():
return db.session.scalars(db.select(Region)).all()

# ── Create / update / delete ───────────────────────────────────────────────────

def create_region(name, description=None):
Expand Down
2 changes: 1 addition & 1 deletion App/controllers/request_item.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from App.database import db
from App.models import RequestItem
from App.controllers.van import reserve_inventory, get_active_van
from App.controllers.van import reserve_inventory

def get_request_by_id(request_id):
return db.session.execute(
Expand Down
8 changes: 6 additions & 2 deletions App/controllers/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from App.models import Route, RouteStop, RouteArea, DriverRoute
from App.controllers.region import get_region_by_id
from App.controllers.customer import get_customer_by_id
from App.controllers.route_area import get_routes_for_region
from sqlalchemy import func
from datetime import datetime

Expand All @@ -18,13 +17,18 @@ def get_todays_route():
)
).scalar_one_or_none()

def get_routes_for_region(region_id):
return db.session.execute(
db.select(RouteArea).filter_by(region_id=region_id)
).scalars().all()

def get_customer_route_id(customer_id):
customer = get_customer_by_id(customer_id)
route_assignments = get_routes_for_region(customer.region_id)
route_id = None

if route_assignments is None:
return None
return None, None

for route in route_assignments:
route = get_route_by_id(route.route_id)
Expand Down
29 changes: 0 additions & 29 deletions App/controllers/route_area.py

This file was deleted.

5 changes: 0 additions & 5 deletions App/controllers/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ def get_status_by_name(status_name):
db.select(Status).filter_by(status_name=status_name)
).scalar_one_or_none()


def get_all_statuses():
return db.session.scalars(db.select(Status)).all()


def create_status(status_name, description=None):
existing = get_status_by_name(status_name)
if existing:
Expand Down
43 changes: 8 additions & 35 deletions App/controllers/van.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from App.database import db
from App.models import Van, DailyInventory
from App.controllers.route import get_customer_route_id, get_driver_id_for_route
from datetime import date, datetime
from datetime import date

def get_van_by_id(van_id):
return db.session.get(Van, van_id)
Expand Down Expand Up @@ -36,10 +36,6 @@ def get_active_van_plate():

return van.license_plate

def get_all_vans():
return db.session.scalars(db.select(Van)).all()


def create_van(license_plate, owner_id, current_route_id=None, status="inactive"):
van = Van(license_plate=license_plate, owner_id=owner_id,
current_route_id=current_route_id, status=status)
Expand Down Expand Up @@ -136,11 +132,7 @@ def set_van_inventory(van_id, item_id, quantity, date):
db.session.commit()

return True
def reserve_inventory(van_id, item_id, quantity, target_date=None):
"""
Reserve `quantity` units for a customer request.
Returns the updated DailyInventory or None if insufficient stock.
"""
def reserve_inventory(van_id, item_id, quantity,is_complete = False ,target_date=None):
target_date = target_date or date.today()
record = db.session.execute(
db.select(DailyInventory).filter_by(
Expand All @@ -152,38 +144,19 @@ def reserve_inventory(van_id, item_id, quantity, target_date=None):
return None

try:
record.quantity_reserved += quantity
record.quantity_available -= quantity
except:
db.session.rollback()
return None

db.session.commit()
return record

def update_stock(van_id, item_id, quantity,target_date =None):
target_date = target_date or date.today()

record = db.session.execute(
db.select(DailyInventory).filter_by(
van_id=van_id, item_id=item_id, date=target_date
)
).scalar_one_or_none()

if not record:
return None

try:
record.quantity_in_stock -= quantity
record.quantity_available -= quantity
if is_complete:
record.quantity_available -= quantity
record.quantity_in_stock -= quantity
else:
record.quantity_reserved += quantity
record.quantity_available -= quantity
except:
db.session.rollback()
return None

db.session.commit()
return record

#New - Set inven

def get_route_daily_inventory(route_id: int, target_date: date) -> list[dict]:
"""
Expand Down
Loading
Loading