From 171f072c1fd59b91b4c4e892d5e7dc24a637dcaa Mon Sep 17 00:00:00 2001 From: "Christihan Laurel [Vauxoo]" Date: Mon, 30 Dec 2024 19:48:52 +0000 Subject: [PATCH] [FIX] default_warehouse_from_sale_team: prevent Sales Team compute on 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 --- default_warehouse_from_sale_team/models/account_move.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/default_warehouse_from_sale_team/models/account_move.py b/default_warehouse_from_sale_team/models/account_move.py index eb42941dfe9..f101157403e 100644 --- a/default_warehouse_from_sale_team/models/account_move.py +++ b/default_warehouse_from_sale_team/models/account_move.py @@ -7,7 +7,13 @@ class AccountMove(models.Model): def _search_default_journal(self): """If a team is provided and it has a sales journal set, take it as 1st alternative""" journal = super()._search_default_journal() - team = self.env.context.get("salesteam") or self.team_id or self.env.user.sale_team_id + team = ( + self.env.context.get("salesteam") + # If the team_id value (ID) is in the cache, it must be converted to a record from the + # cached value to avoid triggering the field's compute method when it has not yet been computed. + or self._fields["team_id"].convert_to_record(self._cache.get("team_id"), self) + or self.env.user.sale_team_id + ) journal_on_team = team._get_default_journal([journal.type or "general"]) return journal_on_team or journal