Hi ZEeineb,
I attach my code here.
class Asset(osv.osv):
_name = "asset"
_description = "Asset (MRO of Assets)"
_inherit = "product.product"
_columns = {
'deployed': fields.boolean('Deployed'),
'asset_deploy_address': fields.one2many('asset_deploy_address', 'asset_id', 'Deploy Address'),
'current_customer': fields.related('asset_deploy_address', 'address_id', 'customer_id', 'name', type='char', string='Customer'),
'current_location': fields.related('asset_deploy_address', 'address_id', 'name', type='char', string='Location'),
'current_address': fields.related('asset_deploy_address', 'address_id', 'address', type='char', string='Address'),
'stage': fields.selection([
('new', 'Draft'),
('deploy', 'Deploy Asset'),
('complete', 'Completed'),
],'Status', readonly=True, select=True, help='Workflow stages'),
}
_defaults = {
'deployed':False,
'stage':'new',
}
After much investigation, I found out that it is due to inheriting product.product model. Because product.product already has "state" fields, so specifying my own "state" field would add-on to it. However, states are still not being colored in the statusbar widget. I didn't have the energy and time to read into the source code of OpenERP base to find out the root cause.
In the end, my solution is to change my "state" field to "stage". Then in my view (XML) i used "attrs" attribute to hide buttons by detecting the value of "stage" field element. See code below.
<record model="ir.ui.view" id="asset_form_view">
<field name="name">asset.form.view</field>
<field name="model">asset</field>
<field name="type">form</field>
<field name="priority" eval="1"/>
<field name="inherit_id" ref="product.product_normal_form_view"/>
<field name="arch" type="xml">
<sheet position="before">
<header>
<button name="specify_holding_wh" string="Specify holding warehouse" attrs="{'invisible':['|',('stage','=','deploy'),('stage','=','complete')]}"/>
<button name="specify_holding_wh_repeat" string="Specify holding warehouse" attrs="{'invisible':['|',('stage','=','new'),('stage','=','complete')]}"/>
<field name="stage" widget="statusbar" statusbar_visible="new,deploy,complete" statusbar_colors='{"new":"red","complete":"blue"}'/>
</header>
</sheet>
This workaround works pretty well. My "stage" statusbar widget now gets colored and buttons show and hide as desired.
If you know how to solve the inherited "state" field problem, let tell me how. Thanks!
Regards,
Aaron