Skip to content

Commit

Permalink
Fix base/models/get_initial_number not fetching the highest number
Browse files Browse the repository at this point in the history
`values(...).last()` returns a dict, on which `getattr` doesn't work, so `get_initial_number` always returned 1 instead of the highest `Invoice.number`
  • Loading branch information
milano-slesarik authored and PetrDlouhy committed Mar 7, 2025
1 parent 9a86313 commit c2ae70b
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions plans/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1066,10 +1066,7 @@ def get_queryset(self):


def get_initial_number(older_invoices):
return (
getattr(older_invoices.order_by("number").values("number").last(), "number", 0)
+ 1
)
return (older_invoices.order_by("number").values_list("number", flat=True).last() or 0) + 1


class AbstractInvoice(BaseMixin, models.Model):
Expand Down

0 comments on commit c2ae70b

Please sign in to comment.