updated dynamic auto

This commit is contained in:
2024-07-17 18:05:11 -04:00
parent 12d973d785
commit ebeecccd63

View File

@@ -271,6 +271,18 @@ def customer_automatic_assignment(customer_id):
.query(Auto_Delivery) .query(Auto_Delivery)
.filter(Auto_Delivery.customer_id == customer_id) .filter(Auto_Delivery.customer_id == customer_id)
.first()) .first())
if get_customer.customer_automatic == 1:
# customer becomes will call
get_customer.customer_automatic = 0
db.session.add(get_customer)
if get_auto is not None:
db.session.delete(get_auto)
status = 0
else:
# customer becames an automatic
if get_auto is None: if get_auto is None:
create_auto = Auto_Delivery(customer_id = customer_id, create_auto = Auto_Delivery(customer_id = customer_id,
customer_full_name =get_customer.customer_first_name + ' ' + get_customer.customer_last_name, customer_full_name =get_customer.customer_first_name + ' ' + get_customer.customer_last_name,
@@ -278,25 +290,22 @@ def customer_automatic_assignment(customer_id):
customer_town=get_customer.customer_town, customer_town=get_customer.customer_town,
customer_state=get_customer.customer_state, customer_state=get_customer.customer_state,
customer_zip=get_customer.customer_zip, customer_zip=get_customer.customer_zip,
customer_address=get_customer.customer_address,
last_fill = datetime.utcnow(), last_fill = datetime.utcnow(),
last_updated = None, last_updated = None,
estimated_gallons_left = 0, estimated_gallons_left = 0,
estimated_gallons_left_prev_day = None, estimated_gallons_left_prev_day = 0,
tank_height = None, tank_height = 0,
tank_size =None, tank_size =275,
house_factor = 1, house_factor = 1,
) )
db.session.add(create_auto) db.session.add(create_auto)
if get_customer.customer_automatic == 1:
get_customer.customer_automatic = 0
status = 0
db.session.add(get_customer)
else:
get_customer.customer_automatic = 1 get_customer.customer_automatic = 1
status = 1
db.session.add(get_customer) db.session.add(get_customer)
status = 1
db.session.commit() db.session.commit()
return jsonify({ return jsonify({