Skip to content

Feature/assign shipment#32

Merged
Ke-vin-S merged 9 commits into
mainfrom
feature/assign_shipment
May 8, 2025
Merged

Feature/assign shipment#32
Ke-vin-S merged 9 commits into
mainfrom
feature/assign_shipment

Conversation

@Ke-vin-S

@Ke-vin-S Ke-vin-S commented May 8, 2025

Copy link
Copy Markdown
Contributor

No description provided.

@Ke-vin-S Ke-vin-S marked this pull request as ready for review May 8, 2025 14:48
Copilot AI review requested due to automatic review settings May 8, 2025 14:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements the "assign shipment" feature by extending vehicle functionality and creating a new assignment planning system that integrates shipments with vehicles. Key changes include:

  • Updates to vehicle API and model tests with enhanced filtering and location update assertions.
  • Addition of depot fields to the Vehicle model along with corresponding migrations and admin UI adjustments.
  • Implementation of new assignment models, services, and views for planning and managing shipment assignments.

Reviewed Changes

Copilot reviewed 33 out of 33 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
fleet/tests/test_vehicle_api.py Refactored integration tests for vehicle API endpoints with clearer naming and assertions
fleet/tests/test_vehicle.py Updated unit tests for vehicle model, including default field value assertions
fleet/serializers/vehicle.py Extended serializer fields to include depot-related attributes
fleet/models/core.py Added depot_id, depot_latitude, and depot_longitude fields to the Vehicle model
fleet/migrations/0004_vehicle_depot_id.py & 0005_vehicle... New migrations to support depot field additions
fleet/admin.py Modified admin configuration to include new depot fields
assignment/views.py Updated AssignmentViewSet to integrate shipment validation and assignment creation
assignment/tests/test_assignment_planner.py Added tests for the new assignment planner functionality
assignment/services/mappers.py Introduced mapping from Vehicle model to VRP input format
assignment/services/assignment_planner.py New service to plan assignments using a VRP solver, mapping shipments to assignment items
assignment/serializers.py Updated imports for the assignment serializer
assignment/models/assignment_item.py & assignment/models/assignment.py New assignment models reflecting shipment items and assignment state
assignment/migrations/0001_initial.py Updated migration reflecting the new assignment schema and inclusion of assignment items

Comment thread fleet/tests/test_vehicle.py
Comment on lines +58 to +64
for i, route in enumerate(result["routes"]):
vehicle = self.vehicles[i]
logger.debug(f"Creating assignment for vehicle {vehicle.vehicle_id}, route: {route}")
assignment = Assignment.objects.create(
vehicle=vehicle,
total_load=sum(
vrp_input.demands[node] for node in route if vrp_input.demands[node] > 0

Copilot AI May 8, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Assuming that the order of routes from the VRP solver always matches the order of self.vehicles might be fragile. Consider adding a mapping mechanism to associate each route with the correct vehicle to improve robustness.

Suggested change
for i, route in enumerate(result["routes"]):
vehicle = self.vehicles[i]
logger.debug(f"Creating assignment for vehicle {vehicle.vehicle_id}, route: {route}")
assignment = Assignment.objects.create(
vehicle=vehicle,
total_load=sum(
vrp_input.demands[node] for node in route if vrp_input.demands[node] > 0
for route in result["routes"]:
vehicle_id = route["vehicle_id"] # Assuming each route includes a vehicle_id field
vehicle = vehicle_map.get(vehicle_id)
if not vehicle:
logger.error(f"Vehicle with ID {vehicle_id} not found in vehicle_map.")
raise Exception(f"Vehicle with ID {vehicle_id} not found.")
logger.debug(f"Creating assignment for vehicle {vehicle.vehicle_id}, route: {route['nodes']}")
assignment = Assignment.objects.create(
vehicle=vehicle,
total_load=sum(
vrp_input.demands[node] for node in route["nodes"] if vrp_input.demands[node] > 0

Copilot uses AI. Check for mistakes.
@Ke-vin-S Ke-vin-S merged commit 6c726d3 into main May 8, 2025
1 check passed
@Ke-vin-S Ke-vin-S deleted the feature/assign_shipment branch May 8, 2025 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants