Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Internal reference column sortable

By
Roberto Barreiro
on 6/17/16, 6:11 AM 470 views

I added the column "internal reference" to the "product.template.product.tree" view.  Unfortunately, this column is not sortable. Is there any way to make it sortable? Thanks in advice.

Here is the code of my custom view:

<openerp>
<data>
<record id="product_template_tree_view_custom_fields" model="ir.ui.view">
<field name="name">product.template.tree.view.custom.fields</field>
<field name="model">product.template</field>
<field name="type">tree</field>
<field name="inherit_id" ref="product.product_template_tree_view"/>
<field name="arch" type="xml">
<field name="name" position="before">
<field name="default_code"/>
<field>
</field>
</record>
</data>
</openerp>

 

1

deep

--deep--
1617
| 5 4 7
Bengaluru, India
--deep--

Techno-Functional Associate with 6+ years of experience in Odoo (formerly known as OpenERP).

deep
On 6/17/16, 7:00 AM

I guess the column "internal reference" which you have added is either a related or computation field, which is not saved to database, if yes then sorting will not happen.

Sorting is a property availed from database, hence you can perform sorting action only on those columns which are actually present/stored into the database.

By default all the basic data-type columns (such as Char, Float etc) will be physically created into the table except for related & computation fields, for which one need to store it explicitly into the database by adding the property "store=True" against the field in PyObject/Class.


The field named "internal reference" it's stored on database, on the table "product_product". On the interface of odoo, the label of this field is "internal reference", but at database the name it's "default_code". The type of the field is "character varying". Thank you.

Roberto Barreiro
on 6/17/16, 9:55 AM

Server restarted and your solution works! Thank you very much!

Roberto Barreiro
on 6/17/16, 12:10 PM
0
Roberto Barreiro
On 6/17/16, 12:12 PM

You are right, now I saw the field default_code on the product_template model, it's a related field to the product_product model. As you said, solved with parameter store=True.

class product_template(osv.osv):

_inherit = 'product.template'

_columns = {

'default_code': fields.related('product_variant_ids', 'default_code', type='char', string='Internal Reference', store=True),

}

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 6/17/16, 6:11 AM
Seen: 470 times
Last updated: 7/5/16, 12:03 PM