Добавлена архитектура правил, планов и состояний ухода - #21
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6dd9b01328
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| CareRule.objects.filter( | ||
| pet=event.pet, | ||
| event_type=event_type, | ||
| is_active=True, | ||
| ) |
There was a problem hiding this comment.
Preserve separate recurring custom tasks
When a pet has two titled recurring custom events, both resolve to the same catalog EventType (custom), so this lookup returns the first active rule and the second event silently overwrites its interval and start date. Custom events previously recurred independently, so rules need an identity beyond the pet/type pair, such as their originating custom task.
Useful? React with 👍 / 👎.
|
|
||
| with transaction.atomic(): | ||
| response = super().form_valid(form) | ||
| sync_care_rule_from_event_repeat(self.object, repeat_after_days) |
There was a problem hiding this comment.
Allow users to disable an existing recurrence
After the first save, repeat_after_days is cleared from the Event and stored in CareRule, so the next update form renders this field blank. Submitting that blank value calls sync_care_rule_from_event_repeat(..., None), which returns without changing the existing active rule; consequently the normal event UI neither displays the configured interval nor provides a way to clear it, and reminders continue after the user submits an empty recurrence field.
Useful? React with 👍 / 👎.
| if base_dt is None: | ||
| base_dt = _get_care_rule_start_datetime(care_rule) |
There was a problem hiding this comment.
Honor the selected CareRule calculation mode
For rules configured as last_planned_date or fixed_schedule, the only preceding calculation branch is skipped and this fallback always uses start_date. Once a generated task is completed or skipped, the next generator run therefore recreates a task at the same original timestamp rather than advancing from the previous plan or along the fixed schedule.
Useful? React with 👍 / 👎.
| if local_next_dt.date() == today: | ||
| event_name = event.title.strip() if event.title else "другое событие" | ||
| tasks.append(event_name) | ||
| tasks.append(task_labels.get(task.event_type_slug, task.event_type_name.lower())) |
There was a problem hiding this comment.
Preserve custom titles in daily reminders
For a recurring custom event represented by a CareRule, task.event_type_name is the catalog name Другое, so this emits a generic “другое” task. The subsequent custom_care_rule_exists check suppresses the legacy loop that used the event's actual title, meaning even a single named reminder such as “Заменить лампу” loses its actionable text after conversion to the new architecture.
Useful? React with 👍 / 👎.
| плановых задач и активных состояний нужно передать ``apply_changes=True``. | ||
| """ | ||
| care_rule_result = backfill_care_rules_from_repeat_events(apply_changes=apply_changes) | ||
| planned_event_result = generate_planned_events_from_care_rules(apply_changes=apply_changes) |
There was a problem hiding this comment.
Include newly previewed rules when counting planned tasks
In dry-run mode with only legacy repeating events, the preceding backfill reports candidate CareRule rows but deliberately does not create them, so this planner sees no rules and reports planned_events_to_create == 0. Running the same command with --apply creates both the rules and their planned events, making the command's “will be created” preview materially undercount the changes it will apply.
Useful? React with 👍 / 👎.
Что изменено
CareRule,PlannedEvent,PetConditionдля разделения регулярности, плановых задач и активных состояний ухода.Event.happened_atрядом со старымevent_datetime.0012-0015.recalculate_pet_statuses.CareRule.Что сохранено
Event.event_type,event_datetime,repeat_after_days,no_handling_daysостаются совместимыми на переходный период.mainне трогались.README
Перед merge проверено: обязательная правка
README.mdсейчас не требуется. README уже описывает повторяющиеся задачи и напоминания на уровне публичной витрины; внутренние деталиCareRule,PlannedEvent,PetConditionне выносим, чтобы README не превращался в техническую спецификацию.Проверки
python manage.py makemigrations --checkpython manage.py checkgit diff --checkisort --check-onlypython manage.py recalculate_pet_statusesв dry-runpytest --no-cov— 257 passedПримечание по форматированию
blackпока не включался в автоматический цикл Codex в этой Windows-среде из-за зависания процесса после форматирования. Основной контроль закрытisort,git diff --check, Django checks и pytest.