-
Notifications
You must be signed in to change notification settings - Fork 9
Automated OrderRound Creation, move from pyenv to uv, update dev setup #389
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
Automated OrderRound Creation, move from pyenv to uv, update dev setup #389
Conversation
This feature automatically creates new order rounds based on a configurable schedule, eliminating the need for manual creation every other Sunday. ## How It Works The system uses a cron job that runs every 6 hours to check if a new order round should be created. When the conditions are met, it automatically creates a new order round with all the proper dates calculated based on your configuration. ## Configuration All settings are managed through the Django admin interface under **Constance Config**: ### Core Settings - **AUTO_CREATE_ORDERROUNDS**: Enable/disable the automation (default: False) - **ORDERROUND_INTERVAL_WEEKS**: How often to create new rounds (default: 2 weeks) - **ORDERROUND_CREATE_DAYS_AHEAD**: How far in advance to create rounds (default: 7 days) ### Timing Settings - **ORDERROUND_OPEN_HOUR**: Hour when order rounds open, 24h format (default: 12) - **ORDERROUND_CLOSE_HOUR**: Hour when order rounds close, 24h format (default: 3) - **ORDERROUND_DURATION_HOURS**: How long order rounds stay open (default: 63 hours) - **ORDERROUND_COLLECT_DAYS_AFTER**: Days after closing when products can be collected (default: 0) - **ORDERROUND_COLLECT_HOUR**: Hour when products can be collected (default: 18) ### Coordinator Settings - **ORDERROUND_DEFAULT_TRANSPORT_COORDINATOR**: Default transport coordinator user ID (default: 986) - **ORDERROUND_DEFAULT_PICKUP_LOCATION**: Default pickup location ID (default: 1) ## Setup Instructions 1. **Enable the feature**: - Go to Django Admin → Constance Config - Set `AUTO_CREATE_ORDERROUNDS` to `True` 2. **Configure your schedule**: - Adjust the timing settings to match your current manual schedule - Current defaults: Opens Sunday at 12:00, closes Wednesday at 03:00, collect Wednesday at 18:00 - Transport coordinator automatically set to user ID 986 - Pickup location automatically set to location ID 1 3. **Set up cron** (if not already running): - The system uses django-cron which should already be configured - Make sure your deployment runs: `python manage.py runcrons` ## Manual Controls ### Admin Interface - Go to Django Admin → Ordering → Order Rounds - Select any order round and use the action "Create next order round automatically" - This respects your automation settings but bypasses the timing checks ### Management Command ```bash # Create the next order round python manage.py create_orderround # Preview what would be created (dry run) python manage.py create_orderround --dry-run # Force creation even if disabled or not needed python manage.py create_orderround --force ``` ## How Dates Are Calculated The system calculates dates based on: 1. **Next Opening Date**: - If there's a previous round: adds the interval (e.g., 2 weeks) to the last round's opening date - If no previous rounds: uses the next Sunday 2. **Closing Date**: Opening date + duration hours (e.g., 72 hours later) 3. **Collection Date**: Closing date + collection days (e.g., same day if 0 days after) **Example Schedule**: - **Opens**: Sunday at 12:00 (noon) - **Closes**: Wednesday at 03:00 (3 AM) - 63 hours later - **Collect**: Wednesday at 18:00 (6 PM) - same day as closing ## Safety Features - **No Duplicates**: Won't create a round if one already exists within the configured timeframe - **Manual Override**: You can always create rounds manually - automation won't interfere - **Configuration Checks**: Won't create rounds if automation is disabled - **Error Logging**: All creation attempts are logged for troubleshooting ## Monitoring - Check the **Log** section in Django admin for creation events - Use the management command with `--dry-run` to preview upcoming rounds - The cron job prints status messages that appear in your application logs ## Troubleshooting ### Order rounds aren't being created automatically 1. Check that `AUTO_CREATE_ORDERROUNDS` is set to `True` 2. Verify that django-cron is running (`python manage.py runcrons`) 3. Check if there's already a future round within your `ORDERROUND_CREATE_DAYS_AHEAD` setting 4. Look at the application logs for any error messages from the `AutoCreateOrderRounds` cron job ### Dates are wrong 1. Review your timing configuration in Constance Config 2. Use `python manage.py create_orderround --dry-run` to preview the next round 3. Check that your server timezone is set correctly ### Need to disable temporarily 1. Set `AUTO_CREATE_ORDERROUNDS` to `False` in Constance Config 2. The cron job will continue to run but won't create any rounds 3. You can still use manual creation methods ## Migration from Manual Process 1. **Before enabling**: Make sure your current manual schedule matches the configuration 2. **Enable gradually**: Start with `AUTO_CREATE_ORDERROUNDS = False` and test with the management command 3. **Monitor first few rounds**: Check that the automatically created rounds have the correct dates 4. **Keep manual backup**: You can always create rounds manually if needed
d64b5ad to
08e9ebf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements automated OrderRound creation and modernizes the development environment by migrating from pyenv to uv. The automation creates order rounds based on a configurable schedule, eliminating the need for manual creation every two weeks.
- Automated order round batch creation with configurable timing and settings
- Migration from pyenv to uv for dependency management with updated Docker setup
- Improved development environment with one-command setup and better documentation
Reviewed Changes
Copilot reviewed 18 out of 20 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| webapp/ordering/core.py | Adds automated order round creation logic with date calculation functions |
| webapp/ordering/cron.py | Implements cron job for automatic order round batch creation |
| webapp/ordering/admin.py | Adds admin action to manually trigger order round batch creation |
| webapp/ordering/tests/test_core.py | Updates tests for renamed functions and adds automation tests |
| webapp/vokou/settings/base.py | Adds configuration constants for order round automation |
| webapp/vokou/settings/development.py | Updates for uv migration and adds automation config override |
| webapp/vokou/settings/docker_development.py | New settings file for Docker development environment |
| pyproject.toml | Replaces Pipfile with modern uv-compatible project configuration |
| docker-compose.yml | Enhanced Docker setup with health checks and auto-configuration |
| Dockerfile | Updates for uv migration and PostgreSQL client installation |
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
|
Net even lokaal getest en het alles lijkt goed te werken, ziet er allemaal prima uit. |
|
@bveldkamp top, ja ik zie nu dat ik daar een fout heb gemaakt, is aangepast en zou nu moeten lukken. dan kunnen we denk ik deployen. doe jij dat? |
Update from pyenv to uv
pyenv is not really nice to use, update to use uv, setup is described in the README.
Update dev setup
The Docker setup has been fixed and simplified, also added a make file to make setting up easier.
Automatic order round creation
This feature automatically creates new order rounds based on a configurable schedule, eliminating the need for manual creation every other Sunday.
How It Works
The system uses a cron job that runs every 24 hours to check if a new order round batch should be created. When the conditions are met, it automatically creates a new order round batch with all the proper dates calculated based on your configuration.
Configuration
All settings are managed through the Django admin interface under Constance Config:
Core Settings
Timing Settings
Coordinator Settings
Setup Instructions
Enable the feature:
AUTO_CREATE_ORDERROUNDStoTrueConfigure your schedule:
Set up cron (if not already running):
python manage.py runcronsManual Controls
Admin Interface
Management Command
How Dates Are Calculated
If the last (as in, with the maximum
open_for_orderstime) order round is less than 31 days from now. Create a new order round batch, starting two weeks from the last order round and ending at the last day of the next quarter.