forked from CGM_Public/pretix_original
Invoice renderer: Group invoice lines even with addons (Z#23173618) (#4744)
* Invoice renderer: Group invoice lines even with addons (Z#23173618) * Add unit test * Update src/pretix/base/invoice.py Co-authored-by: Mira <weller@rami.io> --------- Co-authored-by: Mira Weller <weller@rami.io>
This commit is contained in:
@@ -38,10 +38,12 @@ from decimal import Decimal
|
||||
|
||||
import pytest
|
||||
from django.db import DatabaseError, transaction
|
||||
from django.utils.itercompat import is_iterable
|
||||
from django.utils.timezone import now
|
||||
from django_countries.fields import Country
|
||||
from django_scopes import scope, scopes_disabled
|
||||
|
||||
from pretix.base.invoice import addon_aware_groupby
|
||||
from pretix.base.models import (
|
||||
Event, ExchangeRate, Invoice, InvoiceAddress, Item, ItemVariation, Order,
|
||||
OrderPosition, Organizer,
|
||||
@@ -606,3 +608,55 @@ def test_sales_channels_qualify(env):
|
||||
|
||||
event.settings.set('invoice_generate_sales_channels', [])
|
||||
assert invoice_qualified(order) is False
|
||||
|
||||
|
||||
def test_addon_aware_groupby():
|
||||
def is_addon(item):
|
||||
is_addon, id, price = item
|
||||
return is_addon
|
||||
|
||||
def key(item):
|
||||
return item
|
||||
|
||||
def listify(it):
|
||||
return [listify(i) if is_iterable(i) else i for i in it]
|
||||
|
||||
assert listify(addon_aware_groupby([
|
||||
(False, 1, 5.00),
|
||||
(False, 1, 5.00),
|
||||
(False, 1, 5.00),
|
||||
(False, 2, 7.00),
|
||||
], key, is_addon)) == [
|
||||
[[False, 1, 5.00], [
|
||||
[False, 1, 5.00],
|
||||
[False, 1, 5.00],
|
||||
[False, 1, 5.00],
|
||||
]],
|
||||
[[False, 2, 7.00], [
|
||||
[False, 2, 7.00],
|
||||
]],
|
||||
]
|
||||
|
||||
assert listify(addon_aware_groupby([
|
||||
(False, 1, 5.00),
|
||||
(True, 101, 2.00),
|
||||
(False, 1, 5.00),
|
||||
(True, 101, 2.00),
|
||||
(False, 1, 5.00),
|
||||
(True, 102, 3.00),
|
||||
], key, is_addon)) == [
|
||||
[[False, 1, 5.00], [
|
||||
[False, 1, 5.00],
|
||||
[False, 1, 5.00],
|
||||
]],
|
||||
[[True, 101, 2.00], [
|
||||
[True, 101, 2.00],
|
||||
[True, 101, 2.00],
|
||||
]],
|
||||
[[False, 1, 5.00], [
|
||||
[False, 1, 5.00],
|
||||
]],
|
||||
[[True, 102, 3.00], [
|
||||
[True, 102, 3.00],
|
||||
]],
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user