コンテンツへスキップ
メニュー
この質問にフラグが付けられました
3 返信
10121 ビュー

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>

 

アバター
破棄
最善の回答

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.

著作者

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

著作者 最善の回答

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),

}

アバター
破棄

I am new to this. Could I have the steps to where I can place the above code in odoo?

著作者

The code it's placed on a customized module. Take a look at this addon, this code belongs to it:

https://www.odoo.com/apps/modules/9.0/product_tree_view_internal_reference_sortable/

Thank you very much for sharing this module. It is exactly what is needed. This module will help us save much time. Thank you again for sharing the module.

最善の回答

Hi, 

am not a developer, will i be able with some steps to perform what you mentioned above ?

アバター
破棄
関連投稿 返信 ビュー 活動
1
7月 19
3484
0
7月 24
1021
2
4月 21
3914
0
3月 17
2790
11
10月 24
99859