Skip to content

Commit

Permalink
[ADD] close_datetime for cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir-A committed Dec 7, 2024
1 parent 37f2eeb commit 9ef3550
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Add case close_datetime
Revision ID: 9e8744ca051b
Revises: 11aa5b725b8e
Create Date: 2024-11-18 16:03:05.620518
"""
from alembic import op
import sqlalchemy as sa

from app.alembic.alembic_utils import _table_has_column


# revision identifiers, used by Alembic.
revision = '9e8744ca051b'
down_revision = 'd5a720d1b99b'
branch_labels = None
depends_on = None


def upgrade():
op.execute('COMMIT')

if not _table_has_column('cases', 'close_datetime'):
op.add_column('cases',
sa.Column('close_datetime', sa.DateTime, default=False),
# insert_after requires alembic 1.10.0 or higher
#insert_after = 'initial_date'
)
return


def downgrade():
if _table_has_column('cases', 'close_datetime'):
op.drop_column('cases', 'close_datetime')
return
5 changes: 5 additions & 0 deletions source/app/datamgmt/manage/manage_cases_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def list_cases_dict(user_id):
Client.name.label('client_name'),
Cases.open_date.label('case_open_date'),
Cases.close_date.label('case_close_date'),
Cases.close_datetime.label('case_close_datetime'),
Cases.soc_id.label('case_soc_id'),
Cases.user_id.label('opened_by_user_id'),
user_alias.user.label('opened_by'),
Expand Down Expand Up @@ -182,6 +183,8 @@ def close_case(case_id):

if res:
res.close_date = datetime.utcnow()
res.close_datetime = datetime.utcnow()


res.state_id = get_case_state_by_name('Closed').state_id

Expand Down Expand Up @@ -223,6 +226,7 @@ def reopen_case(case_id):

if res:
res.close_date = None
res.close_datetime = None

res.state_id = get_case_state_by_name('Open').state_id

Expand Down Expand Up @@ -274,6 +278,7 @@ def get_case_details_rt(case_id):
Cases.custom_attributes,
Cases.modification_history,
Cases.initial_date,
Cases.close_datetime,
Cases.classification_id,
CaseClassification.name.label('classification'),
Cases.reviewer_id,
Expand Down
2 changes: 2 additions & 0 deletions source/app/models/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Cases(db.Model):
description = Column(Text)
open_date = Column(Date)
close_date = Column(Date)
close_datetime = Column(DateTime)
initial_date = Column(DateTime, nullable=False, server_default=text("now()"))
closing_note = Column(Text)
user_id = Column(ForeignKey('user.id'))
Expand Down Expand Up @@ -107,6 +108,7 @@ def __init__(self,
self.open_date = datetime.utcnow()
self.close_date = None
self.initial_date = datetime.utcnow()
self.close_datetime = None
self.custom_attributes = custom_attributes
self.case_uuid = uuid.uuid4()
self.status_id = 0
Expand Down
3 changes: 2 additions & 1 deletion source/app/schema/marshables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1540,14 +1540,15 @@ class CaseSchema(ma.SQLAlchemyAutoSchema):
protagonists: List[Dict[str, Any]] = fields.List(fields.Dict, required=False)
case_tags: Optional[str] = fields.String(required=False)
initial_date: Optional[datetime.datetime] = auto_field('initial_date', required=False)
close_datetime: Optional[datetime.datetime] = auto_field('close_datetime', required=False)
classification_id: Optional[int] = auto_field('classification_id', required=False, allow_none=True)
reviewer_id: Optional[int] = auto_field('reviewer_id', required=False, allow_none=True)

class Meta:
model = Cases
include_fk = True
load_instance = True
exclude = ['name', 'description', 'soc_id', 'client_id', 'initial_date']
exclude = ['name', 'description', 'soc_id', 'client_id', 'initial_date', 'close_datetime']
unknown = EXCLUDE

@pre_load
Expand Down

0 comments on commit 9ef3550

Please sign in to comment.