'Create a new sale order for self'

def invoice(self):

    new_invoice = SaleOrder()
    try:
        conf = ModuleSetting.get_for_module('treeio.sales', 'default_order_status')[0]
        new_invoice.status = long(conf.value)
    except Exception:
        ss = SaleStatus.objects.all()[0]
        new_invoice.status = ss
    so = SaleSource.objects.all()[0]
    new_invoice.source = so
    new_invoice.client = self.client
    new_invoice.reference = ('Subscription    Invoice    ' + str(datetime.today().strftime('%Y-%m-%d')))
    new_invoice.save()
    try:
        op = self.orderedproduct_set.filter(trash=False).order_by('-date_created')[0]
        opn = OrderedProduct()
        opn.order = new_invoice
        opn.product = self.product
        opn.quantity = op.quantity
        opn.discount = op.discount
        opn.subscription = self
        opn.save()
    except IndexError:
        opn = OrderedProduct()
        opn.order = new_invoice
        opn.product = self.product
        opn.quantity = 1
        opn.subscription = self
        opn.save()
    return new_invoice.reference
