Browse Source

update timestamp only when update temporary_weight in space weight table

chenhaiyang 4 years ago
parent
commit
21775d0e89
1 changed files with 2 additions and 1 deletions
  1. 2 1
      app/crud/space/weight.py

+ 2 - 1
app/crud/space/weight.py

@@ -32,12 +32,13 @@ def create_weight(db: Session, weight: SpaceWeightCreate) -> VAVRoomWeight:
 
 
 def update_weight(db: Session, db_weight: VAVRoomWeight, weight_in: SpaceWeightUpdate) -> VAVRoomWeight:
-    db_weight.temporary_weight_update_time = get_time_str()
     weight_data = jsonable_encoder(db_weight)
     update_data = weight_in.dict(exclude_unset=True)
     for field in weight_data:
         if field in update_data:
             setattr(db_weight, field, update_data[field])
+            if field == 'temporary_weight':
+                db_weight.temporary_weight_update_time = get_time_str()
     db.add(db_weight)
     db.commit()
     db.refresh(db_weight)