iT邦幫忙

2021 iThome 鐵人賽

DAY 13
0
Software Development

Let's ODOO 開發與應用30天挑戰系列 第 13

Day13 Let's ODOO: Security(2) Group

今天來介紹Group的寫法,Group用意就是分你需要的權限群組,將需要這些權限的人加入,最後再把權限分配給Group,今天以學生的資料權限,我們分為主任、老師、志工三個群組。

在security底下增加res_student_group.xml,記得__mainfest__內要填入path

<odoo>
    <data>
        <record model="ir.module.category" id="module_category_education">
            <field name="name">Education</field>
            <field name="description">About education</field>
        </record>
        
        <record model="res.groups" id="group_school_teacher">
            <field name="name">Teacher</field>
            <field name="category_id" ref="module_category_education"/>
        </record>
        
        <record model="res.groups" id="group_school_director">
            <field name="name">Director</field>
            <field name="category_id" ref="module_category_education"/>
        </record>
                
        <record model="res.groups" id="group_school_volunteer">
            <field name="name">Volunteer</field>
            <field name="category_id" ref="module_category_education"/>
        </record>

    </data>
</odoo>

首先我們先增加一個group category,讓我們的群組有個類別,以便日後好管理這些權限

category的model為ir.module.categoryid 不重複即可。

接下來就是定義group,model固定為res.groups ,其他也都依需求定義,最後記得把剛剛設定的category record指向category_id欄位內。

重新啟動後,在Settings/Users & Companies/Groups內便能看到,記得Groups必須開啟開發者模式:

https://ithelp.ithome.com.tw/upload/images/20210928/20130896pmo4XqUjeN.png

接著我們結合昨天所說,將ir.model.access.csv 重寫:

id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_res_student_director,access_res_student,res.student,model_res_student,group_school_director,1,1,1,1,
access_res_student_teacher,access_res_student_teacher,model_res_student,group_school_teacher,1,1,1,0
access_res_student_volunteer,access_res_student_volunteer,model_res_student,group_school_volunteer,1,0,0,0

如此以來就如昨天所說,志工層級只能讀取員工資料,老師層級可以增加及修改,只有主任層級才有刪除的功能,剩下要做的就是將使用者加入各自的group,我們的權限設定就完成了。

今天就介紹到這邊,明天我們來將Model加入至Odoo的Menu當中。


上一篇
Day12 Let's ODOO: Security(1) Access right
下一篇
Day14 Let's ODOO: Security(3) Record rules
系列文
Let's ODOO 開發與應用30天挑戰30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言