Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
501 Visualizzazioni

How to restrict users from creating companies? I want them to have permissions to create individuals only.

Both individuals and and companies come under Partner.

(Odoo 18 community edition)

Avatar
Abbandona
Risposta migliore

Use this to restrict users from creating contacts:

from odoo import models, api, _
from odoo.exceptions import ValidationError

class ResPartner(models.Model):
    _inherit = 'res.partner'

    @api.model
    def create(self, vals):
        if vals.get('is_company') and not self.env.user.has_group('base.group_system'):
            raise ValidationError(_("You are not allowed to create companies. Please create individuals only."))
        return super(ResPartner, self).create(vals)

    def write(self, vals):
        if vals.get('is_company') and not self.env.user.has_group('base.group_system'):
            raise ValidationError(_("You are not allowed to convert a contact into a company."))
        return super(ResPartner, self).write(vals)


Optional: Hide or Disable the “Is a Company” Checkbox in the Form

Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
3
lug 25
773
1
giu 25
1218
1
mag 25
1503
3
mar 25
2161
1
mar 25
1642