small fixes

This commit is contained in:
2024-11-20 18:00:52 -05:00
parent b9a5667a3b
commit b70ea0b6a0
4 changed files with 130 additions and 23 deletions

View File

@@ -10,6 +10,8 @@ from app.models.delivery import Delivery
from app.models.money import MoneyDelivery
from app.models.pricing import Pricing_Oil_Oil
from app.models.promo import Promo_Promo
from app.models.auto import Tickets_Auto_Delivery
router = APIRouter(
@@ -107,6 +109,7 @@ async def calculate_delivery_final(delivery_id_order):
total_discount_total=discount,
total_profit_oil=profit_from_oil,
total_profit=profit_from_stop,
auto=False
)
session.add(new_money)
@@ -114,4 +117,65 @@ async def calculate_delivery_final(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}