searching items in a many2one field having the attribute widget="selection" - python

I have created some groups of users who should not create new products while creating a purchase order. So as a solution, i made the product_id as a many2one field and in the xml side, i added widget="selection".
I have now a selection field without the possibility of creation of new products (which is good) but the problem is that i cannot search or filter these products.
Any ideas?
(i Want to have this pop up window:

I found the solution:
when i was using widget="selection", i had not the possibility to search more products because the field became a selection field.
Instead, i used
<field name="product_id" options="{'no_quick_create': True, 'no_create_edit' :
True}" />
Now, i have the "search more" option as shown in the picture below:

Related

How to perform lookup in form view - OpenERP 7

I need to control visibility of the field based on the value of another field. That another field is a reference. I think I need to do a lookup pretty much the same way as I can do in a module with browse or search methods. But how to do in a view?
View:
<field name="org_no" attrs="{'invisible':[('country_id','!=','Sweden')]}"/>
Model (standard res.partner):
country_id: fields.many2one('res.country', 'Country')
field_view_get is static solution problem where once you set the value on domain, view will follow that, so if that's your requirement you can use it.
or else you can use below solution for better and dynamic behavior.
Take one Boolean field on your object where you wanna control visibility and add it in field as invisible.
Write on_change method of your field based on what you wanna control visibility and using the on change method you can set the value of the above boolean field.
using the First step boolean field on attrs to make field visible on demand.
Thank You
You can directly use this:
<field name="org_no" attrs="{'invisible':[('country_id.name','!=','Sweden')]}"/>
because country_id just stores the ID of the country that is selected in your many2one field
Leaving aside the hard coding, you pretty much have it. Just ensure that the country_id field is on the form so it can be used in the attrs on org_no. If you don't want the user to see the country, just put it on as an invisible field.

openERP restrict users

I'm facing a complex problem, at least for me.
I have a form called "Task", which contains all the normal info, and I would like to add users to that Task.
If I want to add multiple users to that task, I should use the widget one2many, am I right? If so, is it possible to display a dropdown or something and add the users already registered? Because, with the default one2many, I have to register the users (like a Form) and then I can add them..but if they are already in the table, it should appear me a dropdown menu or something..
After the task is created, the users should only see the task with their name, only administrator can view it all. I think that to achieve this I need to create rules, right? If so, do I need to create them by code or could I use the openERP rule menu? And this will be enough: ('user_id', '=', user.id)]? The first column "user_id" is created on "Task" table?
I do not need to have a auxiliary table that would contain something like: id, task_id, id_user..and by this I could get which tasks belongs to whichs users??
Thanks guys
For your cases:
You can try using Many2Many relation so as to choose the record of users.
Use Groups to obtain your desired result.
For example:
<field name="user_id" groups="your_group" />
By doing this you can provide what fields to be visible to which user based on access rights provided in your GROUPS.

how to add a dropdown field to openerp module

Hi I am using openerp 7. I have created a module with some fields . Now I need to declare dropdown fields to add some additional features. Please give me some hint to do this
Hopes for suggestion
For drop down list, you can use selection field.
for example
'type': fields.selection([('a','Type A'),('b', 'Type B')],'Type')
You can want to show a many2one field as selection, for example, companies, in the view add widget="selection"
<field name="company_id" widget="selection">

Explanation about widget="selection"

I need to know what is the actual scenario with widget option in OpenERP 7.
is it works as readonly field when we use it in form views ?
i used it in my one of form.when i save records in form, that widget values are not saved.
<field name="job_position" placeholder="Finance Manager" widget="selection" />
With widget, one can change the look of the field. In OpenERP, one can use such kind of many widget like widget="selection"/"statusbar"/"monetory"/"progressbar"/"html"/"email"/"image", etc. but it does not work as readonly field.
widget="selection" means it will show all the records of position(many2one) in the selection box. It means if you do not want any user to edit/modify it's record, widget="selection" is useful.
Regarding your issue, issue is due to placeholder attribute, that you used. Place holder will display that value in selection box which may not store in your many2one table and that's why while saving the record, value disappears. Try by removing placeholder over there. If you want any value by default in selection , use _defaults attribute in class.

OpenERP: How to display fields of two objects within the same view?

How can I display fields of two record in the same tree view, Knowing that these tables are linked with OneToMany relashionship ?
here is my field:
'class_id': fields.many2one('mod.class', 'Entree', required=True),
In my tree view :
<field colspan="4" name="class_id" nolabel="1" widget="one2many_list"/>
But this can just display foreign key but i need other fields
I'll appreciate any help .Thank you
Usually, I use a related field to display fields from a related table.
Make related field or make a view(database) without table like many reports. Or make dashboard type view . It is upto you and your requirement.
In OpenERP's addons folder goto addons > base > partner > partner.py, there you can see a field named 'address' which is a one2many field. Also you can find some related fields like 'mobile','phone','city' etc. which are related to the address field. These related fields can be used in the tree view.
This is the same thing that you are trying to do.

Categories

Resources