Skip to Content
Menu
This question has been flagged
2 Replies
4881 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.

Avatar
Discard
Best Answer

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>

Avatar
Discard
Author Best Answer

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'),
}
Avatar
Discard

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

Author

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.

Author

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

Related Posts Replies Views Activity
2
Aug 23
1837
3
Apr 23
1032
3
Dec 22
31943
1
Mar 15
3937
0
Mar 15
2388