Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Can we freeze or hide create button based on conditions?

By
vadivel
on 7/18/16, 6:36 AM 301 views

Hi everyone.I have to restrict user creation after some limit on form loading.Is it possible.

Note:
When i click on create and when im saving that record after enters details means if i return warning is no good.

May be when i click on create button, i can show some warnings and restrict user creation is better to do.

Can anyne done this before.Please share with me.

1

Tarek Mohamed Ibrahim

--Tarek Mohamed Ibrahim--
896
| 5 3 7
Gîza, Egypt
--Tarek Mohamed Ibrahim--

I am an old VFP developer on ERP

I have moved to 2p since Nov-2014 and started developing with Python on Odoo.

https://www.linkedin.com/profile/public-profile-settings?trk=prof-edit-edit-public_profile

tibrahim@2p.com.sa

Tarek Mohamed Ibrahim
On 7/18/16, 11:32 AM

You have to use Access Rights using the csv access privileges definition file. This can be achieved as follows: 

Define your model

Define security groups, one of them should have read only access rights, and be the parent for all other groups, and its first child a group with Read/Write, with no create access right.

You define the groups in xml file like :

 <record id="group_read_only" model="res.groups">
<field name="name">Group Read Only</field>
<field name="implied_ids" eval="[(4, ref('base.group_user'))]"/>
</record>
<record id="group_read_write" model="res.groups">
<field name="name">Group Read/Write</field>
<field name="implied_ids" eval="[(4, ref('group_read_only'))]"/>
</record>
<record id="group_read_create" model="res.groups">
<field name="name">Group Read/Create</field>
<field name="implied_ids" eval="[(4, ref('group_read_only'))]"/>
</record>

Now defining the csv file, you have to name it "ir.model.access.csv"

Suppose that you have a model called "my_model", and your module is "my_module"
id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
access_my_model_read my.model model_my_model my_module.group_read_only 1 0 0 0
access_my_model_write my.model model_my_model my_module.group_read_write 1 1 0 0
access_my_model_create my.model model_my_model my_module.group_read_create 1 0 1 0

both files should be included in the __openerp__.py definition file

Now you can create users and the user you don't want him create records, then grant him write access only, then the 'Create' button won't be shown for him.

This is a concise description, you can refer to one of the standard modules in the addons folder like 'sale' module and imitate the patterns there.

I also didn't mention the 'delete' access right, it would be done the same way as 'create' & 'write', using the 'unlink' column in the csv file.

0
Saravanakumar P
On 7/18/16, 8:23 AM

Hi Vadivel,

     Create method is available in each model. [def create(self, vals): ]  Add your conditions to restrict user creation

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 7/18/16, 6:36 AM
Seen: 301 times
Last updated: 7/18/16, 11:32 AM