Odoo Help


How to show product prices on Physical Inventories?

on 3/12/15, 10:15 AM 1,461 views

Hi guys,

How could I show the prices from the products under Warehouse > Physical Inventories?

I know it is in the module 'stock' and the logic is in stock.py and stock_view.xml. So inside my stock_view.xml I would like to add a field here:

        <record id="view_inventory_form" model="ir.ui.view">
            <field name="name">stock.inventory.form</field>
            <field name="model">stock.inventory</field>
            <field name="arch" type="xml">
                <form string="Physical Inventory" version="7.0">
                //Lots of irrelevant code was here..
                    <page string="General Information">
                        <field name="inventory_line_id">
                            <tree string="Products" editable="bottom">
                                <field domain="[('usage','=','internal')]" name="location_id" groups="stock.group_locations"/>
                                <field context="{'location':location_id, 'uom':product_uom, 'to_date':parent.date}" name="product_id" on_change="on_change_product_id(location_id,product_id,product_uom,parent.date)"  domain="[('type','&lt;&gt;','service')]"/>
                                <field name="product_qty"/>
                                <field name="product_uom" groups="product.group_uom"/>
                                <field name="prod_lot_id" groups="stock.group_production_lot"/>

                                //SHOW PRODUCT PRICES HERE (I'd like both the price per product and the total from the quantity if possible)

So the simple question is how? What exactly should I add in stock.py and where? I've been trying for hours but have no idea how to do this in V7.
With kind regards

price of inventory line's products will not be available to you directly as it is not given in standard stock module. You need to customize code to achieve this. Create custom module.

Mansi Kariya (mka)
on 3/13/15, 3:08 AM

Hi Mansi thanks for the answer but I did know I would have to do that or extend the current module.. I'm just not sure about how to do this for this case in V7 though :/

on 3/13/15, 3:57 AM

Its just you need to take 2 fields one should be related field on product_id that will fetch price of the product, and second you have to take functional field which will calculate your quantity into price(which you have fetched in 1st custom field). Now put both of the fields to the inventory view and update the module, And yeah if you are adding fields through code then you need to restart server too. Hope this will help you :P

Mansi Kariya (mka)
on 3/13/15, 4:33 AM

Hi Mansi thanks for your response! The problem is that I tried to add fields to the .py file and then to the view (XML) but it would always throw me invalid errors and that those fields aren't allowed etc.. So think you could give me a little example? I just can't seem to find the exact place in the python file to make it work in the XML file.

on 3/13/15, 4:38 AM
Mansi Kariya (mka)
On 3/13/15, 7:32 AM

here is an example for custom module,

__init__.py file

import my_custom

my_custom.py file

from openerp.osv import fields, osv

class stock_inventory_line(osv.osv):

_inherit= "stock.inventory.line"

_description = "inventory line"

def _get_total_price(self, cr, uid, ids, fieldnames, args, context=None):

      result = dict.fromkeys(ids, 0.0)

      for obj in self.browse(cr, uid, ids, context=context):

      result[obj.id] = obj.product_price * obj.product_qty

      return result

_columns = {

'product_price': fields.related('product_id','standard_price',string="Product Price", type='float', store=True),

#also add funtional field here to calculate total

'get_total_price': fields.function(_get_total_price, type='float', method=True, string='Total')



my_custom_view.xml file 

<?xml version="1.0" encoding="utf-8"?>
        <record id="view_inventory_form_inherit" model="ir.ui.view">
            <field name="name">inventory.form.inherit</field>
            <field name="model">stock.inventory</field>
            <field name="inherit_id" ref="stock.view_inventory_form"/>
            <field name="arch" type="xml">
                <xpath expr="//field[@name='inventory_line_id']/tree[@string='Products']/field[@name='product_qty']" position="before">
                    <field name="product_price"/>
                    <field name="get_total_price"/>

__openerp__.py File

    'name': 'custom Warehouse Management',
    'version': '1.1',
    'author': 'OpenERP SA',
    'summary': 'custom inventory',
    'description' : """
    'website': 'http://www.openerp.com',
    'images': [],
    'depends': ['stock'],
    'category': 'Warehouse Management',
    'data': [
    'installable': True,
    'application': True,
    'auto_install': False,

This will add product price field. Hope this will help you. And yeah this will work for version 7 only

Thanks for the help Mansi! Sadly when I create this module and try to install it I get an XML error about the arch. When I look at the model stock.inventory.line the new field 'product_price' isn't created. Even when I add the field 'product_price' under the module stock it doesn't get added to my database. Any clue's? Or do you have a working module for this? I have no clue why it is not being added to the model..

on 3/19/15, 5:27 AM

This works perfectly at my side. And Yeah LET ME REMIND YOU that to apply python changes , you need to restart server. and to apply xml changes you need to update module. So Check Once again at your side or show me error.

Mansi Kariya (mka)
on 3/19/15, 5:33 AM

Ahh yes got it working, thanks! What would be the way to make a functional field that calculates the price then? Could you give me a sample / a bit of help here too please? I'll accept the answer afterwards too by the way!

on 3/19/15, 6:01 AM

Forum - This is the place to get help where you got stuck. Instead I have given u almost answer in example itself. So My Friend, Try it, If u get stuck, u can again ask for help. Will surely help you. But Let not it be spoon feeding. And PEOPLE Accept answers if it was useful. So choice is urs. Any ways U should try to solve too rather than asking evrythng done. :P

Mansi Kariya (mka)
on 3/19/15, 6:09 AM

Hi Mansi, no I'm not trying to get a full answer here without me trying. I've been trying a lot last week but really got stuck on this since I always work in V8 and never have (had) to extend current models yet. I've never done anything in V7 and there seem to be quite some differences. Anyways, I do have some code but its already giving me errors and I don't know why. I'll update my question and I hope you can just give me some pointers, I don't need exact code :) My apologies. (Also, accepted your answer.)

on 3/19/15, 6:19 AM

Updated my answer, since I got a bit further. I'm not sure what is wrong now though, looks like an inhertance problem but I have no idea why.

on 3/19/15, 6:55 AM

check my updated answer consist function field too.

Mansi Kariya (mka)
on 3/19/15, 7:49 AM

Thank you very much Mansi! I can now continue expanding this, thanks :)

on 3/19/15, 8:48 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.


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

1 follower(s)


Asked: 3/12/15, 10:15 AM
Seen: 1461 times
Last updated: 3/19/15, 8:16 AM