Skip to Content
Menu
This question has been flagged
1 Reply
8674 Views

Hi all,

I'm trying to modify product.template from within a module. Specifically I am looking to make the Internal Reference (default_code) field sortable. I've managed to build up a module that modifies an esiting form, but I can't seem to manage to get the changes to product.template to work.

My __init__.py looks like this:

 # -*- coding: utf-8 -*-
from . import addIntRef
My addIntRef.py looks like this:

 
# -*- coding: utf-8 -*- from openerp.osv import fields, osv class product_template2(osv.osv): _name = 'product.template' _inherit = 'product.template' _columns = { 'default_code': fields.related('product_variant_ids', 'default_code', type='char', string='Internal Reference'), } product_template2()
Note: I am only trying to change the field label in the example above. Ultimately I would like this to make this field sortable...

My __openerp__.py looks like this:

 
# -*- coding: utf-8 -*- { 'name': "Add Internal Reference", 'summary': """Add Internal Reference field to standard forms.""", 'description': """ Adds the default internal reference field to forms so it is visible. This is used for internal part numbers so access to this is important. """, 'author': "Peck Tech Consulting Ltd.", 'website': "http://www.pecktech.ca", 'category': 'Tool', 'version': '0.1', 'depends': ['product'], 'data': ['addIntRef.xml'], 'demo': [], }
And my addIntRef.xml looks like this:

 
<?xml version="1.0"?> <openerp> <data> <record id="product.product_template_tree_view2" model="ir.ui.view"> <field name="name">product.template.product.tree2</field> <field name="model">product.template</field> <field name="inherit_id" ref="product.product_template_tree_view"/> <field name="arch" type="xml"> <xpath expr="//field[@name='name']" position="before"> <field name="default_code"/> </xpath> </field> </record> </data> </openerp>
I loadup the module just fine, and the product.template.product.tree2 view is loaded in and replaces the default one as expected. When I look at the module definition under Settings > Modules > product.template however I see no change to this template.

I've tried marking this field as sortable from the web interface, it does not allow me to save those changes. Plus that would be non-upgrade freindly... I think I am close, but just need some help getting over this last hump.

Oh and if it makes a difference I have Odoo 8 running on a Ubuntu server and I am accessing it from my local Windows 10 box with Chrome browser. I just updated Odoo this AM so should be on latest and greatest...

Any help / hints here would be much appreciated! Thanks!!!

Avatar
Discard
Author

Thanks for the feedback Groover. What I am trying to achieve here is to have the product.template.product.tree view sortable on Internal Reference (default_code) field that I've added. As it is now, I can click on the Name, Internal Category, Product Type and Status and have the records sorted on those. But the newly added field in the tree view is not sortable. I though it was to do with the product.template default_code value not being set to searchable, but looking at some of those other fields it looks like those are not either... So this leads me to believe that I need to change an attribute on that field that I've added to make that work. I still don't know why my product.template changes are not working, but that's secondary now... By the way I did try your suggestion but that did not work. Thinking it has more to do with my implementation though... Time for some more digging! If I look at the product.template (which is ithe source for this view, I find that those fields

Best Answer

Hello

Templates don't change, they are going to be called pn-the-fly and your xpath is going to work there.... So there is nothing that is going to change. About sortable, i'm not sure if I understood your question but that can be solved adding _order = "default_code" to the model definition.

Avatar
Discard
Related Posts Replies Views Activity
5
Oct 20
6109
0
Nov 24
4352
2
Jun 20
3766
1
Jun 16
2463
1
Jun 15
1182