Fixed year detection for billing number

This commit is contained in:
Marc Aymerich 2016-01-27 09:16:33 +00:00
parent c678a6c0da
commit 2e317e529f
2 changed files with 3 additions and 2 deletions

View file

@ -455,3 +455,4 @@ mkhomedir_helper or create ssh homes with bash.rc and such
* setuppostgres use porject_name for db name and user instead of orchestra
* show all available choices (plugins) on admin settings value i.e. payment methods

View file

@ -226,14 +226,14 @@ class Bill(models.Model):
prefix = getattr(settings, 'BILLS_%s_NUMBER_PREFIX' % bill_type)
if self.is_open:
prefix = 'O{}'.format(prefix)
bills = cls.objects.filter(number__regex=r'^%s[1-9]+' % prefix)
year = timezone.now().strftime("%Y")
bills = cls.objects.filter(number__regex=r'^%s%s[1-9]+' % (prefix, year)
last_number = bills.order_by('-number').values_list('number', flat=True).first()
if last_number is None:
last_number = 0
else:
last_number = int(last_number[len(prefix)+4:])
number = last_number + 1
year = timezone.now().strftime("%Y")
number_length = settings.BILLS_NUMBER_LENGTH
zeros = (number_length - len(str(number))) * '0'
number = zeros + str(number)