def form_valid(self, form): """Called after valid data.""" id = self.kwargs.get('id') data = form.cleaned_data course = data.get('course', 0) txn_method = data.get('txn_method') class_change = data.get('class_change') description = data.get('description') con = get_object_or_404(Contract, pk=id) initial_class = con.course class_obj = Class.objects.filter(course=con.course, student=con.student).first() class_obj.course = course class_obj.save() con.course = course con.save() from django.utils import timezone now = timezone.now() if class_change == FREE: return super(ContractClassChangeView, self).form_valid(form) if initial_class.start_date < now: txn = Transaction() txn.contract = con txn.txn_type = CLASS_CHANGE_INCOME txn.amount = 88000 txn.txn_method = txn_method txn.description = description txn.txn_date = datetime.datetime.now() txn.save() return super(ContractClassChangeView, self).form_valid(form)
def form_valid(self, form): """Called after valid data.""" data = form.cleaned_data payment = data.get('payment', 0) course = data.get('course') minus_length = data.get('minus_length') txn_method = data.get('txn_method') contract_number = data.get('contract_number') off_percent = data['off_percent'] description = data['description'] con_date = data['con_date'] obj = get_object_or_404(Student, pk=self.kwargs.get('id')) con = Contract() con.course = course con.date = con_date con.total_payment = payment con.minus_length = minus_length con.contract_number = contract_number con.off_percent = off_percent con.description = description con.student = obj total_price = course.price hourly_price = course.hourly_price if 100 >= off_percent > 0: off_price = total_price * off_percent / 100 total_price = total_price - off_price hourly_price = round(total_price / course.ctype.length) real_length = course.ctype.length - minus_length if minus_length == 0: con.req_payment = total_price else: con.req_payment = hourly_price * real_length con.save() txn = Transaction() txn.contract = con txn.txn_type = CONTRACT_INCOME txn.amount = payment txn.txn_date = con_date txn.txn_method = txn_method txn.save() cls = Class() cls.student = obj cls.course = course cls.save() return super(ContractFromStudentView, self).form_valid(form)
def form_valid(self, form): """Called after valid data.""" data = form.cleaned_data amount = data.get('amount', 0) txn_type = data.get('txn_type') txn_date = data.get('txn_date') txn_method = data.get('txn_method') info = data.get('info') txn = Transaction() txn.amount = amount txn.txn_type = txn_type txn.txn_date = txn_date txn.txn_method = txn_method txn.info = info txn.save() return super(TransactionAddView, self).form_valid(form)
def form_valid(self, form): """Called after valid data.""" year = form.cleaned_data['year'] month = form.cleaned_data['month'] mshift = form.cleaned_data['mshift'] context = self.get_context_data() salary_form = context['salary_form'] t_objs = TeacherSalary.objects.filter( month=month, year=year, mshift=mshift).exclude(teacher=None) teachers = [] now = datetime.datetime.now() for each in t_objs: teachers.append(each.teacher) if salary_form.is_valid(): objects = [] txn_objs = [] for each in salary_form: teacher = each.cleaned_data.get('teacher') if teacher in teachers: continue hour = each.cleaned_data.get('hour') salary = teacher.hourly_wage * hour if teacher and hour: objects.append( TeacherSalary(teacher=teacher, year=year, worked_hour=hour, month=month, mshift=mshift, salary=salary)) txn_objs.append( Transaction(amount=salary, txn_type=SALARY_EXPENSE, txn_date=now)) try: with transaction.atomic(): TeacherSalary.objects.bulk_create(objects) Transaction.objects.bulk_create(txn_objs) except IntegrityError: return redirect(reverse('teacher')) return HttpResponseRedirect(self.get_success_url())
def form_valid(self, form): """Called after valid data.""" data = form.cleaned_data payment = data.get('payment', 0) txn_date = data.get('txn_date') txn_method = data.get('txn_method') description = data.get('description') con_id = self.kwargs.get('id') con = get_object_or_404(Contract, pk=con_id) txn = Transaction() txn.contract = con txn.txn_type = CONTRACT_INCOME txn.amount = payment txn.txn_date = txn_date txn.txn_method = txn_method txn.description = description txn.save() con.total_payment = con.total_payment + payment con.save() return super(ContractPaymentView, self).form_valid(form)
def form_valid(self, form): """Called after valid data.""" data = form.cleaned_data fname = data['fname'] lname = data['lname'] register = data['register'] phone = data['phone'] birthday = data['birthday'] course = data['course'] payment = data['payment'] txn_method = data['txn_method'] minus_length = data['minus_length'] contract_number = data['contract_number'] off_percent = data['off_percent'] description = data['description'] con_date = data['con_date'] st = Student() st.fname = fname st.lname = lname st.register = register st.birthday = birthday st.phone = phone st.save() con = Contract() con.contract_number = contract_number con.date = con_date con.student = st con.course = course con.minus_length = minus_length con.total_payment = payment con.off_percent = off_percent con.description = description total_price = course.price hourly_price = course.hourly_price real_length = course.ctype.length - minus_length if 100 >= off_percent > 0: off_price = total_price * off_percent / 100 total_price = total_price - off_price hourly_price = round(total_price / course.ctype.length) if minus_length == 0: con.req_payment = total_price else: con.req_payment = hourly_price * real_length con.save() txn = Transaction() txn.contract = con txn.txn_type = CONTRACT_INCOME txn.amount = payment txn.txn_date = con_date txn.txn_method = txn_method txn.save() cls = Class() cls.student = st cls.course = course cls.save() return super(ContractAddView, self).form_valid(form)