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

[FIX] default_warehouse_from_sale_team: prevent Sales Team compute on default journal set i#28375 #1686

Conversation

CLaurelB
Copy link
Contributor

@CLaurelB CLaurelB commented Dec 30, 2024

Use the cached value of the Sales Team field to access its value as a record. This avoids computing its value when it has not been computed yet, which could result in setting the wrong Sales Team on an invoice form creation. This issue occurs because the company is not yet set, and its value is required to determine the correct Sales Team 1.

@CLaurelB
Copy link
Contributor Author

Hello @hugho-ad,

Could you review, please?

Regards.

cc. @desdelinux

team = self.env.context.get("salesteam") or self.team_id or self.env.user.sale_team_id
team = (
self.env.context.get("salesteam")
or (self._cache["team_id"] and self.team_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

If already checking the cache, why do you need to read the current value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the cached value contains only the ID and not the record.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to use the convert_to_record method as suggested.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks a lot! I like the new approach.

Just only one more request:

Since that's not a trivial code, could you add a small comment above the new line (the one with _fields) explaining why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment added.

@CLaurelB CLaurelB requested a review from luisg123v December 31, 2024 04:23
@CLaurelB CLaurelB force-pushed the 17.0-avoid_triggering_team_id_compute-CLaurelB branch from b0fbe23 to 9546b5a Compare January 6, 2025 17:57
… default journal set

Use the cached value of the Sales Team field to access its value as a
record. This avoids computing its value when it has not been computed
yet, which could result in setting the wrong Sales Team on an invoice
form creation. This issue occurs because the company is not yet set, and
its value is required to determine the correct Sales Team [1].

[1]: https://github.com/odoo/odoo/blob/3884a60e/addons/sale/models/account_move.py#L41
@CLaurelB CLaurelB force-pushed the 17.0-avoid_triggering_team_id_compute-CLaurelB branch from 9546b5a to 71da6d8 Compare January 6, 2025 21:42
@luisg123v luisg123v merged commit 171f072 into Vauxoo:17.0 Jan 6, 2025
3 checks passed
@luisg123v luisg123v deleted the 17.0-avoid_triggering_team_id_compute-CLaurelB branch January 6, 2025 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants