Implementation of Field View Function

How to implementation of Field View Functionin Odoo

How to implementation of Field View Function

This blog is all more about how to Implementation of Field View Function in odoo.In our application we had two servers one is the main server and the other one is its copy with the same fields known as branch server, but we got the requirement from client that in main server we need to create the record and it has to be synced with branch server as well and in the branch server all those fields should be read only, so that, the end user can not make changes in the records in the branch .To solve this we used a function by which at run time we can control the fields as per requirement.

For example, we can make the fields mandatory or read only as we wish.

Function defination :

def fields_view_get(self, cr, user, view_id=None, view_type=’form’, context=None, toolbar=False, submenu=False)
return type of the above function is view archtecture.
Now import :
from openerp.osv.orm import setup_modifiers
from tools.translate import _
from lxml import etree

def fields_view_get(self, cr, user, view_id=None, view_type=’form’, context=None, toolbar=False, submenu=False):
if context is None: context = {}
res = super(self.__class__, self).fields_view_get(cr, user, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
doc = etree.XML(res[‘arch’])
tmp_field = “//field[@name=”name”]”
for node in doc.xpath(tmp_field):
node.set(‘readonly’, _(“1”))
setup_modifiers(node)
res[‘arch’] = etree.tostring(doc)
return res

Same way you can try for the various domain, required, read-only condition depending upon view_id through python. This function is called on loading the page only once.

You must be logged in to post a comment.