Shipment Tracking Program

  • Purpose: To Help businesses manage complexity within their orders/shipments. (elaborated in write-up)
  • Functionality: This program allows user to store and log shipments, view these shipments, update them, and delete them, as well as assign specified attributes such as date, cost and location. (elaborated further in write-up)

Update Procedure

  • The student developed procedure that I have used for my CPT writeup and video is the updateq procedure which is able to update elements within the shipment databse. It is located in the 7th code cell.
  • Please note that some procedures below are inspired by online material I found on the web. Some lines may be borrowed. However, the updateq procedure I use for my CPT project was developed by myself. In a # note above every code cell, I have identified what is self-developed and what is inspired.
from flask import Flask
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)

database = 'sqlite:///sqlite.db' 
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SQLALCHEMY_DATABASE_URI'] = database
app.config['SECRET_KEY'] = 'SECRET_KEY'
db = SQLAlchemy()

db.init_app(app)
import datetime 
from datetime import datetime
import json

from sqlalchemy.exc import IntegrityError
from werkzeug.security import generate_password_hash, check_password_hash

class Shipment_B(db.Model):
    __tablename__ = 'Shipment_business' 

    id = db.Column(db.Integer, primary_key=True)
    _Shipment = db.Column(db.String(255), unique=True, nullable=False)
    _Quantity = db.Column(db.String(255), unique=False, nullable=False)
    _Date = db.Column(db.String(255), unique=False, nullable=False)
    _Cost = db.Column(db.String(255), unique=False, nullable=False)
    _Location = db.Column(db.String(255), unique=False, nullable=False)
    _Status = db.Column(db.String, unique=False)

    def __init__(self, Shipment, Quantity, Date, Cost, Location, Status):
        self._Shipment = Shipment  
        self._Quantity = Quantity
        self._Date = Date
        self._Cost = Cost
        self._Location = Location
        self._Status = Status

    @property
    def Shipment(self):
        return self._Shipment
    
    @Shipment.setter
    def Shipment(self, Shipment):
        self._Shipment = Shipment
    
    @property
    def Quantity(self):
        return self._Quantity
    
    @Quantity.setter
    def Quantity(self, Quantity):
        self._Quantity = Quantity

    @property
    def Date(self):
        return self._Date
    
    @Date.setter
    def Date(self, Date):
        self._Date = Date

    @property
    def Cost(self):
        return self._Cost

    @Cost.setter
    def Cost(self, Cost):
        self._Cost = Cost

    @property
    def Location(self):
        return self._Location

    @Location.setter
    def Location(self, Location):
        self._Location = Location

    @property
    def Status(self):
        return self._Status
    
    @Status.setter
    def Status(self, Status):
        self._Status = Status
    
    def __str__(self):
        return json.dumps(self.read())

    def create(self):
        try:
            db.session.add(self)  
            db.session.commit()  
            return self
        except IntegrityError:
            db.session.remove()
            return None

    def read(self):
        return {
            "id": self.id,
            "Shipment" : self.Shipment,
            "Quantity" : self.Quantity,
            "Date" : self.Date,
            "Cost" : self.Cost,
            "Location": self.Location,
            "Status": self.Status
        }

    def update(self, Shipment, Quantity, Date, Cost, Location, Status):
        if len(Shipment) > 0:
            self.Shipment = Shipment
        if len(Quantity) > 0:
            self.Quantity = Quantity
        if len(Date) > 0:
            self.Date = Date
        if len(Cost) > 0:
            self.Cost = Cost
        if len(Location) > 0:
            self.Location = Location
        if len(Status) > 0:
            self.Status = Status
        db.session.add(self)
        db.session.commit()
        return self

    def delete(self):
        db.session.delete(self)
        db.session.commit()
        return None
# This program code is inspired from online resources; some parts may not be self-developed
def initShipment_business():
    with app.app_context():
        db.create_all()
        S1 = Shipment_B(Shipment='Microsoft Microchips', Quantity='500,000', Date='12/01/2021', Cost='$100,000', Location='Microsoft Headquarters', Status='Shipping')
        S2 = Shipment_B(Shipment='Orlando Fish Farm Salmon', Quantity='500', Date='09/03/2022', Cost='$20,000', Location='Orlando Pharmaceuticals', Status='Ordered')
        S3 = Shipment_B(Shipment='PVC Pipes', Quantity='2,000', Date='05/22/2023', Cost='$500', Location='ID Tech', Status='Recieved')
        S4 = Shipment_B(Shipment='Lipo Batteries 360 kWatts', Quantity='150', Date='10/05/2022', Cost='$225', Location='Riverhouse, Illinois', Status='Shipping')
        S5 = Shipment_B(Shipment='Plywood 4x16 in', Quantity='3,000', Date='05/03/2023', Cost='n/a', Location='Lowes Furniture', Status='n/a')
        S6 = Shipment_B(Shipment='CAS Texas Instrument', Quantity='400', Date='12/05/2021', Cost='$20,000', Location='Del Norte High School mathematics', Status='Recieved')
        S7 = Shipment_B(Shipment='Jabra Extendable Headphones', Quantity='2,500', Date='01/01/2021', Cost='$7,687.21', Location='Qualcomm Headquarters', Status='recieved')
        S8 = Shipment_B(Shipment='Apple Wireless AirPods', Quantity='1,500', Date='05/05/2025', Cost='$18,076.20', Location='LS Technology', Status='Ordered')
        S9 = Shipment_B(Shipment='Jordan 4s, custom fade', Quantity='4', Date='08/30/2005', Cost='$1,221', Location='Drip Nation Headquarters', Status='recieved')
        S10 = Shipment_B(Shipment='Tofi Powder', Quantity='250 mg', Date='09/09/2023', Cost='$200', Location='Tyler1 Fuelers', Status='recieved')
        S11 = Shipment_B(Shipment='No. 2 Pencil', Quantity='23,000', Date='05/25/2023', Cost='$1,500', Location='Del Norte High School', Status='ordered')
        S12 = Shipment_B(Shipment='Adidas Techs & Fleeces', Quantity='122', Date='06/26/2022', Cost='€15,000', Location='Jabari Smith Florence', Status='shipping')
        S13 = Shipment_B(Shipment='Forgiato Rims', Quantity='82', Date='11/12/2023', Cost='$2,540', Location='Box Headquarters', Status='shipping' )
        S14 = Shipment_B(Shipment='Insignia Mouse Pads', Quantity='19', Date='04/06/2023', Cost='$1,100.54', Location='Texas Institute of Technology', Status='shipping')
        S15 = Shipment_B(Shipment='Whole Market Produce', Quantity='1,450', Date='08/21/2021', Cost='$2,863.22', Location='Sprouts assorted locations', Status='recieved')
        Ship = [S1, S2, S3, S4, S5, S6, S7, S8, S9, S10, S11, S12, S13, S14, S15]
        for S in Ship:
            try:
                object = S.create()
                print(f"Added data for {object.Shipment}")
            except IntegrityError:
                print(f"Records exist, duplicate shipments, or error: {S.Shipment}") 

initShipment_business()
def find_by_Shipment(Shipment):
    with app.app_context():
        shipment_B = Shipment_B.query.filter_by(_Shipment=Shipment).first()
    return shipment_B
def create():
    Shipment = input("Name for Shipment:")
    Content = find_by_Shipment(Shipment)
    try:
        print("Found\n", Content.read())
        return
    except:
        pass
    
    Quantity = input("Enter the total # of products within shipment:")
    Date = input("Enter Date of Shipment:")
    Cost = input("Enter Shipment Costs:")
    Location = input("Enter Shipment Location:")
    Status = input("Enter Shipment Staus (oredred/shipping/recieved):")

    shipment_B = Shipment_B(Shipment=Shipment, 
                Quantity=Quantity, 
                Date=Date,
                Cost=Cost,
                Location=Location,
                Status=Status
                )
 
    with app.app_context():
        try:
            object = shipment_B.create()
            print("Created\n", object.read())
        except:  
            print("Unknown error uid {Shipment}")
        
create()
Created
 {'id': 31, 'Shipment': 'Dunder Mifflin Paper Packages', 'Quantity': '5,000', 'Date': '07/15/2018', 'Cost': '$1,000', 'Location': 'RT Cubicle Company', 'Status': 'Recieved'}
def read():
    with app.app_context():
        table = Shipment_B.query.all()
    json_ready = [shipment_B.read() for shipment_B in table] 
    return json_ready

read()
[{'id': 16,
  'Shipment': 'Microsoft Microchips',
  'Quantity': '500,000',
  'Date': '12/05/2021',
  'Cost': '$150,000',
  'Location': 'Microsoft Headquarters',
  'Status': 'Recieved'},
 {'id': 17,
  'Shipment': 'Orlando Fish Farm Salmon',
  'Quantity': '1000',
  'Date': '09/03/2021',
  'Cost': '$28,750',
  'Location': 'Orlando Pharmaceuticals',
  'Status': 'Shipping'},
 {'id': 18,
  'Shipment': 'PVC Pipes',
  'Quantity': '2,000',
  'Date': '05/22/2023',
  'Cost': '$500',
  'Location': 'ID Tech',
  'Status': 'Recieved'},
 {'id': 19,
  'Shipment': 'Lipo Batteries 360 kWatts',
  'Quantity': '150',
  'Date': '10/05/2022',
  'Cost': '$225',
  'Location': 'Riverhouse, Illinois',
  'Status': 'Shipping'},
 {'id': 20,
  'Shipment': 'Plywood 4x16 in',
  'Quantity': '3,000',
  'Date': '05/03/2023',
  'Cost': 'n/a',
  'Location': 'Lowes Furniture',
  'Status': 'n/a'},
 {'id': 21,
  'Shipment': 'CAS Texas Instrument',
  'Quantity': '400',
  'Date': '12/05/2021',
  'Cost': '$20,000',
  'Location': 'Del Norte High School mathematics',
  'Status': 'Recieved'},
 {'id': 22,
  'Shipment': 'Jabra Extendable Headphones',
  'Quantity': '2,500',
  'Date': '01/01/2021',
  'Cost': '$7,687.21',
  'Location': 'Qualcomm Headquarters',
  'Status': 'recieved'},
 {'id': 23,
  'Shipment': 'Apple Wireless AirPods',
  'Quantity': '1,500',
  'Date': '05/05/2025',
  'Cost': '$18,076.20',
  'Location': 'LS Technology',
  'Status': 'Ordered'},
 {'id': 24,
  'Shipment': 'Jordan 4s, custom fade',
  'Quantity': '4',
  'Date': '08/30/2005',
  'Cost': '$1,221',
  'Location': 'Drip Nation Headquarters',
  'Status': 'recieved'},
 {'id': 25,
  'Shipment': 'Tofi Powder',
  'Quantity': '250 mg',
  'Date': '09/09/2023',
  'Cost': '$200',
  'Location': 'Tyler1 Fuelers',
  'Status': 'recieved'},
 {'id': 26,
  'Shipment': 'No. 2 Pencil',
  'Quantity': '23,000',
  'Date': '05/25/2023',
  'Cost': '$1,500',
  'Location': 'Del Norte High School',
  'Status': 'ordered'},
 {'id': 27,
  'Shipment': 'Adidas Techs & Fleeces',
  'Quantity': '122',
  'Date': '06/26/2022',
  'Cost': '€15,000',
  'Location': 'Jabari Smith Florence',
  'Status': 'shipping'},
 {'id': 28,
  'Shipment': 'Forgiato Rims',
  'Quantity': '82',
  'Date': '11/12/2023',
  'Cost': '$2,540',
  'Location': 'Box Headquarters',
  'Status': 'shipping'},
 {'id': 29,
  'Shipment': 'Insignia Mouse Pads',
  'Quantity': '19',
  'Date': '04/06/2023',
  'Cost': '$1,100.54',
  'Location': 'Texas Institute of Technology',
  'Status': 'shipping'},
 {'id': 30,
  'Shipment': 'Whole Market Produce',
  'Quantity': '1,450',
  'Date': '08/21/2021',
  'Cost': '$2,863.22',
  'Location': 'Sprouts assorted locations',
  'Status': 'recieved'}]
def updateq():    
    Shipment = input("Enter the name of the Shipment to update: ")
    Content = find_by_Shipment(Shipment)

    Quantity = input("Enter the shipment's new quantity : ")
    Date = input("Enter the updated date : ")
    Cost = input("Enter the new cost: ")
    Location = input("Enter the new location: ")
    Status = input("Enter the new status: ")
    
    if Content is not None:
        with app.app_context():
            Content.update(Shipment=Shipment, Quantity=Quantity, Date=Date, Cost=Cost, Location=Location, Status=Status)
            print("Updated Shipment", Shipment)
    else:
        print("error")

updateq()
Updated Shipment Orlando Fish Farm Salmon
def delete():
    Shipment = input("Enter the Name of the Shipment you would like to Delete:")
    Content = find_by_Shipment(Shipment)
    try:
        pass
    except:
        Shipment = input("Try again, that was not a valid Shipment:")
    
    with app.app_context():
        try:
            object = Content.delete()
            print("Deleted\n", Content)
        except:  
            print("Unknown error uid {Shipment}")
delete()
Deleted
 {"id": 31, "Shipment": "Dunder Mifflin Paper Packages", "Quantity": "5,000", "Date": "07/15/2018", "Cost": "$1,000", "Location": "RT Cubicle Company", "Status": "Recieved"}
def shipmentmenu():
    selection = input("Enter an action --> add = add a new shipment, view = view a shipment, update = Update a shipment, delete = delete a shipment")
    if selection.lower() == "add":
        create()
    elif selection.lower() == "view":
        with app.app_context():
            table = Shipment_B.query.all()
        json_ready = [shipment_B.read() for shipment_B in table]
        return json_ready
    elif selection.lower() == "update":
        updateq()
    elif selection.lower() == "delete":
        delete()
    else:
        selection = input("Please enter a valid action --> add = add a new shipment, view = view a shipment, update = Update a shipment, delete = delete a shipment")

shipmentmenu()
[{'id': 16,
  'Shipment': 'Microsoft Microchips',
  'Quantity': '500,000',
  'Date': '12/01/2021',
  'Cost': '$100,000',
  'Location': 'Microsoft Headquarters',
  'Status': 'Shipping'},
 {'id': 17,
  'Shipment': 'Orlando Fish Farm Salmon',
  'Quantity': '500',
  'Date': '09/03/2022',
  'Cost': '$20,000',
  'Location': 'Orlando Pharmaceuticals',
  'Status': 'Ordered'},
 {'id': 18,
  'Shipment': 'PVC Pipes',
  'Quantity': '2,000',
  'Date': '05/22/2023',
  'Cost': '$500',
  'Location': 'ID Tech',
  'Status': 'Recieved'},
 {'id': 19,
  'Shipment': 'Lipo Batteries 360 kWatts',
  'Quantity': '150',
  'Date': '10/05/2022',
  'Cost': '$225',
  'Location': 'Riverhouse, Illinois',
  'Status': 'Shipping'},
 {'id': 20,
  'Shipment': 'Plywood 4x16 in',
  'Quantity': '3,000',
  'Date': '05/03/2023',
  'Cost': 'n/a',
  'Location': 'Lowes Furniture',
  'Status': 'n/a'},
 {'id': 21,
  'Shipment': 'CAS Texas Instrument',
  'Quantity': '400',
  'Date': '12/05/2021',
  'Cost': '$20,000',
  'Location': 'Del Norte High School mathematics',
  'Status': 'Recieved'},
 {'id': 22,
  'Shipment': 'Jabra Extendable Headphones',
  'Quantity': '2,500',
  'Date': '01/01/2021',
  'Cost': '$7,687.21',
  'Location': 'Qualcomm Headquarters',
  'Status': 'recieved'},
 {'id': 23,
  'Shipment': 'Apple Wireless AirPods',
  'Quantity': '1,500',
  'Date': '05/05/2025',
  'Cost': '$18,076.20',
  'Location': 'LS Technology',
  'Status': 'Ordered'},
 {'id': 24,
  'Shipment': 'Jordan 4s, custom fade',
  'Quantity': '4',
  'Date': '08/30/2005',
  'Cost': '$1,221',
  'Location': 'Drip Nation Headquarters',
  'Status': 'recieved'},
 {'id': 25,
  'Shipment': 'Tofi Powder',
  'Quantity': '250 mg',
  'Date': '09/09/2023',
  'Cost': '$200',
  'Location': 'Tyler1 Fuelers',
  'Status': 'recieved'},
 {'id': 26,
  'Shipment': 'No. 2 Pencil',
  'Quantity': '23,000',
  'Date': '05/25/2023',
  'Cost': '$1,500',
  'Location': 'Del Norte High School',
  'Status': 'ordered'},
 {'id': 27,
  'Shipment': 'Adidas Techs & Fleeces',
  'Quantity': '122',
  'Date': '06/26/2022',
  'Cost': '€15,000',
  'Location': 'Jabari Smith Florence',
  'Status': 'shipping'},
 {'id': 28,
  'Shipment': 'Forgiato Rims',
  'Quantity': '82',
  'Date': '11/12/2023',
  'Cost': '$2,540',
  'Location': 'Box Headquarters',
  'Status': 'shipping'},
 {'id': 29,
  'Shipment': 'Insignia Mouse Pads',
  'Quantity': '19',
  'Date': '04/06/2023',
  'Cost': '$1,100.54',
  'Location': 'Texas Institute of Technology',
  'Status': 'shipping'},
 {'id': 30,
  'Shipment': 'Whole Market Produce',
  'Quantity': '1,450',
  'Date': '08/21/2021',
  'Cost': '$2,863.22',
  'Location': 'Sprouts assorted locations',
  'Status': 'recieved'}]