예제 #1
0
    def create_holvi_invoice(self, rt, t):
        if t.stamp:
            year = t.stamp.year
            month = t.stamp.month
        else:
            now = datetime.datetime.now()
            year = now.year
            month = now.month

        invoice = holviapi.Invoice(get_invoiceapi())
        invoice.receiver = holviapi.InvoiceContact({
            'email': t.owner.email,
            'name': t.owner.name,
        })
        invoice.items.append(holviapi.InvoiceItem(invoice))

        if rt.rtype == RecurringTransaction.YEARLY:
            invoice.items[0].description = "%s %d" % (t.tag.label, year)
        else:
            invoice.items[0].description = "%s %02d/%d" % (t.tag.label, month, year)

        invoice.items[0].net = -t.amount # Negative amount transaction -> positive amount invoice
        if t.tag.holvi_code:
            invoice.items[0].category = holviapi.IncomeCategory(invoice.api.categories_api, { 'code': t.tag.holvi_code }) # Lazy-loading category, avoids a GET
        invoice.subject = "%s / %s" % (invoice.items[0].description, invoice.receiver.name)

        invoice = invoice.save()
        invoice.send()
        print("Created (and sent) Holvi invoice %s" % invoice.code)
        t.reference = invoice.rf_reference
        return True
def test_create_send_invoice(invoicesapi):
    ni = holviapi.Invoice(invoicesapi)
    ni.receiver.email = os.environ.get('HOLVI_INVOICE_TO')
    ni.receiver.name = "Example Person"
    ni.items.append(holviapi.InvoiceItem(ni))
    ni.items[0].description = "API-test %s" % datetime.datetime.now(
    ).isoformat()
    ni.items[0].net = Decimal("25.50")
    ni.subject = "%s / %s" % (ni.items[0].description, ni.receiver.name)
    resp = ni.save()
    assert resp.code
    resp.send()