added net weight, user, date etc. generates new document number with year as a prefix, restarts numbering every year
This commit is contained in:
+16
-1
@@ -1,4 +1,4 @@
|
||||
from django.db import models
|
||||
from django.db import models, transaction
|
||||
from django.contrib.auth.models import AbstractUser
|
||||
from django.utils import timezone
|
||||
|
||||
@@ -57,3 +57,18 @@ class Report(models.Model):
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class DocumentCounter(models.Model):
|
||||
year = models.IntegerField(unique=True)
|
||||
last_number = models.IntegerField(default=0)
|
||||
|
||||
|
||||
def generate_doc_number(year):
|
||||
with transaction.atomic():
|
||||
counter, _ = DocumentCounter.objects.select_for_update().get_or_create(
|
||||
year=year, defaults={'last_number': 0}
|
||||
)
|
||||
counter.last_number += 1
|
||||
counter.save()
|
||||
return f"{year}-{counter.last_number:06d}"
|
||||
|
||||
Reference in New Issue
Block a user