Question: def close _ existing _ invoice ( self , invoice _ number ) : try: with open ( self . registry.file _ path, ' r
def closeexistinginvoiceself invoicenumber:
try:
with openselfregistry.filepath, r as file:
invoicefound False
for line in file:
if line.strip fInvoice Number: invoicenumber:
invoicefound True
break
if invoicefound:
customerinfo
for in range: # Read customer info lines
key, value file.readlinesplit:
customerinfokey value.strip
products
while True:
line file.readlinestrip
if not line or line "Amount Paid:":
break
modelnumber, price line.split: floatlinesplit:
productsmodelnumbername: self.productcatalog.productsmodelnumbername 'price': price
amountpaid floatfilereadlinesplit:
total sumproductprice for product in products.values
if amountpaid total:
printInvoice already fully paid."
else:
printThis invoice still has an outstanding balance."
else:
printInvoice not found."
except FileNotFoundError:
printRegistry file not found."
def returnproductself invoicenumber:
try:
invoiceinfo self.getinvoiceinfoinvoicenumber
if invoiceinfo:
totalamount invoiceinfototal
amountpaid invoiceinfoamountpaid'
returnedamount floatinputEnter the amount of returned product: $
if returnedamount totalamount amountpaid:
customerinfo invoiceinfocustomerinfo'
products invoiceinfoproducts
productsReturned Product'name: 'Returned Product', 'price': returnedamount
returnedinvoice Invoiceinvoicenumber, customerinfo, products
self.registry.saveinvoicereturnedinvoice
print
Return processed successfully!
printreturnedinvoice.generateinvoice
else:
printReturned amount exceeds the remaining balance."
else:
printInvoice not found."
except Exception as e:
printfErrOutput:
Select an option:
Generate a new invoice
Close an existing invoice
Return a product
Get a quote
Quit
Enter your choice:
Enter the invoice number to close:
Error: not enough values to unpack expected got or: stre
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
