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

Merged
merged 1 commit into from
Oct 16, 2024

Conversation

lmignon
Copy link
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
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

@mariancuadranetkia
Copy link

Tested and it recovers funcionality
@pedrobaeza how do you see this fix?

@pedrobaeza pedrobaeza added this to the 16.0 milestone Oct 16, 2024
@pedrobaeza
Copy link
Member

I'm not using the module, but with current review status + coming from a trusted contributor, let's merge it:

/ocabot merge patch

@OCA-git-bot
Copy link
Contributor

What a great day to merge this nice PR. Let's do it!
Prepared branch 16.0-ocabot-merge-pr-3329-by-pedrobaeza-bump-patch, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit 65efa18 into OCA:16.0 Oct 16, 2024
8 of 9 checks passed
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at f32db33. Thanks a lot for contributing to OCA. ❤️

@lmignon lmignon deleted the 16.0-sale-triple-discount-fix branch October 16, 2024 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants