示例#1
0
    def sync_invoices_from_pretix(self, request, **kwargs):
        orders = get_orders(Conference.objects.get(code="pycon12"))
        invoices = get_invoices(Conference.objects.get(code="pycon12"))

        sender = Sender.objects.first()  # TODO: conference based

        orders = {order["code"]: order for order in orders}

        for invoice in invoices:
            order = orders.get(invoice["order"])

            try:
                create_invoice_from_pretix(invoice, sender, order=order)
            except MissingFiscalCodeError:
                self.message_user(
                    request,
                    f'Missing fiscal code for {order["code"]}',
                    level=messages.WARNING,
                )
            except MissingTaxCodeError:
                self.message_user(
                    request,
                    f'Missing tax code for {order["code"]}',
                    level=messages.WARNING,
                )

        self.message_user(request,
                          "Updated all the invoices",
                          level=messages.SUCCESS)

        return redirect("admin:index")
示例#2
0
def test_gets_orders(conference, requests_mock):
    requests_mock.get(
        f"https://pretix/api/organizers/events/orders",
        json={"next": None, "results": []},
    )

    orders = get_orders(conference)

    assert list(orders) == []