This is a Django Vendor Management System designed to handle vendor profiles, track purchase orders, and calculate vendor performance metrics using Django and Django REST Framework.
These instructions will guide you through setting up the project on your local machine for development and testing purposes.
Ensure you have Python and pip installed on your system. You will also need the following packages:
- Django
- Django REST Framework
- djangorestframework-simplejwt for JWT-based authentication
- NumPy
Follow these steps to get your development environment running:
-
Clone the repository To start, clone the repository to your local machine and navigate into the project directory:
git clone https://github.com/yourusername/django-vendor-management.git cd django-vendor-management
-
Set up a virtual environment Next, set up a Python virtual environment by running:
- For Unix-based systems:
python -m venv venv source venv/bin/activate
- For Windows:
python -m venv venv venv\Scripts\activate
- Install the required packages Install Django, Django REST Framework, SimpleJWT, and NumPy using pip:
pip install django djangorestframework djangorestframework-simplejwt numpy
- Apply migrations Initialize your database schema by applying migrations:
python manage.py migrate
- Create an admin user Create a superuser for the Django admin interface:
python manage.py createsuperuser
- Run the development server Start the development server to make the application accessible on your local machine:
python manage.py runserver
Access the server at http://127.0.0.1:8000/
Before interacting with the secured routes, users must authenticate and obtain an access token. This system uses JWT (JSON Web Tokens) for authentication.
-
Obtain Access Token
- POST
/api/token/
: Pass your username and password to receive an access and refresh token. - Request Body:
{ "username": "your_username", "password": "your_password" }
- Response:
{ "refresh": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoi...", "access": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoi..." }
- POST
-
Refresh Access Token
- POST
/api/token/refresh/
: Submit your refresh token to renew your access token. - Request Body:
{ "refresh": "your_refresh_token" }
- Response:
{ "access": "new_access_token" }
- POST
Include the access token in the Authorization header of your requests to access the secured API endpoints. After obtaining your access token, use it as a Bearer token to authenticate requests to the secured API endpoints. Include the access token in the Authorization header of your HTTP requests as follows:
- Authorization Header
Authorization: Bearer your_access_token_here
Example:
Stores essential information about each vendor along with performance metrics.
- name:
CharField
- Vendor's name. - contact_details:
TextField
- Contact information of the vendor. - address:
TextField
- Physical address of the vendor. - vendor_code:
CharField
- Unique identifier for the vendor. - on_time_delivery_rate:
FloatField
- Tracks the percentage of on-time deliveries. - quality_rating_avg:
FloatField
- Average rating of quality based on purchase orders. - average_response_time:
FloatField
- Average time taken to acknowledge purchase orders. - fulfillment_rate:
FloatField
- Percentage of purchase orders fulfilled successfully.
Captures details of each purchase order and used for calculating performance metrics.
- po_number:
CharField
- Unique number identifying the PO. - vendor:
ForeignKey
- Link to the Vendor model. - order_date:
DateTimeField
- Date when the order was placed. - delivery_date:
DateTimeField
- Expected or actual delivery date of the order. - items:
JSONField
- Details of items ordered. - quantity:
IntegerField
- Total quantity of items in the PO. - status:
CharField
- Current status of the PO (e.g., pending, completed, canceled). - quality_rating:
FloatField
- Rating given to the vendor for this PO (nullable). - issue_date:
DateTimeField
- Timestamp when the PO was issued to the vendor. - acknowledgment_date:
DateTimeField
, nullable - Timestamp when the vendor acknowledged the PO.
Optionally stores historical data on vendor performance for trend analysis.
- vendor:
ForeignKey
- Link to the Vendor model. - date:
DateTimeField
- Date of the performance record. - on_time_delivery_rate:
FloatField
- Historical record of the on-time delivery rate. - quality_rating_avg:
FloatField
- Historical record of the quality rating average. - average_response_time:
FloatField
- Historical record of the average response time. - fulfillment_rate:
FloatField
- Historical record of the fulfillment rate.
- On-Time Delivery Rate: Calculated each time a PO status changes to 'completed'. Logic: Count the number of completed POs delivered on or before the delivery_date and divide by the total number of completed POs for that vendor.
- Quality Rating Average: Updated upon the completion of each PO where a quality_rating is provided. Logic: Calculate the average of all quality_rating values for completed POs of the vendor.
- Average Response Time: Calculated each time a PO is acknowledged by the vendor. Logic: Compute the time difference between issue_date and acknowledgment_date for each PO, then find the average of these times for all POs of the vendor.
- Fulfilment Rate: Calculated upon any change in PO status. Logic: Divide the number of successfully fulfilled POs (status 'completed' without issues) by the total number of POs issued to the vendor.
- POST
/api/vendors/
: Create a new vendor. - GET
/api/vendors/
: List all vendors. - GET
/api/vendors/{vendor_id}/
: Retrieve specific vendor details. - PUT
/api/vendors/{vendor_id}/
: Update a vendor's details. - DELETE
/api/vendors/{vendor_id}/
: Delete a vendor.
- POST
/api/purchase_orders/
: Create a purchase order. - GET
/api/purchase_orders/
: List all purchase orders with an option to filter by vendor. - GET
/api/purchase_orders/{po_id}/
: Retrieve details of a specific purchase order. - PUT
/api/purchase_orders/{po_id}/
: Update a purchase order. - DELETE
/api/purchase_orders/{po_id}/
: Delete a purchase order.
- GET
/api/vendors/{vendor_id}/performance
: Retrieve a vendor's performance metrics.