mirror of
https://github.com/pretix/pretix.git
synced 2026-05-06 15:24:02 +00:00
Pluggable invoice transmission methods (#5020)
* Flexible invoice transmission
* UI work
* Add peppol and output
* API support
* Profile integration
* Simplify form for individuals
* Remove sent_to_customer usage
* more steps
* Revert "Bank transfer: Allow to send the invoice direclty to the accounting department (#2975)"
This reverts commit cea6c340be.
* minor fixes
* Fixes after rebase
* update stati
* Backend view
* Transmit and show status
* status, retransmission
* API retransmission
* More fields
* API docs
* Plugin docs
* Update migration
* Add missing license headers
* Remove dead code, fix current tests
* Run isort
* Update regex
* Rebase migration
* Fix migration
* Add tests, fix bugs
* Rebase migration
* Apply suggestion from @luelista
Co-authored-by: luelista <weller@rami.io>
* Apply suggestion from @luelista
Co-authored-by: luelista <weller@rami.io>
* Apply suggestion from @luelista
Co-authored-by: luelista <weller@rami.io>
* Apply suggestion from @luelista
Co-authored-by: luelista <weller@rami.io>
* Apply suggestion from @luelista
Co-authored-by: luelista <weller@rami.io>
* Make migration reversible
* Add TransmissionType.enforce_transmission
* Fix registries API usage after rebase
* Remove code I forgot to delete
* Update transmission status display depending on type
* Add testmode_supported
* Update src/pretix/static/pretixbase/js/addressform.js
Co-authored-by: luelista <weller@rami.io>
* Update src/pretix/static/pretixbase/js/addressform.js
Co-authored-by: luelista <weller@rami.io>
* Update src/pretix/static/pretixbase/js/addressform.js
Co-authored-by: luelista <weller@rami.io>
* New mechanism for non-required invoice forms
* Update src/pretix/base/invoicing/transmission.py
Co-authored-by: luelista <weller@rami.io>
* Declare testmode_supported for email
* Make transmission_email_other an implementation detail
* Fix failing tests and add new ones
* Update src/pretix/base/services/invoices.py
Co-authored-by: luelista <weller@rami.io>
* Add emails to email history
* Fix comma error
* More generic default email text
* Cleanup
* Remove "email invoices" button and refine logic
* Rebase migration
* Fix edge case
---------
Co-authored-by: luelista <weller@rami.io>
This commit is contained in:
234
src/tests/base/test_js_helpers.py
Normal file
234
src/tests/base/test_js_helpers.py
Normal file
@@ -0,0 +1,234 @@
|
||||
#
|
||||
# This file is part of pretix (Community Edition).
|
||||
#
|
||||
# Copyright (C) 2014-2020 Raphael Michel and contributors
|
||||
# Copyright (C) 2020-2021 rami.io GmbH and contributors
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General
|
||||
# Public License as published by the Free Software Foundation in version 3 of the License.
|
||||
#
|
||||
# ADDITIONAL TERMS APPLY: Pursuant to Section 7 of the GNU Affero General Public License, additional terms are
|
||||
# applicable granting you additional permissions and placing additional restrictions on your usage of this software.
|
||||
# Please refer to the pretix LICENSE file to obtain the full terms applicable to this work. If you did not receive
|
||||
# this file, see <https://pretix.eu/about/en/license>.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License along with this program. If not, see
|
||||
# <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
import pytest
|
||||
from django.utils.timezone import now
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
from pretix.base.models import Event, Organizer
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_no_invoice_address(client):
|
||||
response = client.get('/js_helpers/address_form/?country=DE')
|
||||
assert response.json() == {
|
||||
'city': {'required': 'if_any'},
|
||||
'data': [],
|
||||
'state': {'label': 'State', 'required': False, 'visible': False},
|
||||
'street': {'required': 'if_any'},
|
||||
'vat_id': {'required': False, 'visible': True},
|
||||
'zipcode': {'required': 'if_any'}
|
||||
}
|
||||
|
||||
response = client.get('/js_helpers/address_form/?country=CR')
|
||||
assert response.json() == {
|
||||
'city': {'required': False},
|
||||
'data': [],
|
||||
'state': {'label': 'State', 'required': False, 'visible': False},
|
||||
'street': {'required': 'if_any'},
|
||||
'vat_id': {'required': False, 'visible': False},
|
||||
'zipcode': {'required': False}
|
||||
}
|
||||
|
||||
response = client.get('/js_helpers/address_form/?country=US')
|
||||
d = response.json()
|
||||
assert d['state'] == {'label': 'State', 'required': 'if_any', 'visible': True}
|
||||
assert d['data'][0] == {'code': 'AL', 'name': 'Alabama'}
|
||||
|
||||
response = client.get('/js_helpers/address_form/?country=IT')
|
||||
d = response.json()
|
||||
assert d['state'] == {'label': 'Province', 'required': 'if_any', 'visible': True}
|
||||
assert d['data'][0] == {'code': 'AG', 'name': 'Agrigento'}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@scopes_disabled()
|
||||
def event():
|
||||
o = Organizer.objects.create(name='Dummy', slug='org')
|
||||
event = Event.objects.create(
|
||||
organizer=o, name='Dummy', slug='ev',
|
||||
date_from=now(), plugins='tests.testdummy'
|
||||
)
|
||||
return event
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_invalid_event(client):
|
||||
response = client.get(
|
||||
'/js_helpers/address_form/?country=DE&invoice=true&organizer=test&event=test'
|
||||
)
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_provider_only_email_available(client, event):
|
||||
response = client.get(
|
||||
'/js_helpers/address_form/?country=DE&invoice=true&organizer=org&event=ev&transmission_type_required=true'
|
||||
)
|
||||
assert response.status_code == 200
|
||||
d = response.json()
|
||||
assert d == {
|
||||
'city': {'required': 'if_any'},
|
||||
'data': [],
|
||||
'state': {'label': 'State', 'required': False, 'visible': False},
|
||||
'street': {'required': 'if_any'},
|
||||
'transmission_email_address': {'required': False, 'visible': False},
|
||||
'transmission_email_other': {'required': False, 'visible': False},
|
||||
'transmission_it_sdi_codice_fiscale': {'required': False, 'visible': False},
|
||||
'transmission_it_sdi_pec': {'required': False, 'visible': False},
|
||||
'transmission_it_sdi_recipient_code': {'required': False, 'visible': False},
|
||||
'transmission_peppol_participant_id': {'required': False, 'visible': False},
|
||||
'transmission_type': {'visible': False},
|
||||
'transmission_types': [{'code': 'email', 'name': 'Email'}],
|
||||
'vat_id': {'required': False, 'visible': True},
|
||||
'zipcode': {'required': 'if_any'}
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_provider_italy_sdi_not_enforced_when_optional(client, event):
|
||||
response = client.get(
|
||||
'/js_helpers/address_form/?country=IT&invoice=true&organizer=org&event=ev&transmission_type_required=false'
|
||||
)
|
||||
assert response.status_code == 200
|
||||
d = response.json()
|
||||
del d['data']
|
||||
assert d == {
|
||||
'city': {'required': 'if_any'},
|
||||
'state': {'label': 'Province', 'required': 'if_any', 'visible': True},
|
||||
'street': {'required': 'if_any'},
|
||||
'transmission_email_address': {'required': False, 'visible': False},
|
||||
'transmission_email_other': {'required': False, 'visible': False},
|
||||
'transmission_it_sdi_codice_fiscale': {'required': False, 'visible': False},
|
||||
'transmission_it_sdi_pec': {'required': False, 'visible': False},
|
||||
'transmission_it_sdi_recipient_code': {'required': False, 'visible': False},
|
||||
'transmission_peppol_participant_id': {'required': False, 'visible': False},
|
||||
'transmission_type': {'visible': True},
|
||||
'transmission_types': [{'code': 'it_sdi', 'name': 'Exchange System (SdI)'}],
|
||||
'vat_id': {'required': False, 'visible': True},
|
||||
'zipcode': {'required': 'if_any'}
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_provider_italy_sdi_enforced_individual(client, event):
|
||||
response = client.get(
|
||||
'/js_helpers/address_form/?country=IT&invoice=true&organizer=org&event=ev&transmission_type_required=true'
|
||||
)
|
||||
assert response.status_code == 200
|
||||
d = response.json()
|
||||
del d['data']
|
||||
assert d == {
|
||||
'city': {'required': True},
|
||||
'state': {'label': 'Province', 'required': True, 'visible': True},
|
||||
'street': {'required': True},
|
||||
'transmission_email_address': {'required': False, 'visible': False},
|
||||
'transmission_email_other': {'required': False, 'visible': False},
|
||||
'transmission_it_sdi_codice_fiscale': {'required': True, 'visible': True},
|
||||
'transmission_it_sdi_pec': {'required': False, 'visible': True},
|
||||
'transmission_it_sdi_recipient_code': {'required': False, 'visible': False},
|
||||
'transmission_peppol_participant_id': {'required': False, 'visible': False},
|
||||
'transmission_type': {'visible': True},
|
||||
'transmission_types': [{'code': 'it_sdi', 'name': 'Exchange System (SdI)'}],
|
||||
'vat_id': {'required': False, 'visible': True},
|
||||
'zipcode': {'required': True}
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_provider_italy_sdi_enforced_business(client, event):
|
||||
response = client.get(
|
||||
'/js_helpers/address_form/?country=IT&invoice=true&organizer=org&event=ev&transmission_type_required=true'
|
||||
'&is_business=business'
|
||||
)
|
||||
assert response.status_code == 200
|
||||
d = response.json()
|
||||
del d['data']
|
||||
assert d == {
|
||||
'city': {'required': True},
|
||||
'state': {'label': 'Province', 'required': True, 'visible': True},
|
||||
'street': {'required': True},
|
||||
'transmission_email_address': {'required': False, 'visible': False},
|
||||
'transmission_email_other': {'required': False, 'visible': False},
|
||||
'transmission_it_sdi_codice_fiscale': {'required': False, 'visible': True},
|
||||
'transmission_it_sdi_pec': {'required': True, 'visible': True},
|
||||
'transmission_it_sdi_recipient_code': {'required': True, 'visible': True},
|
||||
'transmission_peppol_participant_id': {'required': False, 'visible': False},
|
||||
'transmission_type': {'visible': True},
|
||||
'transmission_types': [{'code': 'it_sdi', 'name': 'Exchange System (SdI)'}],
|
||||
'vat_id': {'required': True, 'visible': True},
|
||||
'zipcode': {'required': True}
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_email_peppol_choice(client, event):
|
||||
response = client.get(
|
||||
'/js_helpers/address_form/?country=DE&invoice=true&organizer=org&event=ev'
|
||||
'&is_business=business&transmission_type_required=true'
|
||||
)
|
||||
assert response.status_code == 200
|
||||
d = response.json()
|
||||
assert d == {
|
||||
'city': {'required': 'if_any'},
|
||||
'data': [],
|
||||
'state': {'label': 'State', 'required': False, 'visible': False},
|
||||
'street': {'required': 'if_any'},
|
||||
'transmission_email_address': {'required': False, 'visible': True},
|
||||
'transmission_email_other': {'required': False, 'visible': True},
|
||||
'transmission_it_sdi_codice_fiscale': {'required': False, 'visible': False},
|
||||
'transmission_it_sdi_pec': {'required': False, 'visible': False},
|
||||
'transmission_it_sdi_recipient_code': {'required': False, 'visible': False},
|
||||
'transmission_peppol_participant_id': {'required': False, 'visible': False},
|
||||
'transmission_type': {'visible': True},
|
||||
'transmission_types': [
|
||||
{'code': 'email', 'name': 'Email'},
|
||||
{'code': 'peppol', 'name': 'PEPPOL'},
|
||||
],
|
||||
'vat_id': {'required': False, 'visible': True},
|
||||
'zipcode': {'required': 'if_any'}
|
||||
}
|
||||
|
||||
response = client.get(
|
||||
'/js_helpers/address_form/?country=DE&invoice=true&organizer=org&event=ev'
|
||||
'&is_business=business&transmission_type=peppol'
|
||||
)
|
||||
assert response.status_code == 200
|
||||
d = response.json()
|
||||
assert d == {
|
||||
'city': {'required': True},
|
||||
'data': [],
|
||||
'state': {'label': 'State', 'required': False, 'visible': False},
|
||||
'street': {'required': True},
|
||||
'transmission_email_address': {'required': False, 'visible': False},
|
||||
'transmission_email_other': {'required': False, 'visible': False},
|
||||
'transmission_it_sdi_codice_fiscale': {'required': False, 'visible': False},
|
||||
'transmission_it_sdi_pec': {'required': False, 'visible': False},
|
||||
'transmission_it_sdi_recipient_code': {'required': False, 'visible': False},
|
||||
'transmission_peppol_participant_id': {'required': True, 'visible': True},
|
||||
'transmission_type': {'visible': True},
|
||||
'transmission_types': [
|
||||
{'code': 'email', 'name': 'Email'},
|
||||
{'code': 'peppol', 'name': 'PEPPOL'},
|
||||
],
|
||||
'vat_id': {'required': False, 'visible': True},
|
||||
'zipcode': {'required': True}
|
||||
}
|
||||
@@ -34,12 +34,13 @@ from django.utils.timezone import make_aware, now
|
||||
from django_countries.fields import Country
|
||||
from django_scopes import scope
|
||||
from freezegun import freeze_time
|
||||
from i18nfield.strings import LazyI18nString
|
||||
from tests.testdummy.signals import FoobazSalesChannel
|
||||
|
||||
from pretix.base.decimal import round_decimal
|
||||
from pretix.base.models import (
|
||||
CartPosition, Event, GiftCard, InvoiceAddress, Item, Order, OrderPosition,
|
||||
Organizer, SeatingPlan,
|
||||
CartPosition, Event, GiftCard, Invoice, InvoiceAddress, Item, Order,
|
||||
OrderPosition, Organizer, SeatingPlan,
|
||||
)
|
||||
from pretix.base.models.items import SubEventItem
|
||||
from pretix.base.models.orders import OrderFee, OrderPayment, OrderRefund
|
||||
@@ -48,7 +49,9 @@ from pretix.base.payment import (
|
||||
)
|
||||
from pretix.base.reldate import RelativeDate, RelativeDateWrapper
|
||||
from pretix.base.secrets import assign_ticket_secret
|
||||
from pretix.base.services.invoices import generate_invoice
|
||||
from pretix.base.services.invoices import (
|
||||
generate_cancellation, generate_invoice,
|
||||
)
|
||||
from pretix.base.services.orders import (
|
||||
OrderChangeManager, OrderError, _create_order, approve_order, cancel_order,
|
||||
deny_order, expire_orders, reactivate_order, send_download_reminders,
|
||||
@@ -573,6 +576,83 @@ def test_approve_send_to_attendees(event):
|
||||
assert 'awaiting payment' not in djmail.outbox[1].subject
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_approve_mail_invoice_attached(event):
|
||||
djmail.outbox = []
|
||||
event.settings.invoice_address_asked = True
|
||||
event.settings.invoice_address_required = True
|
||||
event.settings.invoice_generate = "True"
|
||||
event.settings.invoice_email_attachment = True
|
||||
o1 = Order.objects.create(
|
||||
code='FOO', event=event, email='dummy@dummy.test',
|
||||
status=Order.STATUS_PENDING,
|
||||
datetime=now(), expires=now() - timedelta(days=10),
|
||||
total=10, require_approval=True, locale='en',
|
||||
sales_channel=event.organizer.sales_channels.get(identifier="web"),
|
||||
)
|
||||
ticket = Item.objects.create(event=event, name='Early-bird ticket',
|
||||
default_price=Decimal('23.00'), admission=True)
|
||||
OrderPosition.objects.create(
|
||||
order=o1, item=ticket, variation=None, price=Decimal("23.00"),
|
||||
attendee_name_parts={'full_name': "Peter"},
|
||||
positionid=1
|
||||
)
|
||||
InvoiceAddress.objects.create(
|
||||
order=o1,
|
||||
is_business=True,
|
||||
country=Country('AT'),
|
||||
transmission_type="email",
|
||||
transmission_info={}
|
||||
)
|
||||
o1.create_transactions()
|
||||
assert o1.transactions.count() == 0
|
||||
approve_order(o1)
|
||||
o1.refresh_from_db()
|
||||
assert len(djmail.outbox) == 1
|
||||
assert any(["Invoice_" in a[0] for a in djmail.outbox[0].attachments])
|
||||
|
||||
|
||||
@pytest.mark.django_db(transaction=True)
|
||||
def test_approve_mail_invoice_sent_somewhere_else(event):
|
||||
djmail.outbox = []
|
||||
event.settings.invoice_address_asked = True
|
||||
event.settings.invoice_address_required = True
|
||||
event.settings.invoice_generate = "True"
|
||||
event.settings.invoice_email_attachment = True
|
||||
o1 = Order.objects.create(
|
||||
code='FOO', event=event, email='dummy@dummy.test',
|
||||
status=Order.STATUS_PENDING,
|
||||
datetime=now(), expires=now() - timedelta(days=10),
|
||||
total=10, require_approval=True, locale='en',
|
||||
sales_channel=event.organizer.sales_channels.get(identifier="web"),
|
||||
)
|
||||
ticket = Item.objects.create(event=event, name='Early-bird ticket',
|
||||
default_price=Decimal('23.00'), admission=True)
|
||||
OrderPosition.objects.create(
|
||||
order=o1, item=ticket, variation=None, price=Decimal("23.00"),
|
||||
attendee_name_parts={'full_name': "Peter"},
|
||||
positionid=1
|
||||
)
|
||||
InvoiceAddress.objects.create(
|
||||
order=o1,
|
||||
is_business=True,
|
||||
country=Country('AT'),
|
||||
transmission_type="email",
|
||||
transmission_info={
|
||||
"transmission_email_address": "invoice@example.org",
|
||||
}
|
||||
)
|
||||
o1.create_transactions()
|
||||
assert o1.transactions.count() == 0
|
||||
approve_order(o1)
|
||||
o1.refresh_from_db()
|
||||
assert len(djmail.outbox) == 2
|
||||
assert ["invoice@example.org"] == djmail.outbox[0].to
|
||||
assert any(["Invoice_" in a[0] for a in djmail.outbox[0].attachments])
|
||||
assert ["dummy@dummy.test"] == djmail.outbox[1].to
|
||||
assert not any(["Invoice_" in a[0] for a in djmail.outbox[1].attachments])
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_approve_free(event):
|
||||
djmail.outbox = []
|
||||
@@ -670,6 +750,67 @@ def test_deny(event):
|
||||
assert 'denied' in djmail.outbox[0].subject
|
||||
|
||||
|
||||
@pytest.mark.django_db(transaction=True)
|
||||
def test_mark_invoices_as_sent(event):
|
||||
djmail.outbox = []
|
||||
event.settings.invoice_address_asked = True
|
||||
event.settings.invoice_address_required = True
|
||||
event.settings.invoice_generate = "True"
|
||||
event.settings.invoice_email_attachment = True
|
||||
o1 = Order.objects.create(
|
||||
code='FOO', event=event, email='dummy@dummy.test',
|
||||
status=Order.STATUS_PENDING,
|
||||
datetime=now(), expires=now() - timedelta(days=10),
|
||||
total=10, locale='en',
|
||||
sales_channel=event.organizer.sales_channels.get(identifier="web"),
|
||||
)
|
||||
ticket = Item.objects.create(event=event, name='Early-bird ticket',
|
||||
default_price=Decimal('23.00'), admission=True)
|
||||
OrderPosition.objects.create(
|
||||
order=o1, item=ticket, variation=None, price=Decimal("23.00"),
|
||||
attendee_name_parts={'full_name': "Peter"},
|
||||
positionid=1
|
||||
)
|
||||
ia = InvoiceAddress.objects.create(
|
||||
order=o1,
|
||||
is_business=True,
|
||||
country=Country('AT'),
|
||||
transmission_type="email",
|
||||
transmission_info={
|
||||
"transmission_email_address": "invoice@example.org",
|
||||
}
|
||||
)
|
||||
o1.create_transactions()
|
||||
i = generate_invoice(o1)
|
||||
assert i.transmission_type == "email"
|
||||
assert i.transmission_status == Invoice.TRANSMISSION_STATUS_PENDING
|
||||
assert not i.transmission_provider
|
||||
|
||||
# Not marked as sent because it is not the right address
|
||||
o1.send_mail(
|
||||
subject=LazyI18nString({"en": "Hey"}),
|
||||
template=LazyI18nString({"en": "Just wanted to send this invoice"}),
|
||||
context={},
|
||||
invoices=[i]
|
||||
)
|
||||
i.refresh_from_db()
|
||||
assert i.transmission_type == "email"
|
||||
assert i.transmission_status == Invoice.TRANSMISSION_STATUS_PENDING
|
||||
|
||||
# If no other address is there, order address will be accepted
|
||||
ia.transmission_info = {}
|
||||
ia.save()
|
||||
o1.send_mail(
|
||||
subject=LazyI18nString({"en": "Hey"}),
|
||||
template=LazyI18nString({"en": "Just wanted to send this invoice"}),
|
||||
context={},
|
||||
invoices=[i]
|
||||
)
|
||||
i.refresh_from_db()
|
||||
assert i.transmission_status == Invoice.TRANSMISSION_STATUS_COMPLETED
|
||||
assert i.transmission_provider == "email_pdf"
|
||||
|
||||
|
||||
class PaymentReminderTests(TestCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
@@ -1033,6 +1174,12 @@ class DownloadReminderTests(TestCase):
|
||||
assert len(djmail.outbox) == 0
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def class_monkeypatch(request, monkeypatch):
|
||||
request.cls.monkeypatch = monkeypatch
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("class_monkeypatch")
|
||||
class OrderCancelTests(TestCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
@@ -1060,6 +1207,7 @@ class OrderCancelTests(TestCase):
|
||||
self.order.create_transactions()
|
||||
generate_invoice(self.order)
|
||||
djmail.outbox = []
|
||||
self.monkeypatch.setattr("django.db.transaction.on_commit", lambda t: t())
|
||||
|
||||
@classscope(attr='o')
|
||||
def test_cancel_canceled(self):
|
||||
@@ -1111,6 +1259,56 @@ class OrderCancelTests(TestCase):
|
||||
assert self.order.transactions.count() == 4
|
||||
assert self.order.transactions.aggregate(s=Sum(F('price') * F('count')))['s'] == Decimal('0.00')
|
||||
|
||||
@classscope(attr='o')
|
||||
def test_cancel_mail_invoice_attached(self):
|
||||
self.event.settings.invoice_generate = "True"
|
||||
self.event.settings.invoice_email_attachment = True
|
||||
InvoiceAddress.objects.update_or_create(
|
||||
order=self.order,
|
||||
defaults=dict(
|
||||
is_business=True,
|
||||
country=Country('AT'),
|
||||
transmission_type="email",
|
||||
transmission_info={}
|
||||
)
|
||||
)
|
||||
self.order.status = Order.STATUS_PAID
|
||||
self.order.save()
|
||||
djmail.outbox = []
|
||||
cancel_order(self.order.pk, send_mail=True)
|
||||
assert len(djmail.outbox) == 1
|
||||
assert any(["Invoice_" in a[0] for a in djmail.outbox[0].attachments])
|
||||
|
||||
@classscope(attr='o')
|
||||
def test_cancel_mail_invoice_sent_somewhere_else(self):
|
||||
self.event.settings.invoice_generate = "True"
|
||||
self.event.settings.invoice_email_attachment = True
|
||||
InvoiceAddress.objects.update_or_create(
|
||||
order=self.order,
|
||||
defaults=dict(
|
||||
is_business=True,
|
||||
country=Country('AT'),
|
||||
transmission_type="email",
|
||||
transmission_info={
|
||||
"transmission_email_address": "invoice@example.org",
|
||||
}
|
||||
)
|
||||
)
|
||||
# Recreate invoice because otherwise it will be sent where the original was sent
|
||||
generate_cancellation(self.order.invoices.get())
|
||||
generate_invoice(self.order)
|
||||
self.order.status = Order.STATUS_PAID
|
||||
self.order.save()
|
||||
djmail.outbox = []
|
||||
cancel_order(self.order.pk, send_mail=True)
|
||||
print([s.subject for s in djmail.outbox])
|
||||
print([s.to for s in djmail.outbox])
|
||||
assert len(djmail.outbox) == 2
|
||||
assert ["invoice@example.org"] == djmail.outbox[0].to
|
||||
assert any(["Invoice_" in a[0] for a in djmail.outbox[0].attachments])
|
||||
assert ["dummy@dummy.test"] == djmail.outbox[1].to
|
||||
assert not any(["Invoice_" in a[0] for a in djmail.outbox[1].attachments])
|
||||
|
||||
@classscope(attr='o')
|
||||
def test_cancel_paid_with_too_high_fee(self):
|
||||
self.order.status = Order.STATUS_PAID
|
||||
@@ -1239,6 +1437,7 @@ class OrderCancelTests(TestCase):
|
||||
assert self.order.all_logentries().filter(action_type='pretix.event.order.refund.requested').exists()
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("class_monkeypatch")
|
||||
class OrderChangeManagerTests(TestCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
@@ -1247,6 +1446,7 @@ class OrderChangeManagerTests(TestCase):
|
||||
self.event = Event.objects.create(organizer=self.o, name='Dummy', slug='dummy', date_from=now(),
|
||||
plugins='pretix.plugins.banktransfer')
|
||||
self.event.settings.invoice_generate = "True"
|
||||
self.event.settings.invoice_email_attachment = True
|
||||
self.order = Order.objects.create(
|
||||
code='FOO', event=self.event, email='dummy@dummy.test',
|
||||
status=Order.STATUS_PENDING, locale='en',
|
||||
@@ -1301,6 +1501,7 @@ class OrderChangeManagerTests(TestCase):
|
||||
self.seat_a1 = self.event.seats.create(seat_number="A1", product=self.stalls, seat_guid="A1")
|
||||
self.seat_a2 = self.event.seats.create(seat_number="A2", product=self.stalls, seat_guid="A2")
|
||||
self.seat_a3 = self.event.seats.create(seat_number="A3", product=self.stalls, seat_guid="A3")
|
||||
self.monkeypatch.setattr("django.db.transaction.on_commit", lambda t: t())
|
||||
|
||||
def _enable_reverse_charge(self):
|
||||
self.tr7.eu_reverse_charge = True
|
||||
@@ -3525,6 +3726,79 @@ class OrderChangeManagerTests(TestCase):
|
||||
assert self.op1.valid_from is None
|
||||
assert self.op1.valid_until is None
|
||||
|
||||
@classscope(attr='o')
|
||||
def test_new_invoice_attached(self):
|
||||
generate_invoice(self.order)
|
||||
assert self.order.invoices.count() == 1
|
||||
djmail.outbox = []
|
||||
self.ocm.add_position(self.ticket, None, Decimal('0.00'))
|
||||
self.ocm.commit()
|
||||
assert self.order.invoices.count() == 3
|
||||
assert len(djmail.outbox) == 1
|
||||
assert len(["Invoice_" in a[0] for a in djmail.outbox[0].attachments]) == 2
|
||||
|
||||
@classscope(attr='o')
|
||||
def test_new_invoice_send_somewhere_else(self):
|
||||
generate_invoice(self.order)
|
||||
assert self.order.invoices.count() == 1
|
||||
|
||||
InvoiceAddress.objects.update_or_create(
|
||||
order=self.order,
|
||||
defaults=dict(
|
||||
is_business=True,
|
||||
country=Country('AT'),
|
||||
transmission_type="email",
|
||||
transmission_info={
|
||||
"transmission_email_address": "invoice@example.org",
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
djmail.outbox = []
|
||||
self.ocm.add_position(self.ticket, None, Decimal('0.00'))
|
||||
self.ocm.commit()
|
||||
assert self.order.invoices.count() == 3
|
||||
|
||||
# Cancellation is still sent to old method!
|
||||
assert len(djmail.outbox) == 2
|
||||
assert ["dummy@dummy.test"] == djmail.outbox[0].to
|
||||
assert len(["Invoice_" in a[0] for a in djmail.outbox[0].attachments]) == 1
|
||||
assert ["invoice@example.org"] == djmail.outbox[1].to
|
||||
assert len(["Invoice_" in a[0] for a in djmail.outbox[1].attachments]) == 1
|
||||
|
||||
@classscope(attr='o')
|
||||
def test_new_invoice_split_send_somewhere_else(self):
|
||||
generate_invoice(self.order)
|
||||
assert self.order.invoices.count() == 1
|
||||
|
||||
InvoiceAddress.objects.update_or_create(
|
||||
order=self.order,
|
||||
defaults=dict(
|
||||
is_business=True,
|
||||
country=Country('AT'),
|
||||
transmission_type="email",
|
||||
transmission_info={
|
||||
"transmission_email_address": "invoice@example.org",
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
djmail.outbox = []
|
||||
self.ocm.split(self.op2)
|
||||
self.ocm.commit()
|
||||
assert self.order.invoices.count() == 3
|
||||
|
||||
# Cancellation is still sent to old method!
|
||||
assert len(djmail.outbox) == 4
|
||||
assert ["dummy@dummy.test"] == djmail.outbox[0].to
|
||||
assert len(["Invoice_" in a[0] for a in djmail.outbox[0].attachments]) == 1
|
||||
assert ["dummy@dummy.test"] == djmail.outbox[1].to
|
||||
assert len(["Invoice_" in a[0] for a in djmail.outbox[1].attachments]) == 0
|
||||
assert ["invoice@example.org"] == djmail.outbox[2].to
|
||||
assert len(["Invoice_" in a[0] for a in djmail.outbox[2].attachments]) == 1
|
||||
assert ["invoice@example.org"] == djmail.outbox[3].to
|
||||
assert len(["Invoice_" in a[0] for a in djmail.outbox[3].attachments]) == 1
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_saleschannel_testmode_restriction(event):
|
||||
|
||||
@@ -208,14 +208,20 @@ def test_invoice_address_shredder(event, order):
|
||||
'pretix.event.order.modified',
|
||||
data={
|
||||
"data": [{"attendee_name": "Hans", "question_1": "Test"}],
|
||||
"invoice_data": {"name": "Peter", "country": "DE", "is_business": False, "internal_reference": "",
|
||||
"state": "",
|
||||
"company": "ACME", "street": "Sesam Street", "city": "Sample City", "zipcode": "12345"}
|
||||
"invoice_data": {
|
||||
"name": "Peter", "country": "DE", "is_business": False, "internal_reference": "",
|
||||
"state": "", "company": "ACME", "street": "Sesam Street", "city": "Sample City", "zipcode": "12345",
|
||||
"transmission_type": "email", "transmission_info": {"transmission_email_address": "other@example.org"}
|
||||
}
|
||||
}
|
||||
)
|
||||
ia = InvoiceAddress.objects.create(
|
||||
company='Acme Company', street='221B Baker Street',
|
||||
zipcode='12345', city='London', country='UK',
|
||||
order=order, transmission_type="email", transmission_info={
|
||||
"transmission_email_address": "other@example.org"
|
||||
}
|
||||
)
|
||||
ia = InvoiceAddress.objects.create(company='Acme Company', street='221B Baker Street',
|
||||
zipcode='12345', city='London', country='UK',
|
||||
order=order)
|
||||
s = InvoiceAddressShredder(event)
|
||||
f = list(s.generate_files())
|
||||
assert json.loads(f[0][2]) == {
|
||||
@@ -233,7 +239,9 @@ def test_invoice_address_shredder(event, order):
|
||||
'street': '221B Baker Street',
|
||||
'vat_id': '',
|
||||
'vat_id_validated': False,
|
||||
'zipcode': '12345'
|
||||
'zipcode': '12345',
|
||||
"transmission_type": "email",
|
||||
"transmission_info": {"transmission_email_address": "other@example.org"}
|
||||
}
|
||||
}
|
||||
s.shred_data()
|
||||
@@ -243,7 +251,9 @@ def test_invoice_address_shredder(event, order):
|
||||
assert l1.parsed_data == {
|
||||
"data": [{"attendee_name": "Hans", "question_1": "Test"}],
|
||||
"invoice_data": {"name": "█", "country": "█", "is_business": False, "internal_reference": "", "company": "█",
|
||||
"street": "█", "city": "█", "zipcode": "█", "state": ""}
|
||||
"street": "█", "city": "█", "zipcode": "█", "state": "",
|
||||
"transmission_type": "email",
|
||||
"transmission_info": {"_shredded": True}}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user