added fixes for bug plan 1.0.6RC01
Some checks failed
Chore App Build, Test, and Push Docker Images / build-and-push (push) Failing after 5m43s

This commit is contained in:
2026-03-24 15:31:57 -04:00
parent 81169da05e
commit e9f4343426
27 changed files with 890 additions and 65 deletions

View File

@@ -451,6 +451,7 @@ def trigger_child_task(id):
child_db.update({'points': child.points}, ChildQuery.id == id)
# For chores, create an approved PendingConfirmation so child view shows COMPLETED
# Only persist for scheduled chores; general chores reset to normal after trigger
if task.type == 'chore':
PendingQuery = Query()
# Remove any existing pending confirmation for this chore
@@ -458,12 +459,14 @@ def trigger_child_task(id):
(PendingQuery.child_id == id) & (PendingQuery.entity_id == task_id) &
(PendingQuery.entity_type == 'chore') & (PendingQuery.user_id == user_id)
)
confirmation = PendingConfirmation(
child_id=id, entity_id=task_id, entity_type='chore',
user_id=user_id, status='approved',
approved_at=datetime.now(timezone.utc).isoformat()
)
pending_confirmations_db.insert(confirmation.to_dict())
schedule = get_schedule(id, task_id)
if schedule:
confirmation = PendingConfirmation(
child_id=id, entity_id=task_id, entity_type='chore',
user_id=user_id, status='approved',
approved_at=datetime.now(timezone.utc).isoformat()
)
pending_confirmations_db.insert(confirmation.to_dict())
send_event_for_current_user(Event(EventType.CHILD_CHORE_CONFIRMATION.value,
ChildChoreConfirmation(id, task_id, ChildChoreConfirmation.OPERATION_APPROVED)))
@@ -1198,12 +1201,20 @@ def approve_chore(id):
child_db.update({'points': child.points}, ChildQuery.id == id)
# Update confirmation to approved
now_str = datetime.now(timezone.utc).isoformat()
pending_confirmations_db.update(
{'status': 'approved', 'approved_at': now_str},
(PendingQuery.child_id == id) & (PendingQuery.entity_id == task_id) &
(PendingQuery.entity_type == 'chore') & (PendingQuery.user_id == user_id)
)
# For general (non-scheduled) chores, remove the confirmation so chore resets to normal
schedule = get_schedule(id, task_id)
if schedule:
now_str = datetime.now(timezone.utc).isoformat()
pending_confirmations_db.update(
{'status': 'approved', 'approved_at': now_str},
(PendingQuery.child_id == id) & (PendingQuery.entity_id == task_id) &
(PendingQuery.entity_type == 'chore') & (PendingQuery.user_id == user_id)
)
else:
pending_confirmations_db.remove(
(PendingQuery.child_id == id) & (PendingQuery.entity_id == task_id) &
(PendingQuery.entity_type == 'chore') & (PendingQuery.user_id == user_id)
)
tracking_metadata = {
'task_name': task.name,

View File

@@ -2,7 +2,7 @@ from flask import Blueprint, request, jsonify
from tinydb import Query
from api.utils import get_validated_user_id, send_event_for_current_user
from api.error_codes import ErrorCodes
from db.db import child_db
from db.db import child_db, pending_confirmations_db
from db.chore_schedules import get_schedule, upsert_schedule, delete_schedule
from db.task_extensions import get_extension, add_extension, delete_extension_for_child_task
from models.chore_schedule import ChoreSchedule
@@ -11,6 +11,7 @@ from events.types.event import Event
from events.types.event_types import EventType
from events.types.chore_schedule_modified import ChoreScheduleModified
from events.types.chore_time_extended import ChoreTimeExtended
from events.types.child_chore_confirmation import ChildChoreConfirmation
import logging
chore_schedule_api = Blueprint('chore_schedule_api', __name__)
@@ -102,6 +103,20 @@ def set_chore_schedule(child_id, task_id):
delete_extension_for_child_task(child_id, task_id)
upsert_schedule(schedule)
# Reset pending chore confirmations when schedule changes (completed chores stay)
PendingQuery = Query()
pending_chores = pending_confirmations_db.search(
(PendingQuery.child_id == child_id) & (PendingQuery.entity_id == task_id) &
(PendingQuery.entity_type == 'chore') & (PendingQuery.status == 'pending')
)
for pc in pending_chores:
pending_confirmations_db.remove(
(PendingQuery.child_id == child_id) & (PendingQuery.entity_id == task_id) &
(PendingQuery.entity_type == 'chore') & (PendingQuery.status == 'pending')
)
send_event_for_current_user(Event(EventType.CHILD_CHORE_CONFIRMATION.value,
ChildChoreConfirmation(child_id, task_id, ChildChoreConfirmation.OPERATION_RESET)))
send_event_for_current_user(Event(
EventType.CHORE_SCHEDULE_MODIFIED.value,
ChoreScheduleModified(child_id, task_id, ChoreScheduleModified.OPERATION_SET)

View File

@@ -3,11 +3,12 @@ from tinydb import Query
from api.utils import send_event_for_current_user, get_validated_user_id
from events.types.child_rewards_set import ChildRewardsSet
from db.db import reward_db, child_db
from db.db import reward_db, child_db, pending_confirmations_db
from db.child_overrides import delete_overrides_for_entity
from events.types.event import Event
from events.types.event_types import EventType
from events.types.reward_modified import RewardModified
from events.types.child_reward_request import ChildRewardRequest
from models.reward import Reward
reward_api = Blueprint('reward_api', __name__)
@@ -155,6 +156,21 @@ def edit_reward(id):
if not is_dirty:
return jsonify({'error': 'No valid fields to update'}), 400
# Reset pending reward requests when cost changes
if 'cost' in data:
PendingQuery = Query()
pending_rewards = pending_confirmations_db.search(
(PendingQuery.entity_id == id) & (PendingQuery.entity_type == 'reward') &
(PendingQuery.status == 'pending')
)
for pr in pending_rewards:
pending_confirmations_db.remove(
(PendingQuery.child_id == pr['child_id']) & (PendingQuery.entity_id == id) &
(PendingQuery.entity_type == 'reward') & (PendingQuery.status == 'pending')
)
send_event_for_current_user(Event(EventType.CHILD_REWARD_REQUEST.value,
ChildRewardRequest(pr['child_id'], id, ChildRewardRequest.REQUEST_CANCELLED)))
if reward.user_id is None: # public reward
new_reward = Reward(name=reward.name, description=reward.description, cost=reward.cost, image_id=reward.image_id, user_id=user_id)
reward_db.insert(new_reward.to_dict())

View File

@@ -3,11 +3,12 @@ from tinydb import Query
from api.utils import send_event_for_current_user, get_validated_user_id
from events.types.child_tasks_set import ChildTasksSet
from db.db import task_db, child_db
from db.db import task_db, child_db, pending_confirmations_db
from db.child_overrides import delete_overrides_for_entity
from events.types.event import Event
from events.types.event_types import EventType
from events.types.task_modified import TaskModified
from events.types.child_chore_confirmation import ChildChoreConfirmation
from models.task import Task
task_api = Blueprint('task_api', __name__)
@@ -176,7 +177,23 @@ def edit_task(id):
if not is_dirty:
return jsonify({'error': 'No valid fields to update'}), 400
# Reset pending chore confirmations when task is modified (points, type, etc.)
# Completed (approved) chores stay in completed state
if 'points' in data or 'type' in data:
PendingQuery = Query()
pending_chores = pending_confirmations_db.search(
(PendingQuery.entity_id == id) & (PendingQuery.entity_type == 'chore') &
(PendingQuery.status == 'pending')
)
for pc in pending_chores:
pending_confirmations_db.remove(
(PendingQuery.child_id == pc['child_id']) & (PendingQuery.entity_id == id) &
(PendingQuery.entity_type == 'chore') & (PendingQuery.status == 'pending')
)
send_event_for_current_user(Event(EventType.CHILD_CHORE_CONFIRMATION.value,
ChildChoreConfirmation(pc['child_id'], id, ChildChoreConfirmation.OPERATION_RESET)))
if task.user_id is None: # public task
new_task = Task(name=task.name, points=task.points, type=task.type, image_id=task.image_id, user_id=user_id)
task_db.insert(new_task.to_dict())