def create_invoice(org, status=None, paytype=None, bank=None, details=None): # new invoice i = Invoice() i.organization = org i.plan = org.prefered_plan if status: i.status = status i.bank = bank i.payment_type = PaymentType.objects.get(pk=paytype) i.date_payed = date.today() i.start_date = i.date_payed i.end_date = i.start_date + relativedelta(years=5) i.expiry_date = i.start_date + relativedelta(years=5) i.payment_detail = u"gateway code: %s" % details else: i.status = 2 # free i.save() return i
# main code for o in Organization.objects.filter(suspension=False, organization=None, date_created__gte=new_format): inv = [] # invoices to print resume # last invoice li = Invoice.objects.filter(organization=o).latest('id') while li.end_date < date.today()+relativedelta(months=1) and li.start_date < date.today(): i = Invoice() # new invoice i.organization = li.organization i.start_date = li.end_date i.end_date = li.end_date + relativedelta(months=1) i.expiry_date = i.start_date + relativedelta(days=7) i.payment_type = li.organization.payment_type i.ammount = li.organization.prefered_plan.value i.plan = li.organization.prefered_plan i.status = 0 # pendente i.save() li = i # check end_date of new invoice inv.append(i) # print resume to email admin if len(inv) > 0 : print '--- Creating a new invoice: %s' % (o) for x in inv: print '- Start %s End %s Expiry %s' % (x.start_date, x.end_date, x.expiry_date) print
organization=None, date_created__gte=new_format): inv = [] # invoices to print resume # last invoice li = Invoice.objects.filter(organization=o).latest('id') while li.end_date < date.today() + relativedelta( months=1) and li.start_date < date.today(): i = Invoice() # new invoice i.organization = li.organization i.start_date = li.end_date i.end_date = li.end_date + relativedelta(months=1) i.expiry_date = i.start_date + relativedelta(days=7) i.payment_type = li.organization.payment_type i.ammount = li.organization.prefered_plan.value i.plan = li.organization.prefered_plan i.status = 0 # pendente i.save() li = i # check end_date of new invoice inv.append(i) # print resume to email admin if len(inv) > 0: print '--- Creating a new invoice: %s' % (o) for x in inv: print '- Start %s End %s Expiry %s' % (x.start_date, x.end_date, x.expiry_date)