Beispiel #1
1
def directory_set_inv_payment(user, directory, pricing):
    if get_setting('module', 'directories', 'directoriesrequirespayment'):
        if not directory.invoice:
            inv = Invoice()
            inv.object_type = ContentType.objects.get(app_label=directory._meta.app_label,
                                              model=directory._meta.model_name)
            inv.object_id = directory.id
            inv.title = "Directory Add Invoice"
            inv.bill_to_user(user)
            inv.ship_to_user(user)

            inv.terms = "Due on Receipt"
            inv.due_date = datetime.now()
            inv.ship_date = datetime.now()
            inv.message = 'Thank You.'
            inv.status = True

            inv.total = get_directory_price(user, directory, pricing)
            inv.subtotal = inv.total
            inv.balance = inv.total
            inv.estimate = True
            inv.status_detail = 'estimate'

            if user and not user.is_anonymous:
                inv.set_creator(user)
                inv.set_owner(user)

            inv.save(user)

            # tender the invoice
            inv.tender(user)

            # update job
            directory.invoice = inv
            directory.save()

            if user.profile.is_superuser:
                if directory.payment_method in ['paid - cc', 'paid - check', 'paid - wire transfer']:
                    inv.tender(user)

                    # payment
                    payment = Payment()
                    payment.payments_pop_by_invoice_user(user, inv, inv.guid)
                    payment.mark_as_paid()
                    payment.method = directory.payment_method
                    payment.save(user)

                    # this will make accounting entry
                    inv.make_payment(user, payment.amount)
Beispiel #2
0
    def create_invoice(self, billing_cycle, billing_dt):
        """
        Create an invoice and update the next_billing_dt for this recurring payment.
        """
        try:
            profile = self.user.profile
        except Profile.DoesNotExist:
            profile = Profile.objects.create_profile(user=self.user)

        if self.within_trial_period():
            amount = self.trial_amount
        else:
            amount = self.payment_amount

        self.next_billing_dt = billing_dt

        self.save()

        inv = Invoice()
        inv.due_date = billing_dt
        inv.ship_date = billing_dt

        inv.object_type = ContentType.objects.get(
            app_label=self._meta.app_label, model=self._meta.model_name)
        inv.object_id = self.id
        inv.title = "Recurring Payment Invoice for Billing Cycle %s - %s" % (
            billing_cycle['start'].strftime('%m/%d/%Y'),
            billing_cycle['end'].strftime('%m/%d/%Y'))
        inv.bill_to_user(self.user)
        inv.status = True

        if self.taxable and self.tax_rate:
            inv.tax = self.tax_rate * amount
        else:
            inv.tax_exempt = 1
            inv.tax = 0

        inv.subtotal = amount
        inv.total = inv.subtotal + inv.tax

        inv.balance = inv.total
        inv.estimate = True
        inv.status_detail = 'estimate'

        inv.set_owner(self.user)

        inv.save(self.user)

        # tender the invoice
        inv.tender(self.user)

        rp_invoice = RecurringPaymentInvoice(
            recurring_payment=self,
            invoice=inv,
            billing_cycle_start_dt=billing_cycle['start'],
            billing_cycle_end_dt=billing_cycle['end'],
            billing_dt=billing_dt)
        rp_invoice.save()

        return rp_invoice
Beispiel #3
0
def directory_set_inv_payment(user, directory, pricing):
    if get_setting('module', 'directories', 'directoriesrequirespayment'):
        if not directory.invoice:
            inv = Invoice()
            inv.object_type = ContentType.objects.get(
                app_label=directory._meta.app_label,
                model=directory._meta.model_name)
            inv.object_id = directory.id
            inv.title = "Directory Add Invoice"
            inv.bill_to_user(user)
            inv.ship_to_user(user)

            inv.terms = "Due on Receipt"
            inv.due_date = datetime.now()
            inv.ship_date = datetime.now()
            inv.message = 'Thank You.'
            inv.status = True

            inv.total = get_directory_price(user, directory, pricing)
            inv.subtotal = inv.total
            inv.balance = inv.total
            inv.estimate = True
            inv.status_detail = 'estimate'

            if user and not user.is_anonymous:
                inv.set_creator(user)
                inv.set_owner(user)

            inv.save(user)

            # tender the invoice
            inv.tender(user)

            # update job
            directory.invoice = inv
            directory.save()

            if user.profile.is_superuser:
                if directory.payment_method in [
                        'paid - cc', 'paid - check', 'paid - wire transfer'
                ]:
                    inv.tender(user)

                    # payment
                    payment = Payment()
                    payment.payments_pop_by_invoice_user(user, inv, inv.guid)
                    payment.mark_as_paid()
                    payment.method = directory.payment_method
                    payment.save(user)

                    # this will make accounting entry
                    inv.make_payment(user, payment.amount)