Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(case): Refactor case cost model. #5529

Merged
merged 10 commits into from
Dec 18, 2024
2 changes: 1 addition & 1 deletion src/dispatch/case/type/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def update(*, db_session, case_type: CaseType, case_type_in: CaseTypeUpdate) ->
# Calculate the cost of all non-closed cases associated with this case type
cases = case_service.get_all_open_by_case_type(db_session=db_session, case_type_id=case_type.id)
for case in cases:
case_cost_service.calculate_case_response_cost(case_id=case.id, db_session=db_session)
case_cost_service.calculate_case_response_cost(case=case, db_session=db_session)

if case_type_in.case_template_document:
case_template_document = document_service.get(
Expand Down
3 changes: 3 additions & 0 deletions src/dispatch/case_cost/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import datetime

from sqlalchemy import Column, ForeignKey, Integer, Numeric
from sqlalchemy.ext.associationproxy import association_proxy
from sqlalchemy.orm import relationship
Expand Down Expand Up @@ -40,6 +42,7 @@ class CaseCostUpdate(CaseCostBase):
class CaseCostRead(CaseCostBase):
id: PrimaryKey
case_cost_type: CaseCostTypeRead
updated_at: Optional[datetime] = None


class CaseCostPagination(Pagination):
Expand Down
4 changes: 3 additions & 1 deletion src/dispatch/case_cost/scheduled.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from .service import (
calculate_case_response_cost,
update_case_response_cost,
get_or_create_default_case_response_cost,
)

Expand Down Expand Up @@ -56,7 +57,8 @@ def calculate_cases_response_cost(db_session: Session, project: Project):
continue

# we calculate the response cost amount
amount = calculate_case_response_cost(case.id, db_session)
update_case_response_cost(case, db_session)
amount = calculate_case_response_cost(case, db_session)
# we don't need to update the cost amount if it hasn't changed
if case_response_cost.amount == amount:
continue
Expand Down
Loading
Loading