Odoo Help


Odoo 9: Make popup form of many2one read-only

Peter Nietz
on 5/10/16, 5:18 AM 1,749 views

In our own module we need to connect work being done with invoices, more precisely with invoice lines. Therefore we defined two many2one fields in our custom model:

invoice_id = fields.Many2one('account.invoice')
invoice_line_id = fields.Many2one('account.invoice.line')

The invoice lines do not have a usable display name by default. Hence we have overridden the invoice line model and re-implemented the method "name_get" to deliver a usable display name. So far everything works fine.

Our view prevents creating invoices or invoice lines on-the-fly by setting the appropriate field options in the view:

<field name="invoice_id" domain="[('state','not in',['draft','cancel'])]" options="{'no_create':True}"/>
<field name="invoice_line_id" domain="[('invoice_id','=',invoice_id)]" options="{'no_create':True, 'always_reload':True}"/>

We explicitly want to use the hyperlink to open the referenced invoice / invoice line. This allows the user to verfiy the content of the selected invoice / invoice line (making sure that he selected the correct one). That means we explicitly do not want to add "'no_open': True" to the field options.

The only problem is: When clicking the open button next to the many2one field the opened form is always in edit mode. This is not an issue for the invoice field (we allow only selecting validated invoices, which are read-only by default). But it is an issue for the invoice line field since it allows editing even though the invoice has already been validated. Hence our many2one field allows to bypass the readonly protection of validated invoices. This is of course not good...

How can we modify a many2one field such that the opened popup is strictly in view mode only / read only ?


Prakash Sharma

--Prakash Sharma--
--Prakash Sharma--

I like to surround myself with brave, creative people.

My motivation for learning different technologies and algos drive me. I love challenges of a steep learning curve which I believe makes me a better learner. I have a strong desire to learn different technologies, which would enable me to become a full stack developer.

Prakash Sharma
On 5/10/16, 8:14 AM

Pass  'no_create_edit': True  in the options like: 

<field name="field_name" options="{'no_create_edit': True}"/>

I tried this one, but it does not seem to have any effect, at least not for many2one fields. Also I found the information that "no_create" already includes "no_create_edit" (http://ludwiktrammer.github.io/odoo/form-widgets-many2many-fields-options-odoo.html). Do you use the construction above in production?

Peter Nietz
on 5/10/16, 8:45 AM

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 5/10/16, 5:18 AM
Seen: 1749 times
Last updated: 5/10/16, 8:14 AM