0002-lingo-document-handle_payment-contract-with-assert-4.patch
combo/apps/lingo/views.py | ||
---|---|---|
358 | 358 |
def handle_payment( |
359 | 359 |
self, request, regie, items, remote_items, next_url='/', email='', firstname='', |
360 | 360 |
lastname=''): |
361 |
# we cannot pay items and remote_items at the same time |
|
362 |
if bool(len(items)) == bool(len(remote_items)): |
|
363 |
logger.error('lingo: there should be at least one item or remote item to pay and not both items', |
|
364 |
extra={'regie': str(regie), 'items': items, 'remote_items': remote_items}) |
|
365 |
messages.error(request, _('Grouping basket items is not allowed.')) |
|
366 |
return HttpResponseRedirect(next_url) |
|
367 | ||
368 |
# we cannot pay more than one item on regie with flag 'can_pay_only_one_basket_item' |
|
369 |
if regie.can_pay_only_one_basket_item and len(items) != 1 and len(remote_items) != 1: |
|
370 |
logger.error('lingo: regie can only pay one basket item, but handle_payment() received', |
|
371 |
extra={'regie': str(regie), 'items': items, 'remote_items': remote_items}) |
|
372 |
messages.error(request, _('Grouping basket items is not allowed.')) |
|
373 |
return HttpResponseRedirect(next_url) |
|
361 |
# check contract |
|
362 |
assert bool(len(items)) != bool(len(remote_items)), ( |
|
363 |
'there should be at least one item or remote item to pay and not both items' |
|
364 |
) |
|
365 |
assert not regie.can_pay_only_one_basket_item or len(items) == 1, ( |
|
366 |
'regie can only pay one basket item, but handle_payment() ' |
|
367 |
'did not receive one item: len(items) = %d' % len(items) |
|
368 |
) |
|
374 | 369 | |
375 | 370 |
total_amount = sum([x.amount for x in remote_items or items]) |
376 | 371 | |
377 |
- |