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

Replace normalize with integer wrapper for quantity field #1446

Merged
merged 3 commits into from Apr 9, 2021

Conversation

eeintech
Copy link
Contributor

@eeintech eeintech commented Apr 8, 2021

In a attempt to fix #1443

I don't see when can the BOM Item quantity be a decimal number and it was causing the error in the BOM export because the PyYAML library doesn't have a Decimal object representation.

@SchrodingersGat
Copy link
Member

There are definitely cases where the BOM quantity can be a non integer number - e.g. you might need 0.15m of heatshrink.

Maybe we can replace normalize here with a float?

@eeintech
Copy link
Contributor Author

eeintech commented Apr 9, 2021

Looks like float would work for YAML:

>>> import yaml
>>> dec = 1.23456
>>> print(dec)
1.23456
>>> type(dec)
<class 'float'>
>>> yaml.safe_dump(dec)
'1.23456\n...\n'
>>> dec = 1.2345600000
>>> yaml.safe_dump(dec)
'1.23456\n...\n'

But I'm not sure all the other formats would remove the trailing zeros...

@SchrodingersGat
Copy link
Member

Can we check the output format and choose 'float' if it is a yaml file?

@eeintech
Copy link
Contributor Author

eeintech commented Apr 9, 2021

I don't really find a good way to check the export format and pass it to the dehydrate_quantity method... I'll take another look soon

@SchrodingersGat
Copy link
Member

Ok, what does the output look like for a .csv file? Does it suppress the trailing zeros correctly?

@eeintech
Copy link
Contributor Author

eeintech commented Apr 9, 2021

@SchrodingersGat I tested all formats with float and CSV, TSV and XLS gets no decimal digits for integer quantities and the right amount of digits for decimal numbers, while XLSX, JSON and YAML get one digit for integer quantities and also the right amount of digits for decimal numbers.

So if we are okay that quantity of 10 becomes 10.0 for XLSX, JSON and YAML then float is a great option 😃

@SchrodingersGat
Copy link
Member

Seems like a reasonable compromise.

@SchrodingersGat SchrodingersGat merged commit 6bf3cc9 into inventree:master Apr 9, 2021
@SchrodingersGat
Copy link
Member

Thanks for the fix :)

@eeintech
Copy link
Contributor Author

eeintech commented Apr 9, 2021

No problem, thanks for merging 👍

@eeintech eeintech deleted the bom_yaml_export branch July 14, 2021 19:10
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

Successfully merging this pull request may close these issues.

Error exporting BOM in YAML format
2 participants