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