def make_payment_inv_add(user, make_payment, **kwargs): inv = Invoice() # field to be populated to invoice inv.title = "Make Payment Invoice" inv.bill_to = make_payment.first_name + ' ' + make_payment.last_name inv.bill_to_first_name = make_payment.first_name inv.bill_to_last_name = make_payment.last_name inv.bill_to_company = make_payment.company inv.bill_to_address = '%s %s' % (make_payment.address, make_payment.address2) inv.bill_to_city = make_payment.city inv.bill_to_state = make_payment.state inv.bill_to_zip_code = make_payment.zip_code inv.bill_to_country = make_payment.country inv.bill_to_phone = make_payment.phone inv.bill_to_email = make_payment.email inv.ship_to = make_payment.first_name + ' ' + make_payment.last_name inv.ship_to_first_name = make_payment.first_name inv.ship_to_last_name = make_payment.last_name inv.ship_to_company = make_payment.company inv.ship_to_address = '%s %s' % (make_payment.address, make_payment.address2) inv.ship_to_city = make_payment.city inv.ship_to_state = make_payment.state inv.ship_to_zip_code = make_payment.zip_code inv.ship_to_country = make_payment.country inv.ship_to_phone = make_payment.phone inv.ship_to_email = make_payment.email inv.terms = "Due on Receipt" inv.due_date = datetime.now() inv.ship_date = datetime.now() inv.message = 'Thank You.' inv.status = True inv.estimate = True inv.status_detail = 'estimate' inv.object_type = ContentType.objects.get(app_label=make_payment._meta.app_label, model=make_payment._meta.module_name) inv.object_id = make_payment.id inv.subtotal = make_payment.payment_amount inv.total = make_payment.payment_amount inv.balance = make_payment.payment_amount if user and not user.is_anonymous(): inv.set_creator(user) inv.set_owner(user) inv.save(user) # tender the invoice inv.tender(user) make_payment.invoice_id = inv.id return inv
def make_invoice_for_entry(entry, **kwargs): """ Create an invoice for a Form Entry. """ price = entry.pricing.price or kwargs.get('custom_price') price = unicode(price) now = datetime.now() inv = Invoice() inv.title = "%s Invoice" % (entry.form.title) inv.object_type = ContentType.objects.get(app_label=entry._meta.app_label, model=entry._meta.module_name) inv.object_id = entry.id inv.subtotal = price inv.total = price inv.balance = price inv.due_date = now inv.ship_date = now if entry.creator and not entry.creator.is_anonymous(): inv.set_owner(entry.creator) inv.save() return inv
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)
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
def make_payment_inv_add(user, make_payment, **kwargs): inv = Invoice() # field to be populated to invoice inv.title = _("Make Payment Invoice") inv.bill_to = make_payment.first_name + ' ' + make_payment.last_name inv.bill_to_first_name = make_payment.first_name inv.bill_to_last_name = make_payment.last_name inv.bill_to_company = make_payment.company inv.bill_to_address = '%s %s' % (make_payment.address, make_payment.address2) inv.bill_to_city = make_payment.city inv.bill_to_state = make_payment.state inv.bill_to_zip_code = make_payment.zip_code inv.bill_to_country = make_payment.country inv.bill_to_phone = make_payment.phone inv.bill_to_email = make_payment.email inv.ship_to = make_payment.first_name + ' ' + make_payment.last_name inv.ship_to_first_name = make_payment.first_name inv.ship_to_last_name = make_payment.last_name inv.ship_to_company = make_payment.company inv.ship_to_address = '%s %s' % (make_payment.address, make_payment.address2) inv.ship_to_city = make_payment.city or '' inv.ship_to_state = make_payment.state or '' inv.ship_to_zip_code = make_payment.zip_code or '' inv.ship_to_country = make_payment.country or '' inv.ship_to_phone = make_payment.phone or '' inv.ship_to_email = make_payment.email or '' inv.terms = "Due on Receipt" inv.due_date = datetime.now() inv.ship_date = datetime.now() inv.message = 'Thank You.' inv.status = True inv.estimate = True inv.status_detail = 'estimate' inv.object_type = ContentType.objects.get( app_label=make_payment._meta.app_label, model=make_payment._meta.model_name) inv.object_id = make_payment.id inv.subtotal = make_payment.payment_amount inv.total = make_payment.payment_amount inv.balance = make_payment.payment_amount if user and not user.is_anonymous: inv.set_creator(user) inv.set_owner(user) inv.save(user) # tender the invoice inv.tender(user) make_payment.invoice_id = inv.id return inv
def save_invoice(self, *args, **kwargs): status_detail = kwargs.get('status_detail', 'tendered') admin_notes = kwargs.get('admin_notes', None) object_type = ContentType.objects.get(app_label=self._meta.app_label, model=self._meta.module_name) try: # get invoice invoice = Invoice.objects.get( object_type = object_type, object_id = self.pk, ) except ObjectDoesNotExist: # else; create invoice # cannot use get_or_create method # because too many fields are required invoice = Invoice() invoice.object_type = object_type invoice.object_id = self.pk # primary registrant is responsible for billing primary_registrant = self.registrant invoice.bill_to_first_name = primary_registrant.first_name invoice.bill_to_last_name = primary_registrant.last_name invoice.bill_to_company = primary_registrant.company_name invoice.bill_to_phone = primary_registrant.phone invoice.bill_to_email = primary_registrant.email invoice.bill_to_address = primary_registrant.address invoice.bill_to_city = primary_registrant.city invoice.bill_to_state = primary_registrant.state invoice.bill_to_zip_code = primary_registrant.zip invoice.bill_to_country = primary_registrant.country invoice.creator_id = self.creator_id invoice.owner_id = self.owner_id # update invoice with details invoice.title = "Registration %s for Event: %s" % (self.pk, self.event.title) invoice.estimate = True invoice.status_detail = status_detail invoice.subtotal = self.amount_paid invoice.total = self.amount_paid invoice.balance = invoice.total invoice.tender_date = datetime.now() invoice.due_date = datetime.now() invoice.ship_date = datetime.now() invoice.admin_notes = admin_notes invoice.save() self.invoice = invoice self.save() return invoice
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)
def donation_inv_add(user, donation, **kwargs): inv = Invoice() inv.title = "Donation Invoice" inv.bill_to = donation.first_name + ' ' + donation.last_name inv.bill_to_first_name = donation.first_name inv.bill_to_last_name = donation.last_name inv.bill_to_company = donation.company inv.bill_to_address = donation.address inv.bill_to_city = donation.city inv.bill_to_state = donation.state inv.bill_to_zip_code = donation.zip_code inv.bill_to_country = donation.country inv.bill_to_phone = donation.phone inv.bill_to_email = donation.email inv.ship_to = donation.first_name + ' ' + donation.last_name inv.ship_to_first_name = donation.first_name inv.ship_to_last_name = donation.last_name inv.ship_to_company = donation.company inv.ship_to_address = donation.address inv.ship_to_city = donation.city inv.ship_to_state = donation.state inv.ship_to_zip_code = donation.zip_code inv.ship_to_country = donation.country inv.ship_to_phone = donation.phone #self.ship_to_fax = make_payment.fax inv.ship_to_email = donation.email inv.terms = "Due on Receipt" inv.due_date = datetime.now() inv.ship_date = datetime.now() inv.message = 'Thank You.' inv.status = True if donation.donate_to_entity: inv.entity = donation.donate_to_entity inv.estimate = True inv.status_detail = 'tendered' inv.object_type = ContentType.objects.get( app_label=donation._meta.app_label, model=donation._meta.model_name) inv.object_id = donation.id inv.subtotal = donation.donation_amount inv.total = donation.donation_amount inv.balance = donation.donation_amount inv.save(user) donation.invoice = inv return inv
def make_payment_inv_add(user, make_payment, **kwargs): inv = Invoice() # field to be populated to invoice inv.title = "Make Payment Invoice" inv.bill_to = make_payment.first_name + ' ' + make_payment.last_name inv.bill_to_first_name = make_payment.first_name inv.bill_to_last_name = make_payment.last_name inv.bill_to_company = make_payment.company inv.bill_to_address = make_payment.address inv.bill_to_city = make_payment.city inv.bill_to_state = make_payment.state inv.bill_to_zip_code = make_payment.zip_code inv.bill_to_country = make_payment.country inv.bill_to_phone = make_payment.phone inv.bill_to_email = make_payment.email inv.ship_to = make_payment.first_name + ' ' + make_payment.last_name inv.ship_to_first_name = make_payment.first_name inv.ship_to_last_name = make_payment.last_name inv.ship_to_company = make_payment.company inv.ship_to_address = make_payment.address inv.ship_to_city = make_payment.city inv.ship_to_state = make_payment.state inv.ship_to_zip_code = make_payment.zip_code inv.ship_to_country = make_payment.country inv.ship_to_phone = make_payment.phone inv.ship_to_email = make_payment.email inv.terms = "Due on Receipt" inv.due_date = datetime.now() inv.ship_date = datetime.now() inv.message = 'Thank You.' inv.status = True inv.estimate = True inv.status_detail = 'tendered' inv.object_type = ContentType.objects.get( app_label=make_payment._meta.app_label, model=make_payment._meta.module_name) inv.object_id = make_payment.id inv.subtotal = make_payment.payment_amount inv.total = make_payment.payment_amount inv.balance = make_payment.payment_amount inv.save(user) make_payment.invoice_id = inv.id return inv
def donation_inv_add(user, donation, **kwargs): inv = Invoice() inv.title = "Donation Invoice" inv.bill_to = donation.first_name + ' ' + donation.last_name inv.bill_to_first_name = donation.first_name inv.bill_to_last_name = donation.last_name inv.bill_to_company = donation.company inv.bill_to_address = donation.address inv.bill_to_city = donation.city inv.bill_to_state = donation.state inv.bill_to_zip_code = donation.zip_code inv.bill_to_country = donation.country inv.bill_to_phone = donation.phone inv.bill_to_email = donation.email inv.ship_to = donation.first_name + ' ' + donation.last_name inv.ship_to_first_name = donation.first_name inv.ship_to_last_name = donation.last_name inv.ship_to_company = donation.company inv.ship_to_address = donation.address inv.ship_to_city = donation.city inv.ship_to_state = donation.state inv.ship_to_zip_code = donation.zip_code inv.ship_to_country = donation.country inv.ship_to_phone = donation.phone #self.ship_to_fax = make_payment.fax inv.ship_to_email =donation.email inv.terms = "Due on Receipt" inv.due_date = datetime.now() inv.ship_date = datetime.now() inv.message = 'Thank You.' inv.status = True inv.estimate = True inv.status_detail = 'tendered' inv.object_type = ContentType.objects.get(app_label=donation._meta.app_label, model=donation._meta.model_name) inv.object_id = donation.id inv.subtotal = donation.donation_amount inv.total = donation.donation_amount inv.balance = donation.donation_amount inv.save(user) donation.invoice = inv return inv
def make_invoice_for_entry(entry, **kwargs): """ Create an invoice for a Form Entry. """ price = entry.pricing.price if price is None: price = kwargs.get('custom_price') now = datetime.now() inv = Invoice() inv.title = "%s Invoice" % (entry.form.title) inv.object_type = ContentType.objects.get(app_label=entry._meta.app_label, model=entry._meta.model_name) inv.object_id = entry.id inv.subtotal = price inv.total = price inv.balance = price inv.due_date = now inv.ship_date = now tax = 0 if entry.pricing and entry.pricing.taxable: tax = price * entry.pricing.tax_rate total = tax + price inv.tax = tax inv.subtotal = total inv.total = total inv.balance = total if entry.creator and not entry.creator.is_anonymous: inv.set_owner(entry.creator) inv.save() return inv
def job_set_inv_payment(user, job, pricing): if get_setting('module', 'jobs', 'jobsrequirespayment'): if not job.invoice: inv = Invoice() inv.object_type = ContentType.objects.get( app_label=job._meta.app_label, model=job._meta.module_name) inv.object_id = job.id inv.title = "Job Add Invoice" inv.bill_to = job.contact_name first_name = '' last_name = '' if job.contact_name: name_list = job.contact_name.split(' ') if len(name_list) >= 2: first_name = name_list[0] last_name = ' '.join(name_list[1:]) inv.bill_to_first_name = first_name inv.bill_to_last_name = last_name inv.bill_to_company = job.contact_company inv.bill_to_address = job.contact_address inv.bill_to_city = job.contact_city inv.bill_to_state = job.contact_state inv.bill_to_zip_code = job.contact_zip_code inv.bill_to_country = job.contact_country inv.bill_to_phone = job.contact_phone inv.bill_to_fax = job.contact_fax inv.bill_to_email = job.contact_email inv.ship_to = job.contact_name inv.ship_to_first_name = first_name inv.ship_to_last_name = last_name inv.ship_to_company = job.contact_company inv.ship_to_address = job.contact_address inv.ship_to_city = job.contact_city inv.ship_to_state = job.contact_state inv.ship_to_zip_code = job.contact_zip_code inv.ship_to_country = job.contact_country inv.ship_to_phone = job.contact_phone inv.ship_to_fax = job.contact_fax inv.ship_to_email = job.contact_email 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_job_price(user, job, pricing) inv.subtotal = inv.total inv.balance = inv.total inv.estimate = 1 inv.status_detail = 'estimate' inv.save(user) # tender the invoice inv.tender(user) # update job job.invoice = inv job.save() if user.profile.is_superuser: if job.payment_method in [ 'paid - cc', 'paid - check', 'paid - wire transfer' ]: boo_inv = inv.tender(user) # payment payment = Payment() boo = payment.payments_pop_by_invoice_user( user, inv, inv.guid) payment.mark_as_paid() payment.method = job.payment_method payment.save(user) # this will make accounting entry inv.make_payment(user, payment.amount)
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.module_name) inv.object_id = directory.id profile = user.get_profile() inv.title = "Directory Add Invoice" inv.bill_to = '%s %s' % (user.first_name, user.last_name) inv.bill_to_first_name = user.first_name inv.bill_to_last_name = user.last_name inv.bill_to_company = profile.company inv.bill_to_address = profile.address inv.bill_to_city = profile.city inv.bill_to_state = profile.state inv.bill_to_zip_code = profile.zipcode inv.bill_to_country = profile.country inv.bill_to_phone = profile.phone inv.bill_to_fax = profile.fax inv.bill_to_email = user.email inv.ship_to = inv.bill_to inv.ship_to_first_name = user.first_name inv.ship_to_last_name = user.last_name inv.ship_to_company = profile.company inv.ship_to_address = profile.address inv.ship_to_city = profile.city inv.ship_to_state = profile.state inv.ship_to_zip_code = profile.zipcode inv.ship_to_country = profile.country inv.ship_to_phone = profile.phone inv.ship_to_fax = profile.fax inv.ship_to_email = user.email 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' ]: boo_inv = inv.tender(user) # payment payment = Payment() boo = 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)
def corp_memb_inv_add(user, corp_memb, **kwargs): """ Add an invoice for this corporate membership """ renewal = kwargs.get('renewal', False) renewal_total = kwargs.get('renewal_total', 0) renew_entry = kwargs.get('renew_entry', None) if not corp_memb.invoice or renewal: inv = Invoice() if renew_entry: inv.object_type = ContentType.objects.get( app_label=renew_entry._meta.app_label, model=renew_entry._meta.module_name) inv.object_id = renew_entry.id else: inv.object_type = ContentType.objects.get( app_label=corp_memb._meta.app_label, model=corp_memb._meta.module_name) inv.object_id = corp_memb.id inv.title = "Corporate Membership Invoice" if not user.is_anonymous(): inv.bill_to = '%s %s' % (user.first_name, user.last_name) inv.bill_to_first_name = user.first_name inv.bill_to_last_name = user.last_name inv.bill_to_email = user.email else: if corp_memb.anonymous_creator: cmc = corp_memb.anonymous_creator inv.bill_to = '%s %s' % (cmc.first_name, cmc.last_name) inv.bill_to_first_name = cmc.first_name inv.bill_to_last_name = cmc.last_name inv.bill_to_email = cmc.email else: inv.bill_to = corp_memb.name inv.bill_to_company = corp_memb.name inv.bill_to_address = corp_memb.address inv.bill_to_city = corp_memb.city inv.bill_to_state = corp_memb.state inv.bill_to_zip_code = corp_memb.zip inv.bill_to_country = corp_memb.country inv.bill_to_phone = corp_memb.phone inv.ship_to = corp_memb.name inv.ship_to_company = corp_memb.name inv.ship_to_address = corp_memb.address inv.ship_to_city = corp_memb.city inv.ship_to_state = corp_memb.state inv.ship_to_zip_code = corp_memb.zip inv.ship_to_country = corp_memb.country inv.ship_to_phone = corp_memb.phone inv.ship_to_email = corp_memb.email inv.terms = "Due on Receipt" inv.due_date = datetime.now() inv.ship_date = datetime.now() inv.message = 'Thank You.' inv.status = True if not renewal: inv.total = corp_memb.corporate_membership_type.price else: inv.total = renewal_total inv.subtotal = inv.total inv.balance = inv.total inv.estimate = 1 inv.status_detail = 'tendered' inv.save(user) if user.profile.is_superuser: # if offline payment method if not corp_memb.get_payment_method().is_online: inv.tender(user) # tendered the invoice for admin if offline # mark payment as made payment = Payment() payment.payments_pop_by_invoice_user(user, inv, inv.guid) payment.mark_as_paid() payment.method = corp_memb.get_payment_method() payment.save(user) # this will make accounting entry inv.make_payment(user, payment.amount) return inv return None
def corp_memb_inv_add(user, corp_memb, **kwargs): """ Add an invoice for this corporate membership """ corp_profile = corp_memb.corp_profile renewal = kwargs.get('renewal', False) renewal_total = kwargs.get('renewal_total', 0) if not corp_memb.invoice or renewal: inv = Invoice() inv.object_type = ContentType.objects.get( app_label=corp_memb._meta.app_label, model=corp_memb._meta.module_name) inv.object_id = corp_memb.id inv.title = "Corporate Membership Invoice" if not user.is_anonymous(): inv.bill_to = '%s %s' % (user.first_name, user.last_name) inv.bill_to_first_name = user.first_name inv.bill_to_last_name = user.last_name inv.bill_to_email = user.email else: if corp_memb.anonymous_creator: cmc = corp_memb.anonymous_creator inv.bill_to = '%s %s' % (cmc.first_name, cmc.last_name) inv.bill_to_first_name = cmc.first_name inv.bill_to_last_name = cmc.last_name inv.bill_to_email = cmc.email else: inv.bill_to = corp_memb.name inv.bill_to_company = corp_profile.name inv.bill_to_address = corp_profile.address inv.bill_to_city = corp_profile.city inv.bill_to_state = corp_profile.state inv.bill_to_zip_code = corp_profile.zip inv.bill_to_country = corp_profile.country inv.bill_to_phone = corp_profile.phone inv.ship_to = corp_profile.name inv.ship_to_company = corp_profile.name inv.ship_to_address = corp_profile.address inv.ship_to_city = corp_profile.city inv.ship_to_state = corp_profile.state inv.ship_to_zip_code = corp_profile.zip inv.ship_to_country = corp_profile.country inv.ship_to_phone = corp_profile.phone inv.ship_to_email = corp_profile.email inv.terms = "Due on Receipt" inv.due_date = datetime.now() inv.ship_date = datetime.now() inv.message = 'Thank You.' inv.status = True if not renewal: inv.total = corp_memb.corporate_membership_type.price else: inv.total = renewal_total inv.subtotal = inv.total inv.balance = inv.total inv.estimate = 1 inv.status_detail = 'estimate' inv.save(user) if not corp_memb.payment_method: is_online = True if inv.balance <= 0: is_online = False corp_memb.payment_method = corp_memb.get_payment_method( is_online=is_online) if user.profile.is_superuser: # if offline payment method if not corp_memb.payment_method.is_online: inv.tender(user) # tendered the invoice for admin if offline # mark payment as made payment = Payment() payment.payments_pop_by_invoice_user(user, inv, inv.guid) payment.mark_as_paid() payment.method = corp_memb.get_payment_method() payment.save(user) # this will make accounting entry inv.make_payment(user, payment.amount) return inv return None
def job_set_inv_payment(user, job, pricing): if get_setting('module', 'jobs', 'jobsrequirespayment'): if not job.invoice: inv = Invoice() inv.object_type = ContentType.objects.get(app_label=job._meta.app_label, model=job._meta.module_name) inv.object_id = job.id inv.title = "Job Add Invoice" inv.bill_to = job.contact_name first_name = '' last_name = '' if job.contact_name: name_list = job.contact_name.split(' ') if len(name_list) >= 2: first_name = name_list[0] last_name = ' '.join(name_list[1:]) inv.bill_to_first_name = first_name inv.bill_to_last_name = last_name inv.bill_to_company = job.contact_company inv.bill_to_address = job.contact_address inv.bill_to_city = job.contact_city inv.bill_to_state = job.contact_state inv.bill_to_zip_code = job.contact_zip_code inv.bill_to_country = job.contact_country inv.bill_to_phone = job.contact_phone inv.bill_to_fax = job.contact_fax inv.bill_to_email = job.contact_email inv.ship_to = job.contact_name inv.ship_to_first_name = first_name inv.ship_to_last_name = last_name inv.ship_to_company = job.contact_company inv.ship_to_address = job.contact_address inv.ship_to_city = job.contact_city inv.ship_to_state = job.contact_state inv.ship_to_zip_code = job.contact_zip_code inv.ship_to_country = job.contact_country inv.ship_to_phone = job.contact_phone inv.ship_to_fax = job.contact_fax inv.ship_to_email =job.contact_email 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_job_price(user, job, pricing) inv.subtotal = inv.total inv.balance = inv.total inv.estimate = 1 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 job.invoice = inv job.save() if user.profile.is_superuser: if job.payment_method in ['paid - cc', 'paid - check', 'paid - wire transfer']: boo_inv = inv.tender(user) # payment payment = Payment() boo = payment.payments_pop_by_invoice_user(user, inv, inv.guid) payment.mark_as_paid() payment.method = job.payment_method payment.save(user) # this will make accounting entry inv.make_payment(user, payment.amount)
def corp_memb_inv_add(user, corp_memb, app=None, **kwargs): """ Add an invoice for this corporate membership """ corp_profile = corp_memb.corp_profile renewal = kwargs.get('renewal', False) renewal_total = kwargs.get('renewal_total', 0) if not corp_memb.invoice or renewal: inv = Invoice() inv.entity = corp_profile.entity inv.object_type = ContentType.objects.get( app_label=corp_memb._meta.app_label, model=corp_memb._meta.model_name) inv.object_id = corp_memb.id inv.title = corp_memb.corp_profile.name if not user.is_anonymous: inv.bill_to = '%s %s' % (user.first_name, user.last_name) inv.bill_to_first_name = user.first_name inv.bill_to_last_name = user.last_name inv.bill_to_email = user.email inv.set_creator(user) inv.set_owner(user) else: if corp_memb.anonymous_creator: cmc = corp_memb.anonymous_creator inv.bill_to = '%s %s' % (cmc.first_name, cmc.last_name) inv.bill_to_first_name = cmc.first_name inv.bill_to_last_name = cmc.last_name inv.bill_to_email = cmc.email else: inv.bill_to = corp_memb.name inv.bill_to_company = corp_profile.name inv.bill_to_address = corp_profile.address inv.bill_to_city = corp_profile.city inv.bill_to_state = corp_profile.state inv.bill_to_zip_code = corp_profile.zip inv.bill_to_country = corp_profile.country inv.bill_to_phone = corp_profile.phone inv.ship_to = corp_profile.name inv.ship_to_company = corp_profile.name inv.ship_to_address = corp_profile.address inv.ship_to_city = corp_profile.city inv.ship_to_state = corp_profile.state inv.ship_to_zip_code = corp_profile.zip inv.ship_to_country = corp_profile.country inv.ship_to_phone = corp_profile.phone inv.ship_to_email = corp_profile.email inv.terms = "Due on Receipt" inv.due_date = datetime.now() inv.ship_date = datetime.now() inv.message = 'Thank You.' inv.status = True if not renewal: inv.total = corp_memb.corporate_membership_type.price else: inv.total = renewal_total inv.subtotal = inv.total inv.balance = inv.total tax = 0 if app and app.include_tax: tax = inv.total * app.tax_rate inv.tax = tax total = inv.total + tax inv.subtotal = total inv.total = total inv.balance = total inv.estimate = True inv.status_detail = 'estimate' inv.save(user) if not corp_memb.payment_method: is_online = True if inv.balance <= 0: is_online = False corp_memb.payment_method = corp_memb.get_payment_method( is_online=is_online) if user.profile.is_superuser: # if offline payment method if not corp_memb.payment_method.is_online: inv.tender(user) # tendered the invoice for admin if offline # mark payment as made payment = Payment() payment.payments_pop_by_invoice_user(user, inv, inv.guid) payment.mark_as_paid() payment.method = corp_memb.payment_method.machine_name payment.save(user) # this will make accounting entry inv.make_payment(user, payment.amount) return inv return None
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.get_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.module_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 = self.user.get_full_name() inv.bill_to_company = profile.company inv.bill_to_address = profile.address inv.bill_to_city = profile.city inv.bill_to_state = profile.state inv.bill_to_zip_code = profile.zipcode inv.bill_to_country = profile.country inv.bill_to_phone = profile.phone inv.bill_to_email = self.user.email 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
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.module_name) inv.object_id = directory.id profile = user.get_profile() inv.title = "Directory Add Invoice" inv.bill_to = '%s %s' % (user.first_name, user.last_name) inv.bill_to_first_name = user.first_name inv.bill_to_last_name = user.last_name inv.bill_to_company = profile.company inv.bill_to_address = profile.address inv.bill_to_city = profile.city inv.bill_to_state = profile.state inv.bill_to_zip_code = profile.zipcode inv.bill_to_country = profile.country inv.bill_to_phone = profile.phone inv.bill_to_fax = profile.fax inv.bill_to_email = user.email inv.ship_to = inv.bill_to inv.ship_to_first_name = user.first_name inv.ship_to_last_name = user.last_name inv.ship_to_company = profile.company inv.ship_to_address = profile.address inv.ship_to_city = profile.city inv.ship_to_state = profile.state inv.ship_to_zip_code = profile.zipcode inv.ship_to_country = profile.country inv.ship_to_phone = profile.phone inv.ship_to_fax = profile.fax inv.ship_to_email = user.email 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']: boo_inv = inv.tender(user) # payment payment = Payment() boo = 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)