下面给出的是我用来创建发票的 python 代码:
import os
from InvoiceGenerator.api import Invoice, Item, Client, Provider, Creator
from InvoiceGenerator.pdf import SimpleInvoice
# choose english as language
os.environ["INVOICE_LANG"] = "en"
client = Client('ROHIT RAJ')
provider = Provider('MANIAR TYREWORLD', bank_account='2600420569', bank_code='2010')
creator = Creator('DHIREN AHUJA')
invoice = Invoice(client, provider, creator)
invoice.currency_locale = 'en_US.UTF-8'
invoice.add_item(Item(32, 600, description="Item 1"))
invoice.add_item(Item(60, 50, description="Item 2", tax=21))
invoice.add_item(Item(50, 60, description="Item 3", tax=0))
invoice.add_item(Item(5, 600, description="Item 4", tax=15))
pdf = SimpleInvoice(invoice)
pdf.gen("invoice.pdf", generate_qr_code=True)
上面给出的代码用于生成发票,下面给出的代码用于解析 json 文件中的数据。
#import packages
import json
from json2html import*
#Now open json file
with open('trying.json') as f:
d = json.load(f) # Load our json file
scanoutput = json2html.convert(json=d) # It will convert Json to html
htmlReportFile = "tryingf.html" # Write your desired file name to create output file
with open(htmlReportFile, 'w') as htmlfile: # Open output file into write mode
htmlfile.write(str(scanoutput)) # Write converted json into our created html file
print("Json file is converted into html successfully...")
我只需要合并这两个程序,以便发票生成器库可以自动获取数据。任何人都可以帮忙吗?