Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
388 Tampilan

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
Buang
Jawaban Terbai

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
Buang
Post Terkait Replies Tampilan Aktivitas
3
Jul 25
595
1
Jun 25
1080
1
Mei 25
1332
3
Mar 25
1983
1
Mar 25
1516