Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
454 Weergaven

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
Annuleer
Beste antwoord

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
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
3
jul. 25
679
1
jun. 25
1149
1
mei 25
1428
3
mrt. 25
2098
1
mrt. 25
1570