[ADD] account_asset: Added fields_view_get method for setting the fields invisible based on Time method of asset.

bzr revid: uco@tinyerp.com-20110627122239-byt91wu5b1akzzgq
This commit is contained in:
Ujjvala Collins (OpenERP) 2011-06-27 17:52:39 +05:30
parent 89d9c9407d
commit a5b04d3de0
2 changed files with 33 additions and 3 deletions

View File

@ -19,6 +19,7 @@
#
##############################################################################
import time
from lxml import etree
from osv import osv, fields
@ -33,7 +34,36 @@ class asset_modify(osv.osv_memory):
'method_end': fields.date('Ending date'),
'note': fields.text('Notes'),
}
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
""" Returns views and fields for current model.
@param cr: A database cursor
@param user: ID of the user currently logged in
@param view_id: list of fields, which required to read signatures
@param view_type: defines a view type. it can be one of (form, tree, graph, calender, gantt, search, mdx)
@param context: context arguments, like lang, time zone
@param toolbar: contains a list of reports, wizards, and links related to current model
@return: Returns a dictionary that contains definition for fields, views, and toolbars
"""
asset_obj = self.pool.get('account.asset.asset')
result = super(asset_modify, self).fields_view_get(cr, uid, view_id, view_type, context=context, toolbar=toolbar, submenu=submenu)
if not context:
context = {}
asset_id = context.get('active_id', False)
active_model = context.get('active_model', '')
if active_model == 'account.asset.asset' and asset_id:
asset = asset_obj.browse(cr, uid, asset_id, context=context)
doc = etree.XML(result['arch'])
if asset.method_time == 'delay':
node = doc.xpath("//field[@name='method_end']")[0]
node.set('invisible', '1')
elif asset.method_time == 'end':
node = doc.xpath("//field[@name='method_delay']")[0]
node.set('invisible', '1')
result['arch'] = etree.tostring(doc)
return result
def default_get(self, cr, uid, fields, context=None):
""" To get default values for the object.
@param self: The object pointer.

View File

@ -13,8 +13,8 @@
<field name="name" colspan="4"/>
<field name="method_period"/>
<group colspan="2" col="2">
<field name="method_delay" attrs="{'invisible': [('method_end','!=',False)]}"/>
<field name="method_end" attrs="{'invisible': [('method_delay','!=',0.0)]}"/>
<field name="method_delay"/>
<field name="method_end"/>
</group>
<separator string="Notes" colspan="4"/>
<field name="note" nolabel="1" colspan="4"/>