证书颁发

This commit is contained in:
caoqianming 2021-06-05 22:42:55 +08:00
parent 63017b3c4f
commit 2f7262cbad
3 changed files with 48 additions and 4 deletions

View File

@ -106,9 +106,24 @@ class SendCode(CommonModel):
class Candidate(CommonModel): class Candidate(CommonModel):
consumer = models.ForeignKey(Consumer, on_delete=models.CASCADE, related_name='candidate_consumer') consumer = models.ForeignKey(Consumer, on_delete=models.CASCADE, related_name='candidate_consumer')
workscope = models.ForeignKey(WorkScope, on_delete=models.CASCADE, related_name='candidate_workscope') workscope = models.ForeignKey(WorkScope, on_delete=models.DO_NOTHING, related_name='candidate_workscope')
report_number = models.TextField('报告单号', null=True, blank=True)
# 下面是证书信息
number = models.CharField('报告单号', max_length=60, null=True, blank=True)
workscope_name = models.CharField('证书工作类别', max_length=60, null=True, blank=True)
consumer_name = models.CharField('姓名', max_length=60, null=True, blank=True)
ID_number = models.CharField('身份证号', max_length=60, null=True, blank=True)
compnay_name = models.CharField('单位', max_length=60, null=True, blank=True)
deptname = models.CharField('部门', max_length=60, null=True, blank=True)
issue_date = models.DateField('发证日期', null=True, blank=True) issue_date = models.DateField('发证日期', null=True, blank=True)
start_date = models.DateField('有效期始', null=True, blank=True) start_date = models.DateField('有效期始', null=True, blank=True)
end_date = models.DateField('有效期止', null=True, blank=True) end_date = models.DateField('有效期止', null=True, blank=True)
examtest = models.ForeignKey(to='examtest.examtest', verbose_name='关联考试', null=True, blank=True, on_delete=models.CASCADE) examtest = models.OneToOneField(to='examtest.examtest', verbose_name='关联考试', null=True, blank=True, on_delete=models.DO_NOTHING, related_name='candidate_examtest')
class Meta:
verbose_name = '证书'
verbose_name_plural = verbose_name
def __str__(self):
return self.number

View File

@ -1,5 +1,5 @@
from crm.models import Candidate from crm.models import Candidate
from datetime import datetime from datetime import datetime, timedelta
from django.db.models import Avg from django.db.models import Avg
from django.db.models.query import QuerySet from django.db.models.query import QuerySet
@ -498,6 +498,35 @@ class ExamTestViewSet(PageOrNot, ModelViewSet):
path = exportw_test(obj, False) path = exportw_test(obj, False)
return Response({'path': path}) return Response({'path': path})
@action(methods=['post'], detail=True, perms_map = [{'*':'candidate_issue'}])
def issue(self, request, pk=None):
'''
颁发证书
'''
obj = self.get_object()
try:
candidate = Candidate.objects.get_or_create(examtest=obj)
return Response({'error':'证书已存在'})
except:
candidates = Candidate.objects.filter(consumer=obj.consumer, workscope=obj.workscope, number__isnull=True)
if candidates.exists():
candidate = candidates(1)
else:
candidate = Candidate.objects.create(consumer=obj.consumer, workscope=obj.workscope)
count = Candidate.objects.filter(number__isnull=True).count()
candidate.examtest = obj
now = timezone.now()
candidate.issue_date = now
candidate.start_date = now
candidate.end_date = now + timedelta(years=3)
candidate.workscope_name = obj.workscope.name
candidate.consumer_name = obj.consumer_detail.consumer_name
candidate.ID_number = obj.consumer_detail.ID_number
candidate.company_name = obj.consumer_detail.company_name
candidate.deptname = obj.consumer_detail.deptname
candidate.number='SL'+ str(now.year)[-2:] + str(count+1).zfill(6)
return Response()
class PaperViewSet(ModelViewSet): class PaperViewSet(ModelViewSet):
""" """
押题卷增删改查 押题卷增删改查

Binary file not shown.