Make it optional to notify user on order change

This commit is contained in:
Raphael Michel
2017-10-30 21:24:20 +01:00
parent 5376ce4bdb
commit 429f30fca7
4 changed files with 23 additions and 4 deletions

View File

@@ -658,12 +658,13 @@ class OrderChangeManager:
CancelOperation = namedtuple('CancelOperation', ('position',)) CancelOperation = namedtuple('CancelOperation', ('position',))
AddOperation = namedtuple('AddOperation', ('item', 'variation', 'price', 'addon_to', 'subevent')) AddOperation = namedtuple('AddOperation', ('item', 'variation', 'price', 'addon_to', 'subevent'))
def __init__(self, order: Order, user): def __init__(self, order: Order, user, notify=True):
self.order = order self.order = order
self.user = user self.user = user
self._totaldiff = 0 self._totaldiff = 0
self._quotadiff = Counter() self._quotadiff = Counter()
self._operations = [] self._operations = []
self.notify = notify
self._invoice_dirty = False self._invoice_dirty = False
def change_item(self, position: OrderPosition, item: Item, variation: Optional[ItemVariation]): def change_item(self, position: OrderPosition, item: Item, variation: Optional[ItemVariation]):
@@ -971,7 +972,8 @@ class OrderChangeManager:
self._reissue_invoice() self._reissue_invoice()
self._clear_tickets_cache() self._clear_tickets_cache()
self._check_paid_to_free() self._check_paid_to_free()
self._notify_user() if self.notify:
self._notify_user()
def _clear_tickets_cache(self): def _clear_tickets_cache(self):
CachedTicket.objects.filter(order_position__order=self.order).delete() CachedTicket.objects.filter(order_position__order=self.order).delete()

View File

@@ -90,6 +90,14 @@ class OtherOperationsForm(forms.Form):
'Use with care and only if you need to. Note that rounding differences might occur in this procedure.' 'Use with care and only if you need to. Note that rounding differences might occur in this procedure.'
) )
) )
notify = forms.BooleanField(
label=_('Notify user'),
required=False,
initial=True,
help_text=_(
'Send an email to the customer notifying that their order has been changed.'
)
)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
kwargs.pop('order') kwargs.pop('order')

View File

@@ -175,6 +175,7 @@
</div> </div>
{% endif %} {% endif %}
{% bootstrap_field other_form.recalculate_taxes layout="control" %} {% bootstrap_field other_form.recalculate_taxes layout="control" %}
{% bootstrap_field other_form.notify layout="control" %}
</div> </div>
</div> </div>
</div> </div>

View File

@@ -600,7 +600,12 @@ class OrderChange(OrderView):
return True return True
def post(self, *args, **kwargs): def post(self, *args, **kwargs):
ocm = OrderChangeManager(self.order, self.request.user) notify = self.other_form.cleaned_data['notify'] if self.other_form.is_valid() else True
ocm = OrderChangeManager(
self.order,
user=self.request.user,
notify=notify
)
form_valid = self._process_add(ocm) and self._process_change(ocm) and self._process_other(ocm) form_valid = self._process_add(ocm) and self._process_change(ocm) and self._process_other(ocm)
if not form_valid: if not form_valid:
@@ -611,7 +616,10 @@ class OrderChange(OrderView):
except OrderError as e: except OrderError as e:
messages.error(self.request, str(e)) messages.error(self.request, str(e))
else: else:
messages.success(self.request, _('The order has been changed and the user has been notified.')) if notify:
messages.success(self.request, _('The order has been changed and the user has been notified.'))
else:
messages.success(self.request, _('The order has been changed.'))
return self._redirect_back() return self._redirect_back()
return self.get(*args, **kwargs) return self.get(*args, **kwargs)