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.
Related
May be I am a bit distracted with the current situation, but I cannot understand why this is not working:
I have a model, named my.comodel. This model has a field named invisible, a Boolean.
On the other hand, I have another model, which has an One2many field named my_o2m_field and points to my.comodel. I just want that this field shows only the records whose field invisible is False:
my_o2m_field = fields.One2many(
comodel_name='my.comodel',
inverse_name='my_m2o_field',
domain="[('invisible', '=', False)]",
# domain=[('invisible', '=', False)],
string='Test',
)
I have tried with both domains (and a lot more) with no result. The point is when I go to the technical interface and look for the field in the database structure, the field is updated with all the changes I did to it, except for the domain, which always remains empty. And if I try to modify it through the interface just to test, I get the message which warns you to change field properties by code, not by interface.
Any ideas of what is happening? Or how can I manage what I want? I have an idea but it would be too messy.
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:
In res.partner form view of sale.order, you got this code:
<field name="partner_id" on_change="onchange_partner_id(partner_id, context)" domain="[('customer','=',True)]" context="{'search_default_customer':1, 'show_address': 1}" options='{"always_reload": True}'/>
This view takes res.partner address into form ie: context="{'search_default_customer':1, 'show_address': 1}" now, I want this same behavior BUT on tree view.
I just copied this context into tree view, on partner_id field, but nothing happens, I tried many ways, with no results.
I'd like to have the partner's address on tree view also.
Anybody knows how to accomplish this?
Thanks in advance!
As per my point of view, context is used for often available as contextual actions on resources;
context is nothing but a python directory.
In your case this context will be update with your predefined value like here you have update it with 2 keys.
so when you use any method on this field like on_change so in that case you can use this updated context.
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.
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.