Repository navigation
Conversation
``_get_write_diff_values()`` compares the values with a snapshot built by ``new()``, which fills the cache without validation, so monetary values aren't rounded to their currency there. An amount with more decimals than its currency, e.g. 1.234 against 1.23 in EUR, was always seen as changed, and ``write_diff()`` wrote a value that ``write()`` then rounded back to the stored one. Round them first, with the currency written along with them if any, since ``write()`` sets the currency before the amount.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
_get_write_diff_values()compares the values with a snapshot built bynew(), which fills the cache withvalidate=False(models.py). Monetary fields only round to their currency when validating (fields.py). So a record holding 1.23 € sees{"amount": 1.234}as a change, andwrite_diff()writes a value thatwrite()rounds back to 1.23.This rounds monetary values before the snapshot, with the currency written along with them if any, since
write()writes the currency first (models.py, fields.py).