This question has been flagged
2 Replies
5976 Views

Odoo 9.0 community edition.

When there is a many2one field in an odoo from it is possible to select "create and edit" from the dropdown menu when populating this field in edit mode. This brings up a window which allows you to create a record. I know that you can also provide a "context" such that some of the fields of the new record are pre-populated for you.

I'd like to have a button with a server action that let's me do some calculations on what the context should be and then bring up this same window (new window). In particular this is about creating a contact from a sales opportunity. I was not able to find the window action to call. I tried the window action called Contacts, and this brings up a contact edit window, although there is no Save button at the bottom.

Avatar
Discard

Hey, did you ever find a solution for this? I am experiencing exactly the same problem and I am very excited to find a solution.

Best Answer

So, it turns out there is *not* a window action behind the "create and edit" button -- it's a widget not an action.


Because of this, you need to set the context attribute on the field node in your view.

<field name="many_to_one_model" context="{'default_field': 'prepopulated value'}"/>

Additionally, you may have to explicitly supply the view to use (in cases where there are two views of the same type for a particular model). To specify a form view, for example, set a form_view_ref context option with the xml id of your view.

'form_view_ref': 'module.many_to_one_model_form_view'
Avatar
Discard

Isaac,

How can I do this for the customer many2one field on sale.order model. When I create a new contact. I want the wizard that opens to be populated with value from sale.order field.