Odoo Help

0

Purchase Order, add Quantity to tree view

By
Yao
on 7/12/13, 2:02 AM 2,115 views

Hi there,

I am trying to add a new column into the tree view, but this is a existing element, rather than a new element. Inside the Purchase order-->order lines, there is element product_qty. I need to add this element into the purchase order tree view.

As purchase.order.line is called by purchase.order, I tried to inherit the class, and related a new column to the product_qty in my inherited purchase.order class. But it did not work.

I am attaching the related codes here, your kind help is much appreciated!

from openerp.osv import fields, osv

class purchase_order(osv.osv):

_name='purchase.order'
_inherit='purchase.order'
#_inherits={'purchase.order.line':'product_qty','purchase.order.line':'product_uom'}
_inherits={'purchase.order.line':'product_qty'}
_columns={

           'tree_quantity':fields.related('product_qty',string='Quantity',relation='purchase.order.line'),
          }

purchase_order()

    <record model="ir.ui.view" id="m_purchase_quotation_tree_view">
        <field name="name">Purchase Quotation Inherited List View</field>
        <field name="model">purchase.order</field> 
        <field name="inherit_id" ref="purchase.purchase_order_tree" /> 
            <field name="arch" type="xml">
                <data>

                    <field name="date_order" position="after">
                        <field name="tree_quantity" />
                    </field>

                </data>
            </field>
    </record>

Error msg:

Server Traceback (most recent call last): File "C:\erpDev\workspace\openerp-7.0\openerp\addons\web\session.py", line 89, in send return openerp.netsvc.dispatch_rpc(service_name, method, args) File "C:\erpDev\workspace\openerp-7.0\openerp\netsvc.py", line 292, in dispatch_rpc result = ExportService.getService(service_name).dispatch(method, params) File "C:\erpDev\workspace\openerp-7.0\openerp\service\web_services.py", line 626, in dispatch res = fn(db, uid, params) File "C:\erpDev\workspace\openerp-7.0\openerp\osv\osv.py", line 188, in execute_kw return self.execute(db, uid, obj, method, *args, *kw or {}) File "C:\erpDev\workspace\openerp-7.0\openerp\osv\osv.py", line 131, in wrapper return f(self, dbname, args, *kwargs) File "C:\erpDev\workspace\openerp-7.0\openerp\osv\osv.py", line 197, in execute res = self.execute_cr(cr, uid, obj, method, args, *kw) File "C:\erpDev\workspace\openerp-7.0\openerp\osv\osv.py", line 185, in execute_cr return getattr(object, method)(cr, uid, args, *kw) File "C:\erpDev\workspace\openerp-7.0\openerp\osv\orm.py", line 3604, in read result = self._read_flat(cr, user, select, fields, context, load) File "C:\erpDev\workspace\openerp-7.0\openerp\osv\orm.py", line 3724, in _read_flat res2 = self._columns[f].get(cr, self, ids, f, user, context=context, values=res) File "C:\erpDev\workspace\openerp-7.0\openerp\osv\fields.py", line 1131, in get result = self._fnct(obj, cr, uid, ids, name, self._arg, context) File "C:\erpDev\workspace\openerp-7.0\openerp\osv\fields.py", line 1197, in _fnct_read value = value[field] or False File "C:\erpDev\workspace\openerp-7.0\openerp\osv\orm.py", line 425, in __getitem__ if result_line[field_name]: KeyError: 'product_uom'

0
Ray Carnes
On 7/12/13, 2:12 AM

A purchase order is one or many purchase order lines, each with a quantity.

If there is more than one purchase order line, which quantity do you want in the treeview?

I think you need a new field that calculates what you want, since quantity isn't related to purchase order, but to purchase order line.

hi ray, thank you very much for pointing out my mistake! because in my case i have one type of products in each of purchase order, product quantity makes sense. I think I will need a new filed to calculate the total quantity then. Again, thx a lot for the help!

Yao
on 7/12/13, 3:32 AM

Hi Ray, as I'm pretty new to Openerp and python..i was reading the codes and tried to figure out how to calculate the quantity. I tried to refer to the amount_untaxed/amount_taxed, but it seems that these fields involve with complex functions with accounting etc. I am wondering whether you could advise the approach that how I can sort out the total quantity in the order_lines, then present it in the Order_Line page on Purchase Order form...thx a lot!

Yao
on 7/12/13, 7:05 AM

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)

Stats

Asked: 7/12/13, 2:02 AM
Seen: 2115 times
Last updated: 3/16/15, 8:10 AM