lingo: document handle_payment contract with assert (#47477)
This commit is contained in:
parent
e0d4d2b2f5
commit
1c22405e8b
|
@ -358,19 +358,14 @@ class PayMixin(object):
|
|||
def handle_payment(
|
||||
self, request, regie, items, remote_items, next_url='/', email='', firstname='',
|
||||
lastname=''):
|
||||
# we cannot pay items and remote_items at the same time
|
||||
if bool(len(items)) == bool(len(remote_items)):
|
||||
logger.error('lingo: there should be at least one item or remote item to pay and not both items',
|
||||
extra={'regie': str(regie), 'items': items, 'remote_items': remote_items})
|
||||
messages.error(request, _('Grouping basket items is not allowed.'))
|
||||
return HttpResponseRedirect(next_url)
|
||||
|
||||
# we cannot pay more than one item on regie with flag 'can_pay_only_one_basket_item'
|
||||
if regie.can_pay_only_one_basket_item and len(items) != 1 and len(remote_items) != 1:
|
||||
logger.error('lingo: regie can only pay one basket item, but handle_payment() received',
|
||||
extra={'regie': str(regie), 'items': items, 'remote_items': remote_items})
|
||||
messages.error(request, _('Grouping basket items is not allowed.'))
|
||||
return HttpResponseRedirect(next_url)
|
||||
# check contract
|
||||
assert bool(len(items)) != bool(len(remote_items)), (
|
||||
'there should be at least one item or remote item to pay and not both items'
|
||||
)
|
||||
assert not regie.can_pay_only_one_basket_item or len(items) == 1, (
|
||||
'regie can only pay one basket item, but handle_payment() '
|
||||
'did not receive one item: len(items) = %d' % len(items)
|
||||
)
|
||||
|
||||
total_amount = sum([x.amount for x in remote_items or items])
|
||||
|
||||
|
|
Loading…
Reference in New Issue