This question has been flagged
1 Reply
6166 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 ?


Avatar
Discard
Best Answer

Pass  'no_create_edit': True  in the options like: 

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

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?