|
@@ -67,6 +67,19 @@ class InvoiceNumber:
|
|
|
day=1),
|
|
|
int(m.group('index')))
|
|
|
|
|
|
+ @staticmethod
|
|
|
+ def time_sequence_filter(date, field_name='date'):
|
|
|
+ """ Build queryset filter to be used to get the invoices from the
|
|
|
+ numbering sequence of a given date.
|
|
|
+
|
|
|
+ :param field_name: the invoice field name to filter on.
|
|
|
+
|
|
|
+ :type date: datetime
|
|
|
+ :rtype: dict
|
|
|
+ """
|
|
|
+
|
|
|
+ return {'{}__month'.format(field_name): date.month}
|
|
|
+
|
|
|
|
|
|
class InvoiceQuerySet(models.QuerySet):
|
|
|
def get_next_invoice_number(self, date):
|
|
@@ -81,7 +94,8 @@ class InvoiceQuerySet(models.QuerySet):
|
|
|
return str(invoice_number)
|
|
|
|
|
|
def _get_last_invoice_number(self, date):
|
|
|
- return self.with_valid_number().aggregate(
|
|
|
+ same_seq_filter = InvoiceNumber.time_sequence_filter(date)
|
|
|
+ return self.filter(**same_seq_filter).with_valid_number().aggregate(
|
|
|
models.Max('number'))['number__max']
|
|
|
|
|
|
def with_valid_number(self):
|