From c6e538e727222f7c2d4cd1bc74a3a96968c6ffe2 Mon Sep 17 00:00:00 2001 From: Adrien Widart Date: Mon, 8 Mar 2021 12:35:26 +0000 Subject: [PATCH] [FIX] sale: define team_id with same company than user When creating a journal entry in company C01, if user's sales team belongs to another company CXX, the default sales team of the journal entry is still the user's sales team. To reproduce the error: (Use demo data. Let C01 be the current company) 1. Add the `team_id` field to `account_move` form view: - With web_studio - Directly in the code: ```diff diff --git a/addons/sale/views/sale_views.xml b/addons/sale/views/sale_views.xml index 92cb2a72c4d..acc0e91e890 100644 --- a/addons/sale/views/sale_views.xml +++ b/addons/sale/views/sale_views.xml @@ -1154,6 +1154,17 @@ + + account.move.form.inherit.sale + account.move + + + + + + + + Account Invoice ``` 2. Create a second Company C02 3. Edit the Sales Team 'Europe': - Company: C02 4. Go to Accounting > Accounting > Journal Entries 5. Click on "Create" Error: the default Sales Team is 'Europe'. However, this team belongs to C02 and the user is creating a new JE in C01. When creating a new journal entry, an `onchange` method uses the user's sales team to define the JE's sales team. However, the current user belongs to 'Europe', and the company of 'Europe' is now C02. Therefore, 'Europe' should not be used. OPW-2375444 closes odoo/odoo#67733 X-original-commit: 67cd2ca3d80e5fc53f6c0f3ec73a0f90765dda73 Signed-off-by: Thibault Delavallee (tde) --- addons/sale/models/account_invoice.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/sale/models/account_invoice.py b/addons/sale/models/account_invoice.py index c0d5319ab9a..9ffe13e56d9 100644 --- a/addons/sale/models/account_invoice.py +++ b/addons/sale/models/account_invoice.py @@ -60,7 +60,7 @@ class AccountMove(models.Model): @api.onchange('invoice_user_id') def onchange_user_id(self): if self.invoice_user_id and self.invoice_user_id.sale_team_id: - self.team_id = self.invoice_user_id.sale_team_id + self.team_id = self.env['crm.team']._get_default_team_id(user_id=self.invoice_user_id.id, domain=[('company_id', '=', self.company_id.id)]) def _reverse_moves(self, default_values_list=None, cancel=False): # OVERRIDE