Skip to Content
Menu
This question has been flagged
3 Replies
34111 Views

Hello,

I've added an additional status (draft, sale, etc) to the state field of the sales order model and I would like to add it to the sales order form.

I am using the following xpath sequence to do so:

<xpath expr="//field[@name='state']" position="attributes">    
          <attribute name="statusbar_visible" >{new_status}</attribute>
</xpath>

The problem is that xpath replaces all the existing values (draft,sent,sale )of the attribut statusbar_visible !

I've searched over the net but I didn't found a way to add one attribute value to the existing ones.

Does anyone knows how I can do this (without hard coding the existing values in the xpath sequence) ?


Thanks !

Avatar
Discard

HI Avinash and thank you for your answer!

I already extended the sale order model adding the new value to the state selection field.

I fully agree with you I can simply write all the standard attribute values plus my new one in the attribute field inside the xpath locator.

But if I do this, I am actually overriding the existing sale.order attribute values.

What I would like to do is just add my new value attribute to the others, so if one day Odoo decides to create a new state to this model I won't be overriding it without knowing

Do you think is there a way to insert a attribute value into the existing ones without overriding the whole statusbar_visible attributes?

Thank you!!

Best Answer

Use the add and separator properties of the <attribute> tag.

Take for example the following template from addons/website_blog/views/website_blog_templates.xml 

    203 <!-- Option: Blog Post List: grid layout -->
    204 <template id="opt_blog_post_grid_layout" name="Grid view"
    205         customize_show="True" active="False" inherit_id="website_blog.blog_post_short">
    206     <xpath expr="//div[@name='blog_post']" position="attributes">
    207         <attribute name="class" add="col-sm-5 o_grid" separator=" "/>
    208     </xpath>
    209 </template>



Avatar
Discard

This is an old post, I appreciate you still leave the correct answer for reference.

I just tested on Odoo 12 CE, works great! Thank you.

Anytime, Justin. I'm glad it helped.

Best Answer

Hi,

Please add previous values and new values both in the attributes.

eg:

How to add new values to state

state = fields.Selection(selection_add=[('new_state', 'New State')])

for visible the value in the form view

<xpath expr="//field[@name='state']" position="attributes">
<attribute
name="statusbar_visible">draft,sent,sale,new_state</attribute>
</xpath>

Thank you 

Avatar
Discard