Ejemplo n.º 1
0
def add_baptism_application(request):
    context = {}
    SponsorFormset = formset_factory(SponsorModelForm,
                                     formset=RequiredFormSet,
                                     extra=1,
                                     can_delete=True)
    if (request.method == "POST"):
        profile_form = ProfileModelForm(request.POST, prefix="profile")
        baptism_form = BaptismModelForm(request.POST, prefix="baptism")
        sponsor_formset = SponsorFormset(request.POST)
        invoice_form = InvoiceModelForm_Application(request.POST,
                                                    prefix="invoice")
        invoice_item_form = InvoiceItemModelForm_Application(
            request.POST, prefix="invoice_item")
        if profile_form.is_valid() and baptism_form.is_valid(
        ) and invoice_form.is_valid() and invoice_item_form.is_valid(
        ) and sponsor_formset.is_valid():
            profile = profile_form.save()
            baptism = baptism_form.save(commit=False)
            baptism.profile = profile
            baptism.status = SacramentModel.PENDING
            baptism.save()
            for form in sponsor_formset:
                if (form.is_valid()):
                    if (form.is_empty()):
                        print("EMPTY<<<<<<<<<<<<")
                        pass
                    else:
                        print("NOT EMPTY<<<<<<<<<<<")
                        f = form.save()
                        f.baptism = baptism
                        f.save()
            invoice = invoice_form.save(commit=False)
            invoice.profile_A = profile
            invoice.date_issued = datetime.now().date()
            invoice.save()
            item = invoice_item_form.save(commit=False)
            item.invoice = invoice
            item.item_type = ItemType.objects.get(name="Baptism")
            item.quantity = 1
            item.balance = item.balance - item.amount_paid - item.discount
            item.save()
            return redirect("sacrament:add-baptism-application")
        else:
            context['BaptismModelForm'] = baptism_form
            context['ProfileModelForm'] = profile_form
            context['SponsorFormset'] = sponsor_formset
            context['InvoiceModelForm_Application'] = invoice_form
            context['InvoiceItemModelForm_Application'] = invoice_item_form
            context['Submit_Form'] = Submit_Form()
            return render(request, "sacrament/application_baptism.html",
                          context)
    else:
        suggested_price = ItemType.objects.get(name="Baptism").suggested_price
        context['BaptismModelForm'] = BaptismModelForm(prefix="baptism")
        context['ProfileModelForm'] = ProfileModelForm(prefix="profile")
        context['SponsorFormset'] = SponsorFormset()
        context['InvoiceModelForm_Application'] = InvoiceModelForm_Application(
            prefix="invoice")
        context[
            'InvoiceItemModelForm_Application'] = InvoiceItemModelForm_Application(
                prefix="invoice_item", initial={'balance': suggested_price})
        context['Submit_Form'] = Submit_Form()
        return render(request, "sacrament/application_baptism.html", context)
Ejemplo n.º 2
0
def add_confirmation_application(request):
    context = {}
    SponsorFormset = formset_factory(SponsorModelForm,
                                     formset=RequiredFormSet,
                                     extra=1,
                                     can_delete=True)
    if (request.method == "POST"):
        profile_form = ProfileModelForm(request.POST, prefix="profile")
        confirmation_form = ConfirmationModelForm(request.POST,
                                                  prefix="confirmation")
        sponsor_formset = SponsorFormset(request.POST)
        invoice_form = InvoiceModelForm_Application(request.POST,
                                                    prefix="invoice")
        invoice_item_form = InvoiceItemModelForm_Application(
            request.POST, prefix="invoice_item")
        if profile_form.is_valid() and confirmation_form.is_valid(
        ) and invoice_form.is_valid() and invoice_item_form.is_valid(
        ) and sponsor_formset.is_valid():
            profile = None
            if (request.POST.get("profile_ID") != ""):
                profile_id = int(request.POST.get("profile_ID"))
                profile = Profile.objects.get(id=profile_id)
            else:
                profile = profile_form.save()
            confirmation = confirmation_form.save(commit=False)
            confirmation.profile = profile
            confirmation.status = SacramentModel.PENDING
            confirmation.save()
            for form in sponsor_formset:
                if (form.is_valid()):
                    f = form.save()
                    f.confirmation = confirmation
                    f.save()
            invoice = invoice_form.save(commit=False)
            invoice.profile_A = profile
            invoice.date_issued = datetime.now().date()
            invoice.save()
            item = invoice_item_form.save(commit=False)
            item.invoice = invoice
            item.item_type = ItemType.objects.get(name="Confirmation")
            item.balance = item.balance - item.amount_paid - item.discount
            item.quantity = 1
            item.save()
            return redirect("sacrament:add-confirmation-application")
        else:
            if (not sponsor_formset.is_valid()):
                context[
                    'SponsorError'] = "Firstname, Lastname, and Residence are required"
            context['ConfirmationModelForm'] = confirmation_form
            context['ProfileModelForm'] = profile_form
            context['SponsorFormset'] = sponsor_formset
            context['InvoiceModelForm_Application'] = invoice_form
            context['InvoiceItemModelForm_Application'] = invoice_item_form
            context['Submit_Form'] = Submit_Form()
            return render(request, "sacrament/application_confirmation.html",
                          context)
    else:
        suggested_price = ItemType.objects.get(
            name="Confirmation").suggested_price
        context['ConfirmationModelForm'] = ConfirmationModelForm(
            prefix="confirmation")
        context['ProfileModelForm'] = ProfileModelForm(prefix="profile")
        context['SponsorFormset'] = SponsorFormset()
        context['InvoiceModelForm_Application'] = InvoiceModelForm_Application(
            prefix="invoice")
        context[
            'InvoiceItemModelForm_Application'] = InvoiceItemModelForm_Application(
                prefix="invoice_item", initial={'balance': suggested_price})
        context['Submit_Form'] = Submit_Form()
        return render(request, "sacrament/application_confirmation.html",
                      context)
Ejemplo n.º 3
0
def add_marriage_application(request):
    context = {}
    SponsorFormset = formset_factory(SponsorModelForm,
                                     formset=RequiredFormSet,
                                     extra=1,
                                     can_delete=True)
    if (request.method == "POST"):
        groom_form = ProfileModelForm(request.POST, prefix="groom")
        bride_form = ProfileModelForm(request.POST, prefix="bride")
        marriage_form = MarriageModelForm(request.POST, prefix="marriage")
        sponsor_formset = SponsorFormset(request.POST)
        invoice_form = InvoiceModelForm_Application(request.POST,
                                                    prefix="invoice")
        invoice_item_form = InvoiceItemModelForm_Application(
            request.POST, prefix="invoice_item")
        if groom_form.is_valid() and bride_form.is_valid(
        ) and marriage_form.is_valid() and invoice_form.is_valid(
        ) and invoice_item_form.is_valid() and sponsor_formset.is_valid():
            bride = None
            groom = None
            if (request.POST.get("groom_ID") != ""):
                groom_id = int(request.POST.get("groom_ID"))
                groom = Profile.objects.get(id=groom_id)
            else:
                groom = groom_form.save()

            if (request.POST.get("bride_ID") != ""):
                bride_id = int(request.POST.get("bride_ID"))
                bride = Profile.objects.get(id=bride_id)
            else:
                bride = bride_form.save()

            marriage = marriage_form.save(commit=False)
            marriage.groom_profile = groom
            marriage.bride_profile = bride
            marriage.status = SacramentModel.PENDING
            marriage.save()
            if (sponsor_formset.is_valid()):
                for form in sponsor_formset:
                    f = form.save()
                    f.marriage = marriage
                    f.save()
            invoice = invoice_form.save(commit=False)
            invoice.profile_A = groom
            invoice.profile_B = bride
            invoice.date_issued = datetime.now().date()
            invoice.save()
            item = invoice_item_form.save(commit=False)
            item.invoice = invoice
            item.item_type = ItemType.objects.get(name="Marriage")
            item.balance = item.balance - item.amount_paid - item.discount
            item.quantity = 1
            item.save()
            return redirect("sacrament:add-marriage-application")
        else:
            if (not sponsor_formset.is_valid()):
                context[
                    'SponsorError'] = "Firstname, Lastname, and Residence are required"
            context['MarriageModelForm'] = marriage_form
            context['GroomModelForm'] = groom_form
            context['BrideModelForm'] = bride_form
            context['SponsorFormset'] = sponsor_formset
            context['InvoiceModelForm_Application'] = invoice_form
            context['InvoiceItemModelForm_Application'] = invoice_item_form
            context['Submit_Form'] = Submit_Form()
            return render(request, "sacrament/application_marriage.html",
                          context)
    else:
        suggested_price = ItemType.objects.get(name="Marriage").suggested_price
        context['MarriageModelForm'] = MarriageModelForm(prefix="marriage")
        context['GroomModelForm'] = ProfileModelForm(
            initial={'gender': Profile.MALE}, prefix="groom")
        context['BrideModelForm'] = ProfileModelForm(
            initial={'gender': Profile.FEMALE}, prefix="bride")
        context['SponsorFormset'] = SponsorFormset()
        context['InvoiceModelForm_Application'] = InvoiceModelForm_Application(
            prefix="invoice")
        context[
            'InvoiceItemModelForm_Application'] = InvoiceItemModelForm_Application(
                prefix="invoice_item", initial={'balance': suggested_price})
        context['Submit_Form'] = Submit_Form()
        return render(request, "sacrament/application_marriage.html", context)