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

Add columns to treeView v7.0

By
Mike
on 5/12/15, 9:52 AM 818 views

Hi,

im starting with odoo. My goals is add two custome columns (fields) to purchase.purchase_order_tree.

first field Product

second field Quantity

I have only one product so no need to calculation function. When i click purchase orders there is the list of all purchase orders, and there i need to see Purchase product and quantity.

my XML


<?xml version="1.0" encoding="utf-8"?>

    <openerp>
       <data>
             <record id="view_purchase_inherit_form" model="ir.ui.view">
                    <field name="name">purchase.inherit.form</field>
                    <field name="model">purchase.order</field>
                    <field name="inherit_id" ref="purchase.purchase_order_tree"/>
                    <field name="arch" type="xml">
                             <xpath expr="//field[@name='amount_total']" position="after">
                                      <field name="product_purchase"/>
                                      <field name="quantity_purchase"/>
                             </xpath>
                   </field>
             </record>
        </data>
</openerp>



What im looking for is code for my.py file.


Many thanks for any advice.

1

Jérémy Kersten (jke)

--Jérémy Kersten (jke)--
2993
| 3 2 5
Jodoigne, Belgium
--Jérémy Kersten (jke)--

Jérémy is a member of the core R&D team since september 2013. He developed several projects for OpenERP version 8 including the eCommerce, the Google Calendar synchronization and the new product variants/configurator. Now, he manages Odoo website and themes for saas.

Jérémy Kersten (jke)
On 5/12/15, 12:14 PM

Hi,

It will only work if you have only one line (will show only the first line) like in your question !

# -*- coding: utf-8 -*-
from openerp.osv import fields, osv
class purchase_order(osv.osv):
_inherit = 'purchase.order'
_columns = {
'product_qty': fields.related('order_line', 'product_qty', type='integer', string='Quantity'),
}
 

And to edit the view  

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_purchase_inherit_tree" model="ir.ui.view">
<field name="name">purchase.inherit.tree</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_tree"/>
<field name="arch" type="xml">
<field name="state" position="after">
<field name="product_id"/>
<field name="product_qty"/>
</field>
</field>
</record>
</data>
</openerp>

0
Mike
On 5/13/15, 5:38 AM

Hi,

im contiune with study, now im trying to add same fields to sale orders, in developher mode i looked for correct model and inherited :

but im resived

2015-05-13 13:58:22,815 888 WARNING pokus openerp.osv.orm.browse_record.product.product: Field '_asdict' does not exist in object 'browse_record(product.product, 1)'
2015-05-13 13:58:22,815 888 WARNING pokus openerp.osv.orm.browse_record.product.product: Field '_asdict' does not exist in object 'browse_record(product.product, 1)'
2015-05-13 13:58:22,987 888 INFO pokus werkzeug: 127.0.0.1 - - [13/May/2015 13:58:22] "POST /web/dataset/search_read HTTP/1.1" 500 -
2015-05-13 13:58:23,006 888 ERROR pokus werkzeug: Error on request:
Traceback (most recent call last):
File "werkzeug\serving.py", line 177, in run_wsgi

File "werkzeug\serving.py", line 165, in execute

File "C:\OpenERP 7.0\server\openerp\service\wsgi_server.py", line 417, in application
return application_unproxied(environ, start_response)
File "C:\OpenERP 7.0\server\openerp\service\wsgi_server.py", line 403, in application_unproxied
result = handler(environ, start_response)
File "C:\OpenERP 7.0\server\openerp\addons\web\http.py", line 528, in __call__
return self.dispatch(environ, start_response)
File "C:\OpenERP 7.0\server\openerp\addons\web\http.py", line 487, in __call__
return self.app(environ, start_wrapped)
File "werkzeug\wsgi.py", line 579, in __call__

File "C:\OpenERP 7.0\server\openerp\addons\web\http.py", line 553, in dispatch
result = handler(request)
File "C:\OpenERP 7.0\server\openerp\addons\web\http.py", line 618, in <lambda>
return lambda request: JsonRequest(request).dispatch(method)
File "C:\OpenERP 7.0\server\openerp\addons\web\http.py", line 251, in dispatch
body = simplejson.dumps(response)
File "simplejson\__init__.py", line 354, in dumps

File "simplejson\encoder.py", line 264, in encode

File "simplejson\encoder.py", line 612, in _iterencode

File "simplejson\encoder.py", line 568, in _iterencode_dict

File "simplejson\encoder.py", line 568, in _iterencode_dict

File "simplejson\encoder.py", line 455, in _iterencode_list

File "simplejson\encoder.py", line 568, in _iterencode_dict

File "simplejson\encoder.py", line 622, in _iterencode

File "simplejson\encoder.py", line 239, in default

TypeError: browse_record(product.product, 1) is not JSON serializable

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_sale_inherit_tree" model="ir.ui.view">
<field name="name">sale.inherit.tree</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_tree"/>
<field name="arch" type="xml">
<field name="state" position="after">
<field name="product_id"/>
<field name="product_qty"/>
</field>
</field>
</record>
</data>
</openerp>
from openerp.osv import fields, osv


class sale_order(osv.osv):
_inherit = 'sale.order'

_columns = {
'product_qty': fields.related('order_line', 'product_uom_qty', type='integer', string='Quantity'),
'product_id': fields.related('order_line', 'product_id', type='integer', string='Product'),
}

Strange, I have just copy-past, and it works well :/

Jérémy Kersten (jke)
on 5/13/15, 5:53 AM

new database didnt help, new error Error maximum recursion depth exceeded, i changed many moduls and many codes, maybe i have a mess in base module. Hope so fresh install will fix it.

Mike
on 5/13/15, 8:00 AM

error from log : View error', u"Can't find field 'product_id' in the following view parts composing the view of object model 'sale.order':\n * sale.inherit.tree\n\nEither you wrongly customized this view, or some modules bringing those views are not compatible with your current data model")

Mike
on 5/13/15, 8:37 AM

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

2 follower(s)

Stats

Asked: 5/12/15, 9:52 AM
Seen: 818 times
Last updated: 5/13/15, 10:13 AM