تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
3 الردود
25586 أدوات العرض

I know that we can make a complete form by placing the read-only attribute on each field. But my requirement is to make the complete form read-only based on status (As I have too many fields in my form view).

الصورة الرمزية
إهمال
أفضل إجابة

You can set all fields to readony, using a context value and overriding the fields_view_get() method of your model

Example:

If you want to turn the entire account.invoice form to readonly, you can use the next code, using a context value:

Calling from any specific button, menu or field set a context value. I choose 'turn_view_readonly' value to True
from a the sale order view xml button.

<button name="action_view_invoice" string="View Invoice" type="object" class="oe_highlight"        
context="{'turn_view_readonly':True}"/>


And  inherit  account.invoice code model, checking for this value

from odoo import models, api
from lxml import etree
import simplejson

class AccountInvoice(models.Model):
_inherit = 'account.invoice'
@api.model
def fields_view_get(self, view_id=None, view_type=False, toolbar=False, submenu=False):
context = self._context
res = super(AccountInvoice, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar,
submenu=submenu)

if context.get('turn_view_readonly'): # Check for context value
doc = etree.XML(res['arch'])
if view_type == 'form': # Applies only for form view
for node in doc.xpath("//field"): # All the view fields to readonly
node.set('readonly', '1')
node.set('modifiers', simplejson.dumps({"readonly": True}))

res['arch'] = etree.tostring(doc)
return res

You can also look for 'active_id' or 'active_ids' value in context, and check the state field of the recordset and turn the fields to readonly..

if context.get('active_id') and self.browse(context.get('active_id')).state == 'X':
doc = etree.XML(res['arch'])
# ... etc

  

الصورة الرمزية
إهمال

fields_view_get
This method only gets call when page get refresh, not when you open any record.

أفضل إجابة

You can make a boolean field and make a function to turn it true if status achieved then make view read only if that field is true

الصورة الرمزية
إهمال
أفضل إجابة

Hi,

Can try to add security rule, disable rights to create and edit, grant only read access. 

الصورة الرمزية
إهمال
الكاتب

Dear Sushma. Thank you for your answer. But this is not I'm looking at. I need to make readonly in a specific status for all groups.

Hi Venu,

Indeed, but this is only way you can achieve, with group tag readonly won't work. This need to be added only to fields.

Thanks !

المنشورات ذات الصلة الردود أدوات العرض النشاط
2
يونيو 20
8764
1
مارس 18
6753
2
أكتوبر 18
7737
0
سبتمبر 24
3068
2
يونيو 24
10738