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: Compute amount with decimal precision of 16 #2649

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

Conversation

hildickethan
Copy link
Member

@hildickethan hildickethan changed the title [IMP] sale_triple_discount: Compute amount with decimal precision of 16 [16.0][IMP] sale_triple_discount: Compute amount with decimal precision of 16 Aug 21, 2023
Copy link
Sponsor Contributor

@rousseldenis rousseldenis left a comment

Choose a reason for hiding this comment

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

Could you add a test case for this ?

@hildickethan
Copy link
Member Author

Could you add a test case for this ?

Added the exact use case I had issues with, if you multiply 138*2*0.55*0.95*0.9 you get 129.789 which without these changes Odoo cuts off at 129.78 because the "final discount" gets cut off at 2 decimal precision and then in turn on the invoice it calculates 129.79 because it calculates with 16 digits, causing the mismatch

@@ -97,6 +97,9 @@ def triple_discount_preprocess(self):
this method is called multiple times."""

prev_values = dict()
digits = self._fields["discount"]._digits
self.env["sale.order.line"]._fields["discount"]._digits = (16, 16)
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

I'm not fan of this. I think this could lead to unwanted side effects.

Copy link
Member Author

Choose a reason for hiding this comment

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

Its not very pretty but I think it hasn't caused any issues for us so far, its mainly copying the process in the account equivalent module https://github.com/OCA/account-invoicing/blob/d2e12c03b50011bb788cf482346710f0fefe0de3/account_invoice_triple_discount/models/account_move_line.py#L73-L74 so it calculates the same discount, otherwise it can lead to different rounding

@hildickethan hildickethan force-pushed the 16.0-triple_16digits branch 2 times, most recently from 78a1fbe to c178a00 Compare May 21, 2024 14:23
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.

3 participants