Codex-generated pull request#2
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 53b4e0e866
ℹ️ 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".
|
|
||
| class MeterReading(BaseTimestampModel): | ||
| customer = models.ForeignKey(Customer, on_delete=models.PROTECT, related_name="meter_readings", verbose_name="顧客") | ||
| reading_month = models.DateField("検針月") |
There was a problem hiding this comment.
Enforce month-granular uniqueness for meter readings
reading_month is a DateField, so the uniqueness constraint on (customer, reading_month) only blocks exact same dates, not duplicate entries within the same billing month; for example, the same customer can save both 2025-02-01 and 2025-02-28. This breaks the intended YYYY-MM data model and can lead to duplicate monthly billing records and invoices.
Useful? React with 👍 / 👎.
| "unread_meter_count": Customer.objects.filter(is_active=True).count() | ||
| - MeterReading.objects.filter( | ||
| reading_month__year=timezone.now().year, reading_month__month=timezone.now().month | ||
| ).count(), |
There was a problem hiding this comment.
Compute unread meter count from active-customer gaps
The unread meter KPI subtracts all current-month reading rows from the active customer count, so readings tied to inactive customers (or multiple rows in one month) incorrectly reduce the number and can even make it negative. This underreports pending work on the dashboard whenever current-month readings are not a one-to-one set of active customers.
Useful? React with 👍 / 👎.
| reading_month__year=timezone.now().year, reading_month__month=timezone.now().month | ||
| ).count(), | ||
| "unissued_invoice_count": MeterReading.objects.filter(invoice__isnull=True).count(), | ||
| "unpaid_invoice_count": Invoice.objects.exclude(status="paid").count(), |
There was a problem hiding this comment.
Exclude cancelled invoices from unpaid totals
Using exclude(status="paid") for unpaid_invoice_count treats cancelled invoices as unpaid, which inflates the dashboard’s未入金件数 once cancellations occur and misleads collection tracking. This metric should only include collectible/open invoices rather than every non-paid status.
Useful? React with 👍 / 👎.
Codex generated this pull request, but encountered an unexpected error after generation. This is a placeholder PR message.
Codex Task