res_users.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import api, models, _
  4. from odoo.exceptions import ValidationError
  5. class Users(models.Model):
  6. _inherit = "res.users"
  7. @api.constrains('groups_id')
  8. def _check_one_user_type(self):
  9. super(Users, self)._check_one_user_type()
  10. g1 = self.env.ref('account.group_show_line_subtotals_tax_included', False)
  11. g2 = self.env.ref('account.group_show_line_subtotals_tax_excluded', False)
  12. if not g1 or not g2:
  13. # A user cannot be in a non-existant group
  14. return
  15. for user in self:
  16. if user._has_multiple_groups([g1.id, g2.id]):
  17. raise ValidationError(_("A user cannot have both Tax B2B and Tax B2C.\n"
  18. "You should go in General Settings, and choose to display Product Prices\n"
  19. "either in 'Tax-Included' or in 'Tax-Excluded' mode\n"
  20. "(or switch twice the mode if you are already in the desired one)."))
  21. class GroupsView(models.Model):
  22. _inherit = 'res.groups'
  23. @api.model
  24. def get_application_groups(self, domain):
  25. # Overridden in order to remove 'Show Full Accounting Features' and
  26. # 'Show Full Accounting Features - Readonly' in the 'res.users' form view to prevent confusion
  27. group_account_user = self.env.ref('account.group_account_user', raise_if_not_found=False)
  28. if group_account_user and group_account_user.category_id.xml_id == 'base.module_category_hidden':
  29. domain += [('id', '!=', group_account_user.id)]
  30. group_account_readonly = self.env.ref('account.group_account_readonly', raise_if_not_found=False)
  31. if group_account_readonly and group_account_readonly.category_id.xml_id == 'base.module_category_hidden':
  32. domain += [('id', '!=', group_account_readonly.id)]
  33. return super().get_application_groups(domain)