mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
adding new costs to backend
This commit is contained in:
parent
53e68f8d76
commit
b34f1faca0
1 changed files with 17 additions and 1 deletions
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue