small fixes
This commit is contained in:
25
app/models/admin.py
Normal file
25
app/models/admin.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
from sqlalchemy import (Column, Integer,
|
||||||
|
DECIMAL, TEXT,
|
||||||
|
VARCHAR, DATE, INTEGER)
|
||||||
|
from datetime import datetime
|
||||||
|
from database import Base
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Admin_Company(Base):
|
||||||
|
__tablename__ = 'admin_company'
|
||||||
|
__table_args__ = {"schema": "public"}
|
||||||
|
|
||||||
|
id = Column(Integer,
|
||||||
|
primary_key=True,
|
||||||
|
autoincrement=True,
|
||||||
|
unique=False)
|
||||||
|
creation_date = Column(DATE())
|
||||||
|
account_prefix = Column(VARCHAR(5))
|
||||||
|
company_name = Column(VARCHAR(250))
|
||||||
|
company_address = Column(VARCHAR(250))
|
||||||
|
company_town = Column(VARCHAR(100))
|
||||||
|
company_zip = Column(VARCHAR(25))
|
||||||
|
company_state = Column(INTEGER())
|
||||||
|
company_phone_number = Column(VARCHAR(50))
|
||||||
|
|
||||||
@@ -1,30 +1,21 @@
|
|||||||
from sqlalchemy import Column, Integer,\
|
from sqlalchemy import (Column, Integer,
|
||||||
DECIMAL, TEXT,\
|
DECIMAL, TEXT,
|
||||||
VARCHAR, TIMESTAMP, DATE, INTEGER
|
VARCHAR, DATE, INTEGER)
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from database import Base
|
from database import Base
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Auto_Customer(Base):
|
class Auto_Update(Base):
|
||||||
__tablename__ = 'auto_temp'
|
__tablename__ = 'auto_update'
|
||||||
|
|
||||||
id = Column(Integer,
|
id = Column(Integer,
|
||||||
primary_key=True,
|
primary_key=True,
|
||||||
autoincrement=True,
|
autoincrement=True,
|
||||||
unique=False)
|
unique=False)
|
||||||
customer_id = Column(INTEGER())
|
|
||||||
customer_full_name = Column(VARCHAR(250))
|
|
||||||
last_fill = Column(TIMESTAMP(), default=datetime.utcnow())
|
|
||||||
last_updated = Column(TIMESTAMP(), default=datetime.utcnow())
|
|
||||||
estimated_gallons_left = Column(INTEGER)
|
|
||||||
estimated_gallons_left_prev_day = Column(INTEGER)
|
|
||||||
tank_height = Column(VARCHAR(25))
|
|
||||||
tank_size = Column(VARCHAR(25))
|
|
||||||
house_factor = Column(DECIMAL(5, 2))
|
|
||||||
|
|
||||||
|
|
||||||
|
last_updated = Column(DATE())
|
||||||
|
|
||||||
|
|
||||||
class Auto_Temp(Base):
|
class Auto_Temp(Base):
|
||||||
@@ -35,7 +26,7 @@ class Auto_Temp(Base):
|
|||||||
autoincrement=True,
|
autoincrement=True,
|
||||||
unique=False)
|
unique=False)
|
||||||
|
|
||||||
todays_date = Column(TIMESTAMP(), default=datetime.utcnow())
|
todays_date = Column(DATE)
|
||||||
temp = Column(DECIMAL(5, 2))
|
temp = Column(DECIMAL(5, 2))
|
||||||
temp_max = Column(DECIMAL(5, 2))
|
temp_max = Column(DECIMAL(5, 2))
|
||||||
temp_min = Column(DECIMAL(5, 2))
|
temp_min = Column(DECIMAL(5, 2))
|
||||||
@@ -59,10 +50,36 @@ class Auto_Delivery(Base):
|
|||||||
customer_address = Column(VARCHAR(1000))
|
customer_address = Column(VARCHAR(1000))
|
||||||
customer_zip = Column(VARCHAR(25))
|
customer_zip = Column(VARCHAR(25))
|
||||||
customer_full_name = Column(VARCHAR(250))
|
customer_full_name = Column(VARCHAR(250))
|
||||||
last_fill = Column(TIMESTAMP())
|
last_fill = Column(DATE())
|
||||||
last_updated = Column(TIMESTAMP())
|
last_updated = Column(DATE())
|
||||||
estimated_gallons_left = Column(INTEGER())
|
estimated_gallons_left = Column(DECIMAL(6, 2))
|
||||||
estimated_gallons_left_prev_day = Column(INTEGER())
|
estimated_gallons_left_prev_day = Column(DECIMAL(6, 2))
|
||||||
tank_height = Column(VARCHAR(25))
|
tank_height = Column(VARCHAR(25))
|
||||||
tank_size = Column(VARCHAR(25))
|
tank_size = Column(VARCHAR(25))
|
||||||
house_factor = Column(DECIMAL(5, 2))
|
house_factor = Column(DECIMAL(5, 2))
|
||||||
|
auto_status = Column(INTEGER())
|
||||||
|
|
||||||
|
|
||||||
|
class Tickets_Auto_Delivery(Base):
|
||||||
|
__tablename__ = 'auto_tickets'
|
||||||
|
|
||||||
|
id = Column(Integer,
|
||||||
|
primary_key=True,
|
||||||
|
autoincrement=True,
|
||||||
|
unique=False)
|
||||||
|
customer_id = Column(INTEGER())
|
||||||
|
account_number = Column(VARCHAR(25))
|
||||||
|
|
||||||
|
customer_town = Column(VARCHAR(140))
|
||||||
|
customer_state = Column(Integer)
|
||||||
|
customer_address = Column(VARCHAR(1000))
|
||||||
|
customer_zip = Column(VARCHAR(25))
|
||||||
|
customer_full_name = Column(VARCHAR(250))
|
||||||
|
customer_zip = Column(VARCHAR(25))
|
||||||
|
|
||||||
|
oil_prices_id = Column(INTEGER())
|
||||||
|
|
||||||
|
gallons_delivered = Column(DECIMAL(6, 2))
|
||||||
|
price_per_gallon = Column(DECIMAL(6, 2))
|
||||||
|
|
||||||
|
total_amount_customer = Column(DECIMAL(6, 2))
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from sqlalchemy import Column, Integer,\
|
from sqlalchemy import Column, Integer,\
|
||||||
DECIMAL, TEXT,\
|
DECIMAL, TEXT,\
|
||||||
VARCHAR, TIMESTAMP, DATE
|
VARCHAR, BOOLEAN, DATE
|
||||||
from database import Base
|
from database import Base
|
||||||
|
|
||||||
|
|
||||||
@@ -26,4 +26,5 @@ class MoneyDelivery(Base):
|
|||||||
total_discount_total = Column(DECIMAL(6, 2))
|
total_discount_total = Column(DECIMAL(6, 2))
|
||||||
taxes_paid = Column(DECIMAL(6, 2))
|
taxes_paid = Column(DECIMAL(6, 2))
|
||||||
total_profit = Column(DECIMAL(6, 2))
|
total_profit = Column(DECIMAL(6, 2))
|
||||||
total_profit_oil = Column(DECIMAL(6, 2))
|
total_profit_oil = Column(DECIMAL(6, 2))
|
||||||
|
auto = Column(BOOLEAN)
|
||||||
@@ -10,6 +10,8 @@ from app.models.delivery import Delivery
|
|||||||
from app.models.money import MoneyDelivery
|
from app.models.money import MoneyDelivery
|
||||||
from app.models.pricing import Pricing_Oil_Oil
|
from app.models.pricing import Pricing_Oil_Oil
|
||||||
from app.models.promo import Promo_Promo
|
from app.models.promo import Promo_Promo
|
||||||
|
from app.models.auto import Tickets_Auto_Delivery
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
router = APIRouter(
|
router = APIRouter(
|
||||||
@@ -107,6 +109,7 @@ async def calculate_delivery_final(delivery_id_order):
|
|||||||
total_discount_total=discount,
|
total_discount_total=discount,
|
||||||
total_profit_oil=profit_from_oil,
|
total_profit_oil=profit_from_oil,
|
||||||
total_profit=profit_from_stop,
|
total_profit=profit_from_stop,
|
||||||
|
auto=False
|
||||||
)
|
)
|
||||||
|
|
||||||
session.add(new_money)
|
session.add(new_money)
|
||||||
@@ -114,4 +117,65 @@ async def calculate_delivery_final(delivery_id_order):
|
|||||||
|
|
||||||
|
|
||||||
return {"delivery_id": delivery_id_order}
|
return {"delivery_id": delivery_id_order}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/add/auto/{auto_ticket_id}", status_code=201)
|
||||||
|
async def calculate_delivery_auto_final(auto_ticket_id):
|
||||||
|
|
||||||
|
|
||||||
|
now = datetime.now(timezone.utc).replace(tzinfo=None)
|
||||||
|
auto_ticket_id = int(auto_ticket_id)
|
||||||
|
get_delivery = (session.query(Tickets_Auto_Delivery)
|
||||||
|
.filter(Tickets_Auto_Delivery.id == auto_ticket_id)
|
||||||
|
.first())
|
||||||
|
|
||||||
|
get_current_prices = (session.query(Pricing_Oil_Oil)
|
||||||
|
.order_by(Pricing_Oil_Oil.id.desc())
|
||||||
|
.first())
|
||||||
|
|
||||||
|
|
||||||
|
# get total amount for just oil delivered
|
||||||
|
calc_total_oil = (float(get_delivery.gallons_delivered) * float(get_current_prices.price_for_customer))
|
||||||
|
calc_total_oil_supplier = (float(get_delivery.gallons_delivered) * float(get_current_prices.price_from_supplier))
|
||||||
|
|
||||||
|
discount = 0
|
||||||
|
|
||||||
|
# total amount
|
||||||
|
total_amount_delivery =float(calc_total_oil)
|
||||||
|
|
||||||
|
|
||||||
|
# calculate profit
|
||||||
|
profit_from_oil = float(calc_total_oil) - float(calc_total_oil_supplier)
|
||||||
|
|
||||||
|
|
||||||
|
# add it all together
|
||||||
|
profit_from_stop = float(profit_from_oil)
|
||||||
|
|
||||||
|
|
||||||
|
new_money = MoneyDelivery(
|
||||||
|
delivery_id = get_delivery.id,
|
||||||
|
time_added=now,
|
||||||
|
gallons_delivered=get_delivery.gallons_delivered,
|
||||||
|
supplier_price=get_current_prices.price_from_supplier,
|
||||||
|
customer_price=get_current_prices.price_for_customer,
|
||||||
|
total_amount_oil=calc_total_oil,
|
||||||
|
total_amount_prime=0,
|
||||||
|
total_amount_same_day=0,
|
||||||
|
total_amount_fee= 0,
|
||||||
|
total_amount=total_amount_delivery,
|
||||||
|
taxes_paid=None,
|
||||||
|
total_discount_amount=0,
|
||||||
|
total_discount_total=discount,
|
||||||
|
total_profit_oil=profit_from_oil,
|
||||||
|
total_profit=profit_from_stop,
|
||||||
|
auto=True
|
||||||
|
)
|
||||||
|
|
||||||
|
session.add(new_money)
|
||||||
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
|
return {"delivery_id": auto_ticket_id}
|
||||||
|
|
||||||
Reference in New Issue
Block a user