Implementation of Field View Function

In our application we had two servers one is 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 various domain,required,readonly condition depending upon view_id through python.
These function is called on loading the page only once.

You must be logged in to post a comment.