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

[16.0][IMP] sale_triple_discount: Improves perfs and consistency #3329

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from

Conversation

lmignon
Copy link
Sponsor Contributor

@lmignon lmignon commented Sep 26, 2024

When computing the amount total on a sale.order.line, we now avoid to play with the cache since this change introduced in e3e59ba introduces a decline in performance. When the cache in invalidated, fields are flushed to the database and depending computed fields are recomputed..... This ultimately leads to temporary inconsistencies breaking others addons relaying on this one. Moreover, the method used in this original commit 'self.invalidate_cache(fnames=self._discount_fields(), ids=self.ids)' is deprecated and the use of the recommended new one lead to others side effects. The original approach is replaced by a contextual method modifying only the discount field when we need it's needed to don't break code relaying on the fact that the discount field is the total discount to apply to a line. This contextual method ensures that the original value is properly restored on exit and that it will not trigger additional recompute due to the temporary change of the discount value

@lmignon
Copy link
Sponsor Contributor Author

lmignon commented Sep 26, 2024

ping @renda-dev @toita86 @technativa

When computing the amount total on a sale.order.line, we now avoid to play with the cache since this change introduced in OCA@e3e59ba introduces a decline in performance. When the cache in invalidated, fields are flushed to the database and depending computed fields are recomputed..... This ultimately leads to temporary inconsistencies breaking others addons relaying on this one. Moreover, the method used in this original commit 'self.invalidate_cache(fnames=self._discount_fields(), ids=self.ids)' is deprecated and the use of the recommended new one lead to others side effects. The original approach is replaced by a contextual method modifying only the discount field when we need it's needed to don't break code relaying on the fact that the discount field is the total discount to apply to a line. This contextual method ensures that the original value is properly restored on exit and that it will not trigger additional recompute due to the temporary change of the discount value
@lmignon lmignon force-pushed the 16.0-sale-triple-discount-fix branch from 60172eb to 1396de1 Compare September 26, 2024 14:23
Copy link
Contributor

@renda-dev renda-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solution is really clean and I love it.

Code review, LGTM!

Copy link

@toita86 toita86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review, LGTM.

@IJOL
Copy link

IJOL commented Oct 3, 2024

Just tested this solution and works nicely and is much more clean and less magic, i'm all about less roundtrips and no cache messing, although my latest iteration in #3324 worked nicely too, I much favor this one over ours.

And closes #3323

@francesco-ooops
Copy link
Contributor

@IJOL approve please :)

Copy link

@IJOL IJOL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

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.

6 participants