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

TP2000-1678-Measure-condition-duty-bug #1394

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mattjamc
Copy link
Collaborator

@mattjamc mattjamc commented Jan 23, 2025

TP2000-1678-Measure-condition-duty-bug

Why

Currently, the duty sentence parser returns a float value of the inputted number. If the inputted number cannot be accurately stored as a float, this results in it being replaced with a near approximation with many decimal places. This is causing form validation to fail with an unhelpful error message due to too many decimal places, even if the user only inputted a number with 3 decimal places.

For example, 6.5 GBP / kg or 6.75 would be fine but something like 6.667 would get converted to 6.66699999999999981526 (20 decimal places) and then error.

What

This PR:

  • changes the duty sentence parser to return the duty sentence as a Decimal rather than float object
  • updates tests to account for it being a decimal now
  • adds a check in the form of how many decimal places there are and raises an error - although this was already prevented by it being a DecimalField with max_decimal_places=3, this repeated validation allows a meaningful error message to be surfaced to the user which wasn't before
  • adds a new test to confirm the new error message displays on the reference price field

@mattjamc mattjamc requested a review from a team as a code owner January 23, 2025 17:03
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.

1 participant