You're on the right track by restricting access in the backend via Python, but that does not hide the "Import" button in the UI — it only prevents the action when triggered.
To hide the "Import" button in the UI (tree views), you need to override it at the view level using XML.
1. Hide Import Button via XML View Inheritance
Create a webclient_templates.xml in your module and add:
<odoo>
<template id="webclient_templates" inherit_id="web.webclient_templates" name="Hide Import Button for Certain Groups">
<xpath expr="//div[@class='o_control_panel']" position="before">
<t t-if="not (user.has_group('custom_crm.group_crm_coordinator') or user.has_group('sales_team.group_sale_manager'))">
<t t-set="can_import" t-value="False"/>
</t>
</xpath>
</template>
</odoo>
This snippet disables the import button in the Odoo UI for users not in the allowed groups.
2. Backend Protection (Your Python Code)
Your existing code is good — just make sure it's hooked in via the correct inheritance.
models/base_model.py
You can put this inside a standard views folder in your module and reference it in your __manifest__.py.
from odoo import models, _
from odoo.exceptions import AccessError
class BaseModel(models.AbstractModel):
_inherit = 'base'
def load(self, fields, data):
allowed_groups = [
'custom_crm.group_crm_coordinator',
'sales_team.group_sale_manager',
]
if not any(self.env.user.has_group(g) for g in allowed_groups):
raise AccessError(_("You are not allowed to import records."))
return super(BaseModel, self).load(fields, data)
The XML hides the button from the UI for restricted users.
The Python code blocks direct API imports or external calls (security fallback).
Both together ensure full control.
Is the supposed to be allowed to create records 'in all models of the module' manually? If no, it should be way easier to deny create permission altogether. (If yes, why..?)