Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json output in wrong order #383

Closed
bosd opened this issue Jun 28, 2022 · 4 comments
Closed

Json output in wrong order #383

bosd opened this issue Jun 28, 2022 · 4 comments

Comments

@bosd
Copy link
Collaborator

bosd commented Jun 28, 2022

The written content to the json file is in the wrong order.
Environment: local system. Might occur on CI unit tests as well

Steps to reproduce:
invoice2data ./SammyMaystoneLinesTest.pdf --input-reader=pdftotext --template-folder=./Templates --output-format=json --output-name=samy-before.json --debug

Debug output:

{'issuer': 'Sammy Maystone - For Lines testing', 'invoice_number': 'invoice_number_1', 'date': datetime.datetime(2022, 1, 1, 0, 0), 'line_items': [{'item': 'A', 'desc': 'Parts: 1 x cap_a'}, {'item': 'B', 'desc': 'Parts: 2 x shop supplies'}], 'currency': 'USD', 'desc': 'Invoice from Sammy Maystone - For Lines testing'}

Actually written to the json file:

[
    {
        "currency": "USD",
        "date": "2022-01-01",
        "desc": "Invoice from Sammy Maystone - For Lines testing",
        "invoice_number": "invoice_number_1",
        "issuer": "Sammy Maystone - For Lines testing",
        "line_items": [
            {
                "desc": "Parts: 1 x cap_a",
                "item": "A"
            },
            {
                "desc": "Parts: 2 x shop supplies",
                "item": "B"
            }
        ]
    }
]

This causes the unittests to fail when it is compared against
https://github.com/invoice-x/invoice2data/blob/master/tests/compare/SammyMaystoneLinesTest.json

Encountered this while testing for: #378

Output to CSV, and Library are ok.
Untested: output to XML.

@bosd
Copy link
Collaborator Author

bosd commented Aug 5, 2022

@rmilecki Any thoughts on this?

@bosd
Copy link
Collaborator Author

bosd commented Aug 25, 2022

@m3nu Your thoughts on this?

@rmilecki
Copy link
Collaborator

That comes from sort_keys=True in the src/invoice2data/output/to_json.py. I think we have two options:

  1. Drop sort_keys=True
  2. Update SammyMaystoneLinesTest.json (sort its keys)

I think that sort_keys=False would be more natural but it's also a behaviour change. On the other hand it's a very minimal change that noone should complain about.

@m3nu: thoughts?

@bosd
Copy link
Collaborator Author

bosd commented Sep 1, 2022

IMO we should drop the sort_keys

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants