Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
506 Lượt xem

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)

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 7 25
782
1
thg 6 25
1246
1
thg 5 25
1505
3
thg 3 25
2187
1
thg 3 25
1643