From b34f1faca0e10fbabd00a01b07af6909391dbf37 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Tue, 17 Sep 2024 16:28:07 +0100 Subject: [PATCH] adding new costs to backend --- etl/costs/app.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/etl/costs/app.py b/etl/costs/app.py index 59852cc5..85c2410e 100644 --- a/etl/costs/app.py +++ b/etl/costs/app.py @@ -11,7 +11,7 @@ import inspect src_file_path = inspect.getfile(lambda: None) -DATA_DIRECTORY = Path(src_file_path).parent / "local_data" / "20240626 Hestia Materials.xlsx" +DATA_DIRECTORY = Path(src_file_path).parent / "local_data" / "20240917 Hestia Materials.xlsx" # Environment file is at the same level as this file ENV_FILE = Path(src_file_path).parent / "etl" / "costs" / ".env" dotenv.load_dotenv(ENV_FILE) @@ -46,6 +46,17 @@ def push_costs_to_db(engine, costs_df): session.commit() +def set_current_costs_inactive(engine): + """ + Set all current costs to inactive in the database. + + :param engine: The SQLAlchemy engine connected to your database. + """ + with Session(engine) as session: + session.query(Material).update({Material.is_active: False}) + session.commit() + + def app(): """ This application uploads the cost data to our database @@ -108,6 +119,11 @@ def app(): costs[col] = costs[col].fillna(0) # Push the costs to the database + # Since this is just uploading all of the new costs to the database, we make all of the current costs inactive + print("Setting all current costs to inactive") + set_current_costs_inactive(db_engine) + + print("Pushing costs to db") push_costs_to_db(db_engine, costs)