Skip to content

[17.0][FIX] base_write_diff: round monetary values before comparing - #3878

Draft
vvrossem wants to merge 1 commit into
OCA:17.0from
camptocamp:17.0-fix-base_write_diff-monetary
Draft

vvrossem wants to merge 1 commit into
OCA:17.0from
camptocamp:17.0-fix-base_write_diff-monetary

Conversation

@vvrossem

Copy link
Copy Markdown
Contributor

_get_write_diff_values() compares the values with a snapshot built by new(), which fills the cache with validate=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, and write_diff() writes a value that write() 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).

``_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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants