Ir al contenido
Menú
Se marcó esta pregunta
3 Respuestas
15938 Vistas

In my custom module i have this field:

'stage_id': fields.selection([
        ('draft', 'Draft'),
        ('final', 'Final'),
        ('modified', 'Modified'),
        ], 'Status',
        help="Contract Status", track_visibility='onchange'),

and in the XML view:

<header>
    <button name="action_final" attrs="{'invisible': [('stage_id', '!=', 'draft')]}" type="object" string="Final" class="oe_highlight"/>
    <button name="action_modified" attrs="{'invisible': [('stage_id', '!=', 'final')]}" type="object" string="Modified" class="oe_highlight"/>
    <field name="stage_id" widget="statusbar"  statusbar_visible="draft,final,modified"  statusbar_colors='{"draft":"red","final":"blue"}'/>
</header>

and yet my statusbar widget refuses to be colored on any stage. I am trying to use stage_id as states, thought.

or am i using states in a wrong way?

Avatar
Descartar
Mejor respuesta

Check the following post: ../question/2154/how-to-add-a-new-value-to-a-selection-field-state-in-saleorder/

If you still have problem with the colour, check if the same field (in your case 'state') appears twice in the form. If this is the case, the widget "statusbar" won't display the colour properly.

Avatar
Descartar
Mejor respuesta

Hi Adrian,

Try to define a default value for your custom selection field on the python class. Here an example:

 _defaults = {  
        'stage_id': 'draft',
        }
Avatar
Descartar

Hi there, I have the same problem. The states just simply refuse to be colored. I have set _defaults for my state but it still does not get colored. Anything else that I am missing?

Hi there, I have the same problem. The states just simply refuse to be colored. I have set _defaults for my state but it still does not get colored. Anything else that I am missing?

Hi Aaron Neo, could you post your code here please like Adrian?

Mejor respuesta

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

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
ene 25
2818
1
ene 24
1317
4
may 19
12311
1
mar 15
7223
2
mar 15
6321