Esempio n. 1
0
def adjust(request, id, form_class=AdminAdjustForm, template_name="invoices/adjust.html"):
    #if not id: return HttpResponseRedirect(reverse('invoice.search'))
    invoice = get_object_or_404(Invoice, pk=id)
    original_total = invoice.total
    original_balance = invoice.balance
    original_variance = invoice.variance

    if not (request.user.profile.is_superuser or has_perm(request.user, 'invoices.change_invoice')): raise Http403

    if request.method == "POST":
        form = form_class(request.POST, instance=invoice)
        if form.is_valid():
            invoice = form.save()
            
            variance_changed = invoice.variance - original_variance
            invoice.total += variance_changed
            invoice.balance = invoice.total - invoice.payments_credits
            invoice.save()

            EventLog.objects.log(instance=invoice)

            notif_context = {
                'request': request,
                'object': invoice,
            }
            send_notifications('module','invoices','invoicerecipients',
                'invoice_edited', notif_context)

            # make accounting entries
            from tendenci.apps.accountings.models import AcctEntry
            ae = AcctEntry.objects.create_acct_entry(request.user, 'invoice', invoice.id)
            if variance_changed < 0:
                from tendenci.apps.accountings.utils import make_acct_entries_discount
                #this is a discount
                opt_d = {}
                opt_d['discount'] = True
                opt_d['original_invoice_total'] = original_total
                opt_d['original_invoice_balance'] = original_balance
                opt_d['discount_account_number'] = 460100

                obj = invoice.get_object()
                if obj and hasattr(obj, 'get_acct_number'):
                    opt_d['discount_account_number'] = obj.get_acct_number(discount=True)

                make_acct_entries_discount(request.user, invoice, ae, opt_d)

            elif variance_changed > 0:
                from tendenci.apps.accountings.utils import make_acct_entries_initial
                make_acct_entries_initial(request.user, ae, variance_changed)

            return HttpResponseRedirect(invoice.get_absolute_url())

    else:
        form = form_class(initial={'variance': invoice.variance, 'variance_notes':invoice.variance_notes})

    return render_to_resp(request=request, template_name=template_name,
        context={'invoice': invoice,
                                              'form':form})
Esempio n. 2
0
def adjust(request, id, form_class=AdminAdjustForm, template_name="invoices/adjust.html"):
    #if not id: return HttpResponseRedirect(reverse('invoice.search'))
    invoice = get_object_or_404(Invoice, pk=id)
    original_total = invoice.total
    original_balance = invoice.balance
    original_variance = invoice.variance

    if not (request.user.profile.is_superuser or has_perm(request.user, 'invoices.change_invoice')): raise Http403

    if request.method == "POST":
        form = form_class(request.POST, instance=invoice)
        if form.is_valid():
            invoice = form.save()
            
            variance_changed = invoice.variance - original_variance
            invoice.total += variance_changed
            invoice.balance = invoice.total - invoice.payments_credits
            invoice.save()

            EventLog.objects.log(instance=invoice)

            notif_context = {
                'request': request,
                'object': invoice,
            }
            send_notifications('module','invoices','invoicerecipients',
                'invoice_edited', notif_context)

            # make accounting entries
            from tendenci.apps.accountings.models import AcctEntry
            ae = AcctEntry.objects.create_acct_entry(request.user, 'invoice', invoice.id)
            if variance_changed < 0:
                from tendenci.apps.accountings.utils import make_acct_entries_discount
                #this is a discount
                opt_d = {}
                opt_d['discount'] = True
                opt_d['original_invoice_total'] = original_total
                opt_d['original_invoice_balance'] = original_balance
                opt_d['discount_account_number'] = 460100

                obj = invoice.get_object()
                if obj and hasattr(obj, 'get_acct_number'):
                    opt_d['discount_account_number'] = obj.get_acct_number(discount=True)

                make_acct_entries_discount(request.user, invoice, ae, opt_d)

            elif variance_changed > 0:
                from tendenci.apps.accountings.utils import make_acct_entries_initial
                make_acct_entries_initial(request.user, ae, variance_changed)

            return HttpResponseRedirect(invoice.get_absolute_url())

    else:
        form = form_class(initial={'variance': invoice.variance, 'variance_notes':invoice.variance_notes})

    return render_to_resp(request=request, template_name=template_name,
        context={'invoice': invoice,
                                              'form':form})
Esempio n. 3
0
def adjust(request, id, form_class=AdminAdjustForm, template_name="invoices/adjust.html"):
    # if not id: return HttpResponseRedirect(reverse('invoice.search'))
    invoice = get_object_or_404(Invoice, pk=id)
    original_total = invoice.total
    original_balance = invoice.balance

    if not (request.user.profile.is_superuser or has_perm(request.user, "invoices.change_invoice")):
        raise Http403

    if request.method == "POST":
        form = form_class(request.POST, instance=invoice)
        if form.is_valid():
            invoice = form.save()
            invoice.total += invoice.variance
            invoice.balance = invoice.total - invoice.payments_credits
            invoice.save()

            EventLog.objects.log(instance=invoice)

            notif_context = {"request": request, "object": invoice}
            send_notifications("module", "invoices", "invoicerecipients", "invoice_edited", notif_context)

            # make accounting entries
            from tendenci.apps.accountings.models import AcctEntry

            ae = AcctEntry.objects.create_acct_entry(request.user, "invoice", invoice.id)
            if invoice.variance < 0:
                from tendenci.apps.accountings.utils import make_acct_entries_discount

                # this is a discount
                opt_d = {}
                opt_d["discount"] = True
                opt_d["original_invoice_total"] = original_total
                opt_d["original_invoice_balance"] = original_balance
                opt_d["discount_account_number"] = 460100

                obj = invoice.get_object()
                if obj and hasattr(obj, "get_acct_number"):
                    opt_d["discount_account_number"] = obj.get_acct_number(discount=True)

                make_acct_entries_discount(request.user, invoice, ae, opt_d)

            else:
                from tendenci.apps.accountings.utils import make_acct_entries_initial

                make_acct_entries_initial(request.user, ae, invoice.variance)

            return HttpResponseRedirect(invoice.get_absolute_url())

    else:
        form = form_class(initial={"variance": 0.00, "variance_notes": invoice.variance_notes})

    return render_to_response(
        template_name, {"invoice": invoice, "form": form}, context_instance=RequestContext(request)
    )
Esempio n. 4
0
    def make_acct_entries(self, user, inv, amount, **kwargs):
        """
        Make the accounting entries for the donation sale
        """
        from tendenci.apps.accountings.models import Acct, AcctEntry, AcctTran
        from tendenci.apps.accountings.utils import make_acct_entries_initial, make_acct_entries_closing

        ae = AcctEntry.objects.create_acct_entry(user, 'invoice', inv.id)
        if not inv.is_tendered:
            make_acct_entries_initial(user, ae, amount)
        else:
            # payment has now been received
            make_acct_entries_closing(user, ae, amount)

            # #CREDIT donation SALES
            acct_number = self.get_acct_number()
            acct = Acct.objects.get(account_number=acct_number)
            AcctTran.objects.create_acct_tran(user, ae, acct, amount*(-1))
Esempio n. 5
0
    def make_acct_entries(self, user, inv, amount, **kwargs):
        """
        Make the accounting entries for the job sale
        """
        from tendenci.apps.accountings.models import Acct, AcctEntry, AcctTran
        from tendenci.apps.accountings.utils import make_acct_entries_initial, make_acct_entries_closing

        ae = AcctEntry.objects.create_acct_entry(user, 'invoice', inv.id)
        if not inv.is_tendered:
            make_acct_entries_initial(user, ae, amount)
        else:
            # payment has now been received
            make_acct_entries_closing(user, ae, amount)

            # #CREDIT job SALES
            acct_number = self.get_acct_number()
            acct = Acct.objects.get(account_number=acct_number)
            AcctTran.objects.create_acct_tran(user, ae, acct, amount * (-1))