Allow for gt and gte selection of change_allow_user_price (#1746)

This commit is contained in:
Martin Gross
2020-08-07 11:54:27 +02:00
committed by GitHub
parent 7d9220ae3e
commit 750c3c5201
6 changed files with 118 additions and 4 deletions

View File

@@ -0,0 +1,20 @@
from django.db import migrations
def migrate_change_allow_user_price(apps, schema_editor):
# Previously, the "gt" value was meant to represent "greater or equal", which became an issue the moment
# we introduced a "greater" and "greater or equal" option. This migrates any previous "greater or equal"
# selection to the new "gte".
Event_SettingsStore = apps.get_model('pretixbase', 'Event_SettingsStore')
Event_SettingsStore.objects.filter(key="change_allow_user_price", value="gt").update(value="gte")
class Migration(migrations.Migration):
dependencies = [
('pretixbase', '0160_multiple_confirm_texts'),
]
operations = [
migrations.RunPython(migrate_change_allow_user_price, migrations.RunPython.noop),
]

View File

@@ -492,6 +492,10 @@ class Order(LockModel, LoggedModel):
if self.cancellation_requests.exists():
return False
if self.require_approval:
return False
positions = list(
self.positions.all().annotate(
has_variations=Exists(ItemVariation.objects.filter(item_id=OuterRef('item_id'))),

View File

@@ -960,13 +960,14 @@ DEFAULTS = {
)
},
'change_allow_user_price': {
'default': 'gt',
'default': 'gte',
'type': str,
'form_class': forms.ChoiceField,
'serializer_class': serializers.ChoiceField,
'serializer_kwargs': dict(
choices=(
('gt', _('Only allow changes if the resulting price is higher or equal than the previous price.')),
('gte', _('Only allow changes if the resulting price is higher or equal than the previous price.')),
('gt', _('Only allow changes if the resulting price is higher than the previous price.')),
('eq', _('Only allow changes if the resulting price is equal to the previous price.')),
('any', _('Allow changes regardless of price, even if this results in a refund.')),
)
@@ -974,7 +975,8 @@ DEFAULTS = {
'form_kwargs': dict(
label=_("Requirement for changed prices"),
choices=(
('gt', _('Only allow changes if the resulting price is higher or equal than the previous price.')),
('gte', _('Only allow changes if the resulting price is higher or equal than the previous price.')),
('gt', _('Only allow changes if the resulting price is higher than the previous price.')),
('eq', _('Only allow changes if the resulting price is equal to the previous price.')),
('any', _('Allow changes regardless of price, even if this results in a refund.')),
),

View File

@@ -60,7 +60,9 @@ class OrderPositionChangeForm(forms.Form):
invoice_address=invoice_address)
current_price = TaxedPrice(tax=instance.tax_value, gross=instance.price, net=instance.price - instance.tax_value,
name=instance.tax_rule.name if instance.tax_rule else '', rate=instance.tax_rate)
if new_price.gross < current_price.gross and event.settings.change_allow_user_price == 'gt':
if new_price.gross < current_price.gross and event.settings.change_allow_user_price == 'gte':
continue
if new_price.gross <= current_price.gross and event.settings.change_allow_user_price == 'gt':
continue
if new_price.gross != current_price.gross and event.settings.change_allow_user_price == 'eq':
continue