fixed bug
This commit is contained in:
52
app/script/update_auto.py
Normal file
52
app/script/update_auto.py
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
from decimal import Decimal
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from app.models.auto import Auto_Delivery
|
||||||
|
|
||||||
|
|
||||||
|
def update_automatic(get_delivery, gallons_delivered ):
|
||||||
|
|
||||||
|
now = datetime.utcnow()
|
||||||
|
|
||||||
|
|
||||||
|
get_auto_delivery = (db.session
|
||||||
|
.query(Auto_Delivery)
|
||||||
|
.filter(Auto_Delivery.customer_id == get_delivery.customer_id)
|
||||||
|
.first())
|
||||||
|
|
||||||
|
gallons_put_in_home = Decimal(gallons_delivered)
|
||||||
|
|
||||||
|
customer_home_factor = get_auto_delivery.house_factor
|
||||||
|
|
||||||
|
|
||||||
|
new_home_factor = calc_home_factor(gallons_put_in_home = gallons_put_in_home,
|
||||||
|
current_house_factor=customer_home_factor)
|
||||||
|
get_auto_delivery.house_factor = new_home_factor
|
||||||
|
get_auto_delivery.tank_height = 'Full'
|
||||||
|
get_auto_delivery.last_fill = now
|
||||||
|
get_auto_delivery.estimated_gallons_left = 240
|
||||||
|
get_auto_delivery.estimated_gallons_left_prev_day = 240
|
||||||
|
get_auto_delivery.auto_status = 0
|
||||||
|
|
||||||
|
db.session.add(get_auto_delivery)
|
||||||
|
|
||||||
|
|
||||||
|
def calc_home_factor(gallons_put_in_home, current_house_factor):
|
||||||
|
|
||||||
|
|
||||||
|
if 200.01 >= gallons_put_in_home >= 500:
|
||||||
|
customer_home_factor = Decimal(current_house_factor) + Decimal(1)
|
||||||
|
elif 170.01 <= gallons_put_in_home <= 200:
|
||||||
|
customer_home_factor = Decimal(current_house_factor) + Decimal(1.5)
|
||||||
|
elif 150.01 <= gallons_put_in_home <= 170:
|
||||||
|
customer_home_factor = Decimal(current_house_factor) + Decimal(1.25)
|
||||||
|
elif 120.01 <= gallons_put_in_home <= 150:
|
||||||
|
customer_home_factor = Decimal(current_house_factor) - Decimal(.25)
|
||||||
|
elif 90.01 <= gallons_put_in_home <= 120:
|
||||||
|
customer_home_factor = Decimal(current_house_factor) - Decimal(.50)
|
||||||
|
elif 0.01 <= gallons_put_in_home <= 90:
|
||||||
|
customer_home_factor = Decimal(current_house_factor) - Decimal(.75)
|
||||||
|
else:
|
||||||
|
customer_home_factor = Decimal(current_house_factor)
|
||||||
|
|
||||||
|
return customer_home_factor
|
||||||
Reference in New Issue
Block a user