summaryrefslogtreecommitdiff
path: root/indoteknik_custom
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2024-02-07 15:17:15 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2024-02-07 15:17:15 +0700
commit1a339c7e5b644add00c3bd7c623cb6d4553277cf (patch)
tree966b744ecde042810aebbf61b658ecfe31e59bc2 /indoteknik_custom
parent953c3e611af5c57a8f7d57b5f2f651314c2a92a3 (diff)
parent20b1410fc2335f51ab08fdbecb54d6bfc437b6e1 (diff)
Merge branch 'feature/role-permission' into production
# Conflicts: # indoteknik_custom/__manifest__.py # indoteknik_custom/models/__init__.py
Diffstat (limited to 'indoteknik_custom')
-rwxr-xr-xindoteknik_custom/__manifest__.py2
-rwxr-xr-xindoteknik_custom/models/__init__.py1
-rw-r--r--indoteknik_custom/models/base_import_import.py9
-rwxr-xr-xindoteknik_custom/models/res_users.py17
-rw-r--r--indoteknik_custom/models/role_permission/__init__.py1
-rw-r--r--indoteknik_custom/models/role_permission/ir_model_access.py9
-rw-r--r--indoteknik_custom/views/role_permission/ir_model_access.xml16
-rw-r--r--indoteknik_custom/views/role_permission/res_groups.xml45
8 files changed, 97 insertions, 3 deletions
diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py
index b8a5f6f8..9c505916 100755
--- a/indoteknik_custom/__manifest__.py
+++ b/indoteknik_custom/__manifest__.py
@@ -110,6 +110,8 @@
'views/po_multi_cancel.xml',
'views/logbook_sj.xml',
'views/report_logbook_sj.xml',
+ 'views/role_permission/ir_model_access.xml',
+ 'views/role_permission/res_groups.xml',
'report/report.xml',
'report/report_banner_banner.xml',
'report/report_banner_banner2.xml',
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py
index 49e3567c..327da2d5 100755
--- a/indoteknik_custom/models/__init__.py
+++ b/indoteknik_custom/models/__init__.py
@@ -101,3 +101,4 @@ from . import stock_quant
from . import po_multi_cancel
from . import logbook_sj
from . import report_logbook_sj
+from . import role_permission
diff --git a/indoteknik_custom/models/base_import_import.py b/indoteknik_custom/models/base_import_import.py
index 6a100cb8..01e02a4a 100644
--- a/indoteknik_custom/models/base_import_import.py
+++ b/indoteknik_custom/models/base_import_import.py
@@ -56,7 +56,10 @@ class Import(models.TransientModel):
raise UserError(message)
def do(self, fields, columns, options, dryrun=False):
- enable_import = self._check_enable_import()
- if not enable_import:
- self._unable_import_notif()
+ model = self.res_model
+ can_import = self.env.user.check_access(model, 'import')
+
+ if not can_import:
+ raise UserError('You are not allowed to import')
+
return super(Import, self).do(fields, columns, options, dryrun)
diff --git a/indoteknik_custom/models/res_users.py b/indoteknik_custom/models/res_users.py
index 09321fc6..33f64ce3 100755
--- a/indoteknik_custom/models/res_users.py
+++ b/indoteknik_custom/models/res_users.py
@@ -39,3 +39,20 @@ class ResUsers(models.Model):
if not vouchers: return None
return ', '.join(x.code for x in vouchers)
return None
+
+ def check_access(self, model, mode):
+ assert mode in ('read', 'write', 'create', 'unlink', 'import', 'export'), 'Invalid access mode'
+
+ self._cr.execute("""
+ SELECT MAX(CASE WHEN perm_{mode} THEN 1 ELSE 0 END)
+ FROM ir_model_access a
+ JOIN ir_model m ON (m.id = a.model_id)
+ JOIN res_groups_users_rel gu ON (gu.gid = a.group_id)
+ WHERE m.model = %s
+ AND gu.uid = %s
+ AND a.active IS TRUE
+ """.format(mode=mode), (model, self._uid,))
+ r = self._cr.fetchone()[0]
+
+ return bool(r)
+
diff --git a/indoteknik_custom/models/role_permission/__init__.py b/indoteknik_custom/models/role_permission/__init__.py
new file mode 100644
index 00000000..da36bc1e
--- /dev/null
+++ b/indoteknik_custom/models/role_permission/__init__.py
@@ -0,0 +1 @@
+from . import ir_model_access \ No newline at end of file
diff --git a/indoteknik_custom/models/role_permission/ir_model_access.py b/indoteknik_custom/models/role_permission/ir_model_access.py
new file mode 100644
index 00000000..c77e9b79
--- /dev/null
+++ b/indoteknik_custom/models/role_permission/ir_model_access.py
@@ -0,0 +1,9 @@
+from odoo import fields, models
+
+
+class IrModelAccess(models.Model):
+ _inherit = 'ir.model.access'
+
+ perm_import = fields.Boolean(string='Import Access')
+ perm_export = fields.Boolean(string='Export Access')
+ \ No newline at end of file
diff --git a/indoteknik_custom/views/role_permission/ir_model_access.xml b/indoteknik_custom/views/role_permission/ir_model_access.xml
new file mode 100644
index 00000000..0c74d5e2
--- /dev/null
+++ b/indoteknik_custom/views/role_permission/ir_model_access.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<odoo>
+ <data>
+ <record id="ir_model_access_tree_view_inherit" model="ir.ui.view">
+ <field name="name">Access Rights</field>
+ <field name="model">ir.model.access</field>
+ <field name="inherit_id" ref="base.ir_access_view_tree_edition"/>
+ <field name="arch" type="xml">
+ <field name="perm_unlink" position="after">
+ <field name="perm_import"/>
+ <field name="perm_export"/>
+ </field>
+ </field>
+ </record>
+ </data>
+</odoo>
diff --git a/indoteknik_custom/views/role_permission/res_groups.xml b/indoteknik_custom/views/role_permission/res_groups.xml
new file mode 100644
index 00000000..910469fd
--- /dev/null
+++ b/indoteknik_custom/views/role_permission/res_groups.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<odoo>
+ <data>
+ <record model="ir.module.category" id="module_category_roles">
+ <field name="name">Roles</field>
+ <field name="sequence">70</field>
+ <field name="visible" eval="0" />
+ </record>
+
+ <record id="group_role_it" model="res.groups">
+ <field name="name">IT</field>
+ <field name="category_id" ref="module_category_roles" />
+ </record>
+
+ <record id="group_role_fat" model="res.groups">
+ <field name="name">FAT</field>
+ <field name="category_id" ref="module_category_roles" />
+ </record>
+
+ <record id="group_role_sales" model="res.groups">
+ <field name="name">Sales</field>
+ <field name="category_id" ref="module_category_roles" />
+ </record>
+
+ <record id="group_role_marketing" model="res.groups">
+ <field name="name">Marketing</field>
+ <field name="category_id" ref="module_category_roles" />
+ </record>
+
+ <record id="group_role_purchasing" model="res.groups">
+ <field name="name">Purchasing</field>
+ <field name="category_id" ref="module_category_roles" />
+ </record>
+
+ <record id="group_role_logistic" model="res.groups">
+ <field name="name">Logistic</field>
+ <field name="category_id" ref="module_category_roles" />
+ </record>
+
+ <record id="group_role_merchandiser" model="res.groups">
+ <field name="name">Merchandiser</field>
+ <field name="category_id" ref="module_category_roles" />
+ </record>
+ </data>
+</odoo> \ No newline at end of file