invoice-x / invoice2data

Extract structured data from PDF invoices
MIT License
1.84k stars 482 forks source link

issue to export into csv #511

Closed Mandagsteve closed 1 year ago

Mandagsteve commented 1 year ago

for k, v in line.items(): AttributeError: 'str' object has no attribute 'items'

rmilecki commented 1 year ago

Can you share your parsed invoice (you can skip personal data)? In whatever readable form. Python's dict or JSON or XML.

Mandagsteve commented 1 year ago

{'issuer': 'SC ICORE OUTSOURCING SRL', 'Address': 'Victor Babes 36, office 1.10 Brasov RO', 'issued_to': 'Makro-Mikro Consulting GmbH', 'amount': 1729.46, 'date': datetime.datetime(2023, 1, 15, 0, 0), 'date_payement_due': datetime.datetime(2023, 1, 30, 0, 0), 'invoice_number': '002', 'currency': 'EUR, LEI', 'lines': [{'name': '1 (Providing Services as per Contract no.13 from', 'desc': 'buc / pc.', 'qty': 1.0, 'price_unit': '350.00', 'Total': '350.00'}], 'desc': 'Invoice from SC ICORE OUTSOURCING SRL'}

Mandagsteve commented 1 year ago

i tried it with other invoices as well and got the same error

Mandagsteve commented 1 year ago

tried into a JSON format got the same error

rmilecki commented 1 year ago

I tried to reproduce this few times using invoice2data command line tool and failed. The loop code looks basically as this:

for line in data:
    for k, v in line.items():
        ...

Variable data always contains a list of invoices (a list of dicts).

My only explanation is that you use invoice2data from a custom Python script and you pass wrong argument to it. Please note that data has to be an array of invoices. Not a single invoice.

Please verify your script if I'm right with my guess.