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

How to show product prices on Physical Inventories?

By
Yenthe
on 3/12/15, 10:15 AM 886 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
Yenthe

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 :/

Yenthe
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.

Yenthe
on 3/13/15, 4:38 AM
2
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')

}

stock_inventory_line()


my_custom_view.xml file 

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <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"/>
                </xpath>
            </field>
        </record>
    </data>
</openerp>

__openerp__.py File

{
    'name': 'custom Warehouse Management',
    'version': '1.1',
    'author': 'OpenERP SA',
    'summary': 'custom inventory',
    'description' : """
    Customization
    """,
    'website': 'http://www.openerp.com',
    'images': [],
    'depends': ['stock'],
    'category': 'Warehouse Management',
    'data': [
        'my_custom_view.xml',
    ],
    '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..

Yenthe
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!

Yenthe
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.)

Yenthe
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.

Yenthe
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 :)

Yenthe
on 3/19/15, 8:48 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: 3/12/15, 10:15 AM
Seen: 886 times
Last updated: 3/19/15, 8:16 AM