from tinymce.models import HTMLField
from django.db.models import signals
+
+months_choices = []
+for i in range(1,13):
+ months_choices.append((i, datetime.date(2015, i, 1).strftime('%B')))
+
+
class IEJ(Model):
name = models.CharField(_('name'), max_length=255)
available = models.BooleanField(_('available'))
platform_only = models.BooleanField(_('e-learning platform only'))
duration = models.IntegerField(u"Durée en heures", default=0)
-
+
def __unicode__(self):
if self.name and self.period:
return ' - '.join([self.name, self.period.name])
receipt_id = models.IntegerField('numéro de facture', blank=True, null=True,
unique=True)
-
+
def __unicode__(self):
try:
return self.user.last_name + ' ' + self.user.first_name
if payment['type'] != 'online' or payment['online_paid']:
amount += payment['value']
return amount
-
+
@property
def total_payments_all(self):
amount = 0
pay_status = models.CharField('Statut', choices=PAY_STATUS_CHOICES,
max_length=64, blank=True, null=True,
default='honoraire')
-
+
date_registered = models.DateTimeField(_('registration date'), auto_now_add=True, null=True, blank=True)
-
-
+
+
def __unicode__(self):
try:
return self.user.last_name + ' ' + self.user.first_name
except:
return ''
-
+
class Meta(MetaCore):
db_table = app_label + '_' + 'corrector'
verbose_name = _('Correcteur')
ordering = ['user__last_name', '-date_registered']
-months_choices = []
-for i in range(1,13):
- months_choices.append((i, datetime.date(2015, i, 1).strftime('%B')))
-
-
class Payment(models.Model):
"a payment from a student"
blank=True)
date_paid = models.DateField(u"date de paiement", blank=True, null=True)
-
+
class Meta(MetaCore):
db_table = app_label + '_' + 'payments'
verbose_name = _("Payment")
if month in payment_per_month:
payment_per_month[month]['amount'] += value
payment_per_month[month]['type'].add(ptype_label)
-
+
row.write(19, total_payments)
row.write(20, student.total_fees)
row.write(23, student.subscription_fees)
row.write(24, student.fascicule)
-
-
+
+
i = 25
for month in months_choices:
row.write(i, payment_per_month[month[0]]['amount'])
for student in self.students:
counter = self.export_user(counter, student)
+ def date_str_to_date(self, date):
+ date_split = date.split('/')
+ pydate = datetime.date(day=date_split[0], month=date_split[1], year=date_split[2])
+ return pydate
+
+ def date_str_to_datetime(self, date):
+ date_split = date.split('/')
+ pydate = datetime.datetime(day=date_split[0], month=date_split[1], year=date_split[2])
+ return pydate
+
+ def import_user(self, row):
+ last_name = row[0]
+ first_name = row[1]
+ iej = row[2]
+ training = row[3]
+ proc = row[4]
+ spe = row[5]
+ oral_1 = row[6]
+ email = row[7]
+ address = row[8]
+ address_detail = row[9]
+ cp = row[10]
+ city = row[11]
+ tel = row[12]
+ birth = row[13]
+ level = row[14]
+ register_date = row[15]
+ total_reduction = row[16]
+ desc_reduction = row[17]
+ total_payment = row[18]
+ total_fees = row[19]
+ balance = row[20]
+ total_paybacks = row[21]
+ subscription_fees = row[22]
+ fascicule_sent = row[23]
+
+ students = Student.objects.filter(first_name=first_name, last_name=last_name, email=email)
+
+ if not students:
+ username = get_unique_username('first_name', 'last_name')
+ user = User(first_name=first_name, last_name=last_name, email=email, username=username)
+ user.save()
+
+ profile = Profile(user=user)
+ profile.address = address
+ profile.address_detail = address_detail
+ profile.postal_code = cp
+ profile.city = city
+ profile.telephone = tel
+ profile.birthday = self.date_str_to_date(birth)
+ profile.save()
+
+ student = Student(first_name=first_name, last_name=last_name, email=email)
+ student.user = user
+ student.iej = IEJ.objects.get(name=iej)
+ student.trainings.add(Training.objects.get(code=training))
+ student.procedure = Course.objects.get(code=proc)
+ student.written_speciality = Course.objects.get(code=spe)
+ student.oral_1 = Course.objects.get(code=oral_1)
+ student.level = level
+ student.date_subscribed = self.date_str_to_datetime(register_date)
+
+ if total_reduction:
+ discount = Discount(student=student, value=float(total_reduction), description=desc_reduction)
+ discount.save()
+ student.balance = float(balance)
+
+ if total_paybacks:
+ payback = Payback(student=student, value=float(total_paybacks))
+ payback.save()
+ student.subscription_fees = float(subscription_fees)
+ student.fascicule = True if fascicule else False
+
+ student.save()
+
+ i = 24
+ for month in months_choices:
+ amount = row[i]
+ payment_type = row[i+1]
+ payment = Payment(student=student, value=float(amount), month=month, type=payment_type)
+ payment.save()
+ i += 2
+
+
+ def read(self, path):
+
+ cols = [{'name':'NOM', 'width':5000},
+ {'name':'PRENOM', 'width':5000},
+ {'name': 'PHOTO', 'width': 7500},
+ {'name':'IEJ', 'width':2500},
+ {'name':'FORMATIONS', 'width':6000},
+ {'name':'PROC', 'width':2500},
+ {'name':'Ecrit Spe', 'width':3000},
+ {'name':'ORAL 1', 'width':3000},
+ {'name':'MAIL', 'width':7500},
+ {'name':'ADRESSE', 'width':7500},
+ {'name':'ADRESSE (suite)', 'width': 7500},
+ {'name':'CP', 'width':2500},
+ {'name':'VILLE', 'width':5000},
+ {'name':'TEL', 'width':5000},
+ {'name': 'Date de naissance', 'width': 5000},
+ {'name': "Niveau d'etude", 'width': 5000},
+ {'name':"Date inscription", 'width':5000},
+ {'name':"Total reductions", 'width':4000},
+ {'name':"Description reduction", 'width':4000},
+ {'name':"Total paiements", 'width':4000},
+ {'name':"Prix formation net", 'width':4000},
+ {'name':"Balance", 'width':4000},
+ {'name':"Total remboursement", 'width':4000},
+ {'name': "Frais d'inscription", 'width': 4000},
+ {'name':"Envoi des fascicules", 'width':3500},
+ ]
+
+ book = xlrd.open_workbook(path)
+ sheet = book.sheet_by_index(0)
+ for rx in range(sheet.nrows):
+ self.import_user(sheet.row_values(rx))
+
class UsersExportView(UsersView):
row.write(15, str(corrector.period))
row.write(16, corrector.pay_status)
row.write(17, (', ').join([course.title for course in corrector.courses.all()]))
-
+
return counter + 1
def write(self):
{'name':"STATUT", 'width':5000},
{'name':"MATIERES", 'width':30000},
]
-
+
i = 0
for col in cols:
row.write(i, col['name'])
self.sheet.col(i).width = col['width']
i += 1
-
+
counter = 0
for corrector in self.correctors:
counter = self.export_user(counter, corrector)
student.oral_1 = Course.objects.get(code='X')
if not student.oral_2:
student.oral_2 = Course.objects.get(code='X')
- student.save()
+ student.save()
profile = user.profile.all()[0]
if profile.city:
profile.city = profile.city.upper()
filename += '.pdf'
return filename.encode('utf-8')
-
+
class ReceiptPDFView(PDFTemplateResponseMixin, TemplateView):
template_name = 'receipt/receipt_pdf.html'
raise PermissionDenied
context['site'] = Site.objects.get_current()
-
+
student = user.student.all()[0]
if not student.training and student.trainings.all():
student.training = student.trainings.all()[0]
training = student.training
period = training.period
- student.save()
+ student.save()
profile = user.profile.all()[0]
context['student'] = student
period.date_end.strftime('%d/%m/%Y'),)
oral_1 = student.oral_1 and student.oral_1.title != 'Aucune'
-
+
if oral_1:
- substract += ORAL_OPTION_PRICE
-
+ substract += ORAL_OPTION_PRICE
+
items.append({ 'label': label,
'unit_price': student.total_fees - substract - student.total_discount,
'amount': 1,
context['receipt_items'] = items
context['receipt_total'] = sum([ i['total'] for i in items ])
return context
-
+
class ReceiptPDFViewDownload(ReceiptPDFView):
pdf_filename = 'facture.pdf'
filename += '.pdf'
return filename.encode('utf-8')
-
+
class CorrectorRegistrationPDFView(PDFTemplateResponseMixin, TemplateView):
template_name = 'registration/registration_corrector_pdf.html'
context['corrector'] = corrector
context['profile'] = profile
return context
-
+
class RegistrationPDFViewDownload(RegistrationPDFView):
pdf_filename = 'registration.pdf'
filename = '_'.join([prefix, corrector.user.first_name, corrector.user.last_name])
filename += '.pdf'
return filename.encode('utf-8')
-
+
class CorrectorAddView(CreateView):
def get_success_url(self):
return reverse_lazy('teleforma-corrector-register-complete', kwargs={'username':self.object.username})
-
+
class CorrectorCompleteView(TemplateView):
template_name = 'registration/registration_corrector_complete.html'