Skip ke Konten
Odoo Menu
  • Login
  • Uji coba gratis
  • Aplikasi
    Keuangan
    • Akuntansi
    • Faktur
    • Pengeluaran
    • Spreadsheet (BI)
    • Dokumen
    • Tanda Tangan
    Sales
    • CRM
    • Sales
    • POS Toko
    • POS Restoran
    • Langganan
    • Rental
    Website
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Rantai Pasokan
    • Inventaris
    • Manufaktur
    • PLM
    • Purchase
    • Maintenance
    • Kualitas
    Sumber Daya Manusia
    • Karyawan
    • Rekrutmen
    • Cuti
    • Appraisal
    • Referensi
    • Armada
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Acara
    • Otomatisasi Marketing
    • Survei
    Layanan
    • Project
    • Timesheet
    • Layanan Lapangan
    • Meja Bantuan
    • Planning
    • Appointment
    Produktivitas
    • Discuss
    • Approval
    • IoT
    • VoIP
    • Pengetahuan
    • WhatsApp
    Aplikasi pihak ketiga Odoo Studio Platform Odoo Cloud
  • Industri-Industri
    Retail
    • Toko Buku
    • Toko Baju
    • Toko Furnitur
    • Toko Kelontong
    • Toko Hardware
    • Toko Mainan
    Makanan & Hospitality
    • Bar dan Pub
    • Restoran
    • Fast Food
    • Rumah Tamu
    • Distributor Minuman
    • Hotel
    Real Estate
    • Agensi Real Estate
    • Firma Arsitektur
    • Konstruksi
    • Estate Management
    • Perkebunan
    • Asosiasi Pemilik Properti
    Konsultansi
    • Firma Akuntansi
    • Mitra Odoo
    • Agensi Marketing
    • Firma huku
    • Talent Acquisition
    • Audit & Sertifikasi
    Manufaktur
    • Tekstil
    • Logam
    • Perabotan
    • Makanan
    • Brewery
    • Corporate Gift
    Kesehatan & Fitness
    • Sports Club
    • Toko Kacamata
    • Fitness Center
    • Wellness Practitioners
    • Farmasi
    • Salon Rambut
    Perdagangan
    • Handyman
    • IT Hardware & Support
    • Sistem-Sistem Energi Surya
    • Pembuat Sepatu
    • Cleaning Service
    • Layanan HVAC
    Lainnya
    • Organisasi Nirlaba
    • Agen Lingkungan
    • Rental Billboard
    • Fotografi
    • Penyewaan Sepeda
    • Reseller Software
    Browse semua Industri
  • Komunitas
    Belajar
    • Tutorial-tutorial
    • Dokumentasi
    • Sertifikasi
    • Pelatihan
    • Blog
    • Podcast
    Empower Education
    • Program Edukasi
    • Game Bisnis 'Scale Up!'
    • Kunjungi Odoo
    Dapatkan Softwarenya
    • Download
    • Bandingkan Edisi
    • Daftar Rilis
    Kolaborasi
    • Github
    • Forum
    • Acara
    • Terjemahan
    • Menjadi Partner
    • Layanan untuk Partner
    • Daftarkan perusahaan Akuntansi Anda.
    Dapatkan Layanan
    • Temukan Mitra
    • Temukan Akuntan
    • Temui penasihat
    • Layanan Implementasi
    • Referensi Pelanggan
    • Bantuan
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dapatkan demo
  • Harga
  • Bantuan

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Akuntansi
  • Inventaris
  • PoS
  • Project
  • MRP
All apps
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Help

How to restrict the values of a field based on user groups?

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
stagesgroupscomputeaccess_rules
15 Replies
7891 Tampilan
Avatar
Ragav Y

I know how to restrict visibility of a field using the groups attribute. But how do I restrict the values that would be visible in the field? 

Here's my specific case:-

So in our application there is a request lifecycle and each request created has to pass through several stages, in a specific order. There are different groups who operate on the request at each stage and their access is restricted to that stage. So a user can only see a request if they have access to the stage it is currently in. And when they open it, they have the ability to process the request and push it to the next stage, if they have access to the next stage. 

We need to know what are the next stages that the request can go through depending on the stage it is currently in. For this we compute a field called "next_stage_ids" in the model file:-

@api.depends('type_id', 'stage_id')
def _compute_next_stage_ids(self):
for record in self:
routes = self.env['request.stage.route'].search(
record._get_next_stage_route_domain())
record.next_stage_ids = (
record.stage_id + routes.mapped('stage_to_id'))

Currently we are giving all the users all the available stage_ids that come after the current stage. But we have to restrict the available stage ids based on the user group that the user belongs to. How do we do this?

Update:-
I should clarify that we already have specified the groups that each stage is allowed to be accessible by. So access control-wise it is configured. But the problem is that we have a widget at the right top where it shows which is the next stage that it should be moved to and it is visible regardless of whether the user has access to that stage or not. When a user clicks on it, it will either completed the moving to the stage or say that they don't have access. What I need is for that stage to not even show up on the screen if they don't have access. I'm sorry, I should have clarified this in the original post.

0
Avatar
Buang
Sehrish

Groups and Access Rights: https://goo.gl/4jAhtH

Avatar
Mohammed Rida Yahla
Jawaban Terbai

Hi,

Why dont you make it easy for yourself bro , and just add a groups_ids field in 'request.stage.route':

like : groups_ids = field.Many2many('res.groups')

and after you add it and display it in xml views of request.stage.route you can select the groups you want foreach stage_id you create.

and to use it in your functions just like your example, you can : 

First get the groups related to the current user :

groups_uid = self.env['res.users'].browse([uid]).groups_id.ids

intersection_list = [value for value in   groups_uid if value in self.stage_id.groups_ids.ids]

if intersection_list : # wich means you're testing if this current user has at least one group of the selected groups in this stage_id.

Dont forget to vote positive.



2
Avatar
Buang
Ragav Y
Penulis

We've based it not on specific users, but groups of users. It's a large organization with changing users. Only the groups remain constant.

Mohammed Rida Yahla

well in that case instead of doing res.users , do groups_ids = field.Many2many('res.groups'), , so you can select groups you want for each stage_id you create

Ragav Y
Penulis

mireda, thanks for the suggestion. I should have clarified this earlier. Please see my update in the original post above.

Mohammed Rida Yahla

ur welcome, i edited the answer for you :) , hope it make sense

Ragav Y
Penulis

I tried to implement what you've suggested in your answer. I am seeing an error. Please check if I've made some mistake in using your code:-

@api.depends('type_id', 'stage_id')

def _compute_next_stage_ids(self):

for record in self:

routes = self.env['request.stage.route'].search(

record._get_next_stage_route_domain())

groups_uid = self.env['res.users'].browse([self.env.user.id]).groups_id.ids

intersection_list = [value for value in groups_uid if value in self.stage_id.groups_ids.ids]

if intersection_list:

record.next_stage_ids = intersection_list

# record.next_stage_ids = (

# record.stage_id + routes.mapped('stage_to_id'))

Initially I was seeing an error in the group_uids line, so I replaced "uid" in your original comment with self.env.user and it worked but now it is stalling in the intersection_list line and I don't understand your code enough to modify it on my own. Could you explain your code please?

Thank you!

Mohammed Rida Yahla

Still no votes xD, my idea , brother , this line: intersection_list = [value for value in groups_uid if value in self.stage_id.groups_ids.ids]

to get get commun groups_ids between the groups of the current user , and the groups selected in your current stage_id

Ragav Y
Penulis

Ok I see what you're trying, but for some reason I can't seem to fix the error. I don't mind giving upvotes, but I need the problem solved. And as mentioned above my problem still remains. But thanks for trying.

Mohammed Rida Yahla

mail me your code , my user name is my mail

Ragav Y
Penulis

Sent you email.

Mohammed Rida Yahla

brother, you didnt add a field in request.stage !! you have to to add groups_ids field there

Ragav Y
Penulis

Ok, thanks for your efforts. I will try and update you. Btw, I've upvoted your answer.

Mohammed Rida Yahla

thank you brother , and nice to meet you , i'll be in touch whenver you need any help :)

Avatar
Haresh Kansara
Jawaban Terbai

Hi Ragav,

In this case, record rule will helpful.

What you need to do is, 

for stages, actually it's a model records, so you can create mutliple access groups for accessibility and assign record rules based on groups. So stages only visible to that group's users. 

Record Rules

How to create record rules


I hope it will helpful for you.

Regards

Haresh Kansara

0
Avatar
Buang
Menikmati diskusi? Jangan hanya membaca, ikuti!

Buat akun sekarang untuk menikmati fitur eksklufi dan agar terlibat dengan komunitas kami!

Daftar
Post Terkait Replies Tampilan Aktivitas
Unable to set access control on view element in XML via groups="" attribute. What am I missing? Diselesaikan
groups access_rules
Avatar
Avatar
1
Des 19
5875
Give a Single User Access Rights to Specific Field
groups record_rules access_rules
Avatar
Avatar
Avatar
2
Agu 23
3852
How to use groups to restrict field access rights?
groups access_rules v12
Avatar
Avatar
Avatar
Avatar
3
Des 20
11358
Allow "Project / Users" creating new task stages (Kanban view) Diselesaikan
project stages task groups
Avatar
Avatar
Avatar
2
Mar 25
3495
Adding Another Internal User Group (Odoo V14)
rights groups internal access_rules
Avatar
Avatar
1
Mar 25
3425
Komunitas
  • Tutorial-tutorial
  • Dokumentasi
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Terjemahan
Layanan
  • Odoo.sh Hosting
  • Bantuan
  • Peningkatan
  • Custom Development
  • Pendidikan
  • Temukan Akuntan
  • Temukan Mitra
  • Menjadi Partner
Tentang Kami
  • Perusahaan kami
  • Aset Merek
  • Hubungi kami
  • Tugas
  • Acara
  • Podcast
  • Blog
  • Pelanggan
  • Hukum • Privasi
  • Keamanan
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo adalah rangkaian aplikasi bisnis open source yang mencakup semua kebutuhan perusahaan Anda: CRM, eCommerce, akuntansi, inventaris, point of sale, manajemen project, dan seterusnya.

Mudah digunakan dan terintegrasi penuh pada saat yang sama adalah value proposition unik Odoo.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now