From 552da8dc8d55962c69dcdfec6fc4509f61cb27f1 Mon Sep 17 00:00:00 2001 From: Nans Lefebvre Date: Thu, 28 Mar 2019 10:41:23 +0000 Subject: [PATCH] [FIX] account: do not allow a user to have both B2B and B2C groups MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We base ourselves on commit f206714af08, which added a check on user groups. The tax-included and tax excluded displays are meant to be exclusive, but wily users can add themselves to both groups using the res_users view in debug mode. opw 1950833 closes odoo/odoo#32200 Signed-off-by: Jérémy Kersten (jke) --- addons/account/i18n/account.pot | 6 ++++++ addons/account/models/__init__.py | 1 + addons/account/models/res_users.py | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 addons/account/models/res_users.py diff --git a/addons/account/i18n/account.pot b/addons/account/i18n/account.pot index 063c8af308b..7d790411b5d 100644 --- a/addons/account/i18n/account.pot +++ b/addons/account/i18n/account.pot @@ -654,6 +654,12 @@ msgstr "" msgid "A tax fiscal position could be defined only one time on same taxes." msgstr "" +#. module: account +#: code:addons/account/models/res_users.py:17 +#, python-format +msgid "A user cannot have both Tax B2B and Tax B2C" +msgstr "" + #. module: account #: model:res.groups,name:account.group_warning_account msgid "A warning can be set on a partner (Account)" diff --git a/addons/account/models/__init__.py b/addons/account/models/__init__.py index b6b023055b8..5f99c57e04d 100644 --- a/addons/account/models/__init__.py +++ b/addons/account/models/__init__.py @@ -19,3 +19,4 @@ from . import reconciliation_widget from . import account_incoterms from . import digest from . import account_invoice_import_wizard +from . import res_users diff --git a/addons/account/models/res_users.py b/addons/account/models/res_users.py new file mode 100644 index 00000000000..3e6fd163482 --- /dev/null +++ b/addons/account/models/res_users.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, models, _ +from odoo.exceptions import ValidationError + + +class Users(models.Model): + _inherit = "res.users" + + @api.multi + @api.constrains('groups_id') + def _check_one_user_type(self): + super(Users, self)._check_one_user_type() + for user in self: + if (user.user_has_groups('account.group_show_line_subtotals_tax_included') and + user.user_has_groups('account.group_show_line_subtotals_tax_excluded')): + raise ValidationError(_('A user cannot have both Tax B2B and Tax B2C'))