From 8e51fd2afe5a5fa388da55c8d873b25a832dca37 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Sun, 26 Jan 2020 14:19:42 +0000 Subject: [PATCH] [FIX] account: Perform B2B/B2C overlapping check per user Steps to reproduce the problem: - Have user A with B2B group. - Have user B with B2C group. - Add simultaneously on both - via write - another group (or call `_check_one_user_type`). Expected result: - No problem Got result: - Error "A user cannot have both Tax B2B and Tax B2C..." That's because the check is performed for more than one user each time, while it has to be record per record. The implementation of `_has_multiple_groups` actually checks if the passed recordset is only one record, and if not, it looks directly for all existing users, so also the case of both users A and B being in the same B2x group, but having a 3rd user in the other group will fail. Revisiting the query in `_has_multiple_groups`, there's a hidden error when you use it for only one ID because a missing space. closes odoo/odoo#44300 X-original-commit: 83f104b2f2fc1345ad067430466c004697a91db9 Signed-off-by: Nicolas Martinelli (nim) --- addons/account/models/res_users.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/addons/account/models/res_users.py b/addons/account/models/res_users.py index d564746dfd6..0cf9d85cedb 100644 --- a/addons/account/models/res_users.py +++ b/addons/account/models/res_users.py @@ -19,8 +19,9 @@ class Users(models.Model): # A user cannot be in a non-existant group return - if self._has_multiple_groups([g1.id, g2.id]): - raise ValidationError(_("A user cannot have both Tax B2B and Tax B2C.\n" - "You should go in General Settings, and choose to display Product Prices\n" - "either in 'Tax-Included' or in 'Tax-Excluded' mode\n" - "(or switch twice the mode if you are already in the desired one).")) + for user in self: + if user._has_multiple_groups([g1.id, g2.id]): + raise ValidationError(_("A user cannot have both Tax B2B and Tax B2C.\n" + "You should go in General Settings, and choose to display Product Prices\n" + "either in 'Tax-Included' or in 'Tax-Excluded' mode\n" + "(or switch twice the mode if you are already in the desired one)."))