Order change manager: Allow to disable invoice issuing

This commit is contained in:
Raphael Michel
2019-10-10 12:19:06 +02:00
parent fb3fc05522
commit d4d046ca60
5 changed files with 24 additions and 3 deletions
+3 -2
View File
@@ -904,12 +904,13 @@ class OrderChangeManager:
SplitOperation = namedtuple('SplitOperation', ('position',)) SplitOperation = namedtuple('SplitOperation', ('position',))
RegenerateSecretOperation = namedtuple('RegenerateSecretOperation', ('position',)) RegenerateSecretOperation = namedtuple('RegenerateSecretOperation', ('position',))
def __init__(self, order: Order, user=None, auth=None, notify=True): def __init__(self, order: Order, user=None, auth=None, notify=True, reissue_invoice=True):
self.order = order self.order = order
self.user = user self.user = user
self.auth = auth self.auth = auth
self.event = order.event self.event = order.event
self.split_order = None self.split_order = None
self.reissue_invoice = reissue_invoice
self._committed = False self._committed = False
self._totaldiff = 0 self._totaldiff = 0
self._quotadiff = Counter() self._quotadiff = Counter()
@@ -1392,7 +1393,7 @@ class OrderChangeManager:
def _reissue_invoice(self): def _reissue_invoice(self):
i = self.order.invoices.filter(is_cancellation=False).last() i = self.order.invoices.filter(is_cancellation=False).last()
if i and self._invoice_dirty: if self.reissue_invoice and i and self._invoice_dirty:
generate_cancellation(i) generate_cancellation(i)
generate_invoice(self.order) generate_invoice(self.order)
+9
View File
@@ -168,6 +168,15 @@ 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.'
) )
) )
reissue_invoice = forms.BooleanField(
label=_('Issue a new invoice if required'),
required=False,
initial=True,
help_text=_(
'If an invoice exists for this order and this operation would change its contents, the old invoice will '
'be cancelled and a new invoice will be issued.'
)
)
notify = forms.BooleanField( notify = forms.BooleanField(
label=_('Notify user'), label=_('Notify user'),
required=False, required=False,
@@ -215,6 +215,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.reissue_invoice layout="control" %}
{% bootstrap_field other_form.notify layout="control" %} {% bootstrap_field other_form.notify layout="control" %}
</div> </div>
</div> </div>
+2 -1
View File
@@ -1297,7 +1297,8 @@ class OrderChange(OrderView):
ocm = OrderChangeManager( ocm = OrderChangeManager(
self.order, self.order,
user=self.request.user, user=self.request.user,
notify=notify notify=notify,
reissue_invoice=self.other_form.cleaned_data['reissue_invoice'] if self.other_form.is_valid() else True
) )
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)
+9
View File
@@ -1219,6 +1219,15 @@ class OrderChangeManagerTests(TestCase):
self.ocm.commit() self.ocm.commit()
assert self.order.invoices.count() == 3 assert self.order.invoices.count() == 3
@classscope(attr='o')
def test_reissue_invoice_disabled(self):
self.ocm.reissue_invoice = False
generate_invoice(self.order)
assert self.order.invoices.count() == 1
self.ocm.add_position(self.ticket, None, Decimal('0.00'))
self.ocm.commit()
assert self.order.invoices.count() == 1
@classscope(attr='o') @classscope(attr='o')
def test_dont_reissue_invoice_on_free_product_changes(self): def test_dont_reissue_invoice_on_free_product_changes(self):
self.event.settings.invoice_include_free = False self.event.settings.invoice_include_free = False