Question: def close _ existing _ invoice ( self , invoice _ number ) : try: with open ( self . registry.file _ path, ' r

def close_existing_invoice(self, invoice_number):
try:
with open(self.registry.file_path, 'r') as file:
invoice_found = False
for line in file:
if line.strip()== f"Invoice Number: {invoice_number}":
invoice_found = True
break
if invoice_found:
customer_info ={}
for _ in range(4): # Read customer info lines
key, value = file.readline().split(": ",1)
customer_info[key]= value.strip()
products ={}
while True:
line = file.readline().strip()
if not line or line == "Amount Paid:":
break
model_number, price = line.split(": ")[0], float(line.split(": ")[1])
products[model_number]={'name': self.product_catalog.products[model_number]['name'], 'price': price}
amount_paid = float(file.readline().split(": ")[1])
total = sum(product['price'] for product in products.values())
if amount_paid >= total:
print("Invoice already fully paid.")
else:
print("This invoice still has an outstanding balance.")
else:
print("Invoice not found.")
except FileNotFoundError:
print("Registry file not found.")
def return_product(self, invoice_number):
try:
invoice_info = self.get_invoice_info(invoice_number)
if invoice_info:
total_amount = invoice_info['total']
amount_paid = invoice_info['amount_paid']
returned_amount = float(input("Enter the amount of returned product: $"))
if returned_amount <= total_amount - amount_paid:
customer_info = invoice_info['customer_info']
products = invoice_info['products']
products['Returned Product']={'name': 'Returned Product', 'price': -returned_amount}
returned_invoice = Invoice(invoice_number, customer_info, products)
self.registry.save_invoice(returned_invoice)
print("
Return processed successfully!
")
print(returned_invoice.generate_invoice())
else:
print("Returned amount exceeds the remaining balance.")
else:
print("Invoice not found.")
except Exception as e:
print(f"ErrOutput:
Select an option:
1. Generate a new invoice
2. Close an existing invoice
3. Return a product
4. Get a quote
5. Quit
Enter your choice: 2
Enter the invoice number to close: 1
Error: not enough values to unpack (expected 2, got 1)or: {str(e)}")
Please fix this error, same issue with both return and close invoice

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!