def test_checkout_one_return(): cart = [[{ 'item_name': 'car', 'base_rental_price': 4, 'replacement_cost': 10 }, 'return']] assert core.checkout(cart) == -1.0
def show_receipt(cart, customer): ''' (list of lists [dict, str], str) -> NoneType prints out the receipt to the user; negative number means money was refunded ''' grand_total = '$' + '{:.2f}'.format(core.checkout(cart)) grand_tax = '$' + '{:.2f}'.format(core.transaction_tax(cart)) print(f'\n\n{customer}') print('Receipt'.center(40) + '\n') print('*' * 40) for item in cart: if 'rent' in item: print('''\t{:<20}{:>15}{:>15} \t{:<20}{:>18}\n'''.format(item[0]['item_name'], '$' + f'{item[0]["base_rental_price"]:.2f}', item[1], '(Replacement deposit)', ('$' + f'{item[0]["replacement_cost"] * .1:.2f}'))) if 'return' in item: print('''\t{:<20}{:>10}{:>8}\n'''.format( item[0]['item_name'], '$' + f'{-item[0]["replacement_cost"] * .1:.2f}', item[1])) print('*' * 40) print('''\t{:<10}{:>18} \t{:<10}{:>18}'''.format( 'Tax', grand_tax, 'Total', grand_total)) #prints tax total then prints grand total
def test_checkout_mix(): cart = [[{ 'item_name': 'car', 'base_rental_price': 4, 'replacement_cost': 10 }, 'return'], [{ 'item_name': 'car', 'base_rental_price': 4, 'replacement_cost': 10 }, 'rent'], [{ 'item_name': 'rabbit', 'base_rental_price': 7, 'replacement_cost': 15 }, 'rent']] assert core.checkout(cart) == 13.27
def checkout_operations(inventory, cart, username, customer_manifesto): ''' (list of lists [dict, str], str, list of dict) -> NoneType The functions called when the user checks out ''' show_receipt(cart, username) grand_total = core.checkout(cart) new_customer_manifesto = core.change_rented_items(cart, username, customer_manifesto) disk.rewrite_manifesto_file('customer_manifesto.txt', new_customer_manifesto) disk.rewrite_inventory('inventory_2.txt', inventory) disk.update_history('history.txt', username, grand_total) revenue = disk.read_revenue('revenue.txt') disk.update_revenue('revenue.txt', revenue, grand_total) print('\n\nGoodbye, have a nice day!') quit()
def test_checkout_empty(): cart = [[]] assert core.checkout(cart) == 0.00