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

self.pool.get from other object and browse the value

By
GonG
on 2/17/14, 4:19 AM 7,735 views

In the Sale Order Line table, I want to add columns Quantity on Hand from the Inventory tab in Product view afer the columns Product. To achieve this, I try to create a custom module with self.pool.get and browse method. The problem right now is it shows the error of invalid XML for view architecture. Please help me.

Here is my code

qty_available.py

from openerp.osv import fields, osv
from openerp import netsvc, tools, pooler
import openerp.addons.decimal_precision as dp

class qty_available_add(osv.osv):

    _inherit = "sale.order"

    _columns = {
        'qty_available': fields.float('Qty Disponible',digits_compute= dp.get_precision('Product UoS')),
    }

    def get_qty(self, cr, uid, id, product, context=None):
        wg_qty_avail = self.pool.get('product.product').browse(cr,uid,product,context=None).qty_available
        result['qty_available'] = wg_qty_avail


qty_available_add()

qty_available.xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
  <data>
    <record model="ir.ui.view" id="qty_available">
        <field name="name">sale.order.form</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form" />
        <field name="arch" type="xml">
            <xpath expr="/form/sheet/notebook/page/field[@name='order_line']/form/group/group/field[@name='product_id']" position="after">
                <field name="qty_available" />
            </xpath>
        </field>
    </record>
  </data>
</openerp>

Thank you very much

0
Ayyappan
On 2/17/14, 7:36 AM

Use below code:

In qty_available.py

from openerp.osv import fields, osv
from openerp import netsvc, tools, pooler
import openerp.addons.decimal_precision as dp

class sale_order_line(osv.osv):

    _inherit = "sale.order.line"

    _columns = {
        'qty_available': fields.float('Qty Disponible',digits_compute= dp.get_precision('Product UoS')),
    }    

sale_order_line()

In qty_available.xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
  <data>
    <record model="ir.ui.view" id="view_sale_order_line_form_inherit">
        <field name="name">view.sale.order.line.form.inherit</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form"/>
        <field name="arch" type="xml">

    <xpath expr="/form/sheet/notebook/page[@string='Order Lines']/field[@name='order_line']/form/group/group/field[@name='product_id']" position="after">                    
                    <field name="qty_available" />
                </xpath>

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

Thank you for your response. The module has been installed successfully. However, the column Quantity on Hand and it's associated value didn't show on the Sale Order Line table after the column Product. Do you have any suggestion?

GonG
on 2/17/14, 10:22 AM

The field "Qty Disponible" is displaying after the product field in sale order line(form) view. If you want to display the "Quantity on Hand" field value in the "Qty Disponible" field, you have to write onchange function.

Ayyappan
on 2/18/14, 5:13 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

1 follower(s)

Stats

Asked: 2/17/14, 4:19 AM
Seen: 7735 times
Last updated: 3/16/15, 8:10 AM