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.

14

Module/Function that shows/returns stock locations in products

By
Stefan Reisich
on 3/22/13, 1:05 PM 5,429 views

I want develop a module that shows the stock locations with quantity in the product form like in the image. Of course only the locations with quantity > 0.

Maybe Somebody knows a function that gets the location ids? Or maybe exists such a module already. Can somebody give me some hints or code?

image description

looks good, we would use this.......

john
on 3/25/13, 7:35 AM

so vote for me to make this question more important... I need help with this...

Stefan Reisich
on 3/25/13, 7:40 AM

i know... i cant see the option though !

john
on 3/25/13, 7:48 AM

just click on the arrow up, left of the question title :-)

Stefan Reisich
on 3/25/13, 8:00 AM

i have some updates, but i'm stuck on this problem: http://help.openerp.com/question/8598/how-can-i-pass-context-to-a-one2many-field/ maybe someone can help me on this...

Stefan Reisich
on 3/28/13, 10:30 AM
5

Stefan Reisich

--Stefan Reisich--
831
| 7 7 8
Pfungstadt, Germany
--Stefan Reisich--
Stefan Reisich
On 4/5/13, 11:41 AM

Ok I finally got it! Here it is:

First you must handle a bug in OpenERP 7. You can find what to do here: https://accounts.openerp.com/forum/Help-1/question/8598

The Bug has been fixed. Just update to last revision: http://bazaar.launchpad.net/~openerp/openerp-web/7.0/revision/4027

And then this module will work:

__init__.py:

import stock_location
import product

__openerp__.py:

{
    'name': 'nfx Stock Location',
    'version' : '0.1',
    'author' : 'Stefan Reisich, Rove.design GmbH',
    'website' : 'http://www.rove.de/',
    'description': 'Extends Stock Location functionality',
    'category': '',
    'depends': ['stock'],
    'data': ['stock_location.xml'],
    'installable': True,
}

product.py:

from openerp.osv import osv, fields


class product_product(osv.osv):
    _name = 'product.product'
    _inherit = 'product.product'

    def get_stock_locations(self, cr, uid, ids, field_names=None, arg=None, context=None):
        result = {}
        if not ids: return result

        context['only_with_stock'] = True

        for id in ids:
            context['product_id'] = id
            location_obj = self.pool.get('stock.location')
            result[id] = location_obj.search(cr, uid, [('usage', '=', 'internal')], context=context)

        return result


    _columns = {
        'stock_locations': fields.function(get_stock_locations, type='one2many', relation='stock.location', string='Stock by Location'),
    }

product_product()

stock_location.py:

from openerp.osv import osv


class stock_location(osv.osv):
    _name = "stock.location"
    _inherit = "stock.location"

    def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
        if context is None:
            context = {}

        res_ids = super(stock_location, self).search(cr, uid, args, offset, limit, order, context=context, count=count)
        if context.get('only_with_stock', False) is True:
            loc_obj = self.browse(cr, uid, res_ids, context=context)
            res_ids = [x.id for x in loc_obj if x.stock_real>0]

        return res_ids


stock_location()

stock_location.xml:

<openerp>
    <data>

        <act_window
            context="{'product_id': active_id, 'only_with_stock': True}"
            id="act_stock_product_location_open"
            name="Stock by Location"
            res_model="stock.location"
            src_model="product.product"/>


        <record id="nfx_view_normal_procurement_locations_form" model="ir.ui.view">
            <field name="name">nfx_product.normal.procurement.locations.inherit</field>
            <field name="model">product.product</field>
            <field name="inherit_id" ref="stock.view_normal_procurement_locations_form"/>
            <field name="arch" type="xml">

                <group name="status" position="before">
                    <group name="nfx_locations" string="Locations" attrs="{'invisible': [('type', '=', 'service')]}" groups="base.group_user" colspan="2">

                        <field name="stock_locations" nolabel="1" context="{'product_id': active_id}">
                            <tree string="Stock Location">
                                <field name="complete_name"/>
                                <field name="stock_real"/>
                                <field name="stock_virtual"/>
                            </tree>
                        </field>

                    </group>
                </group>

            </field>
        </record>

    </data>
</openerp>

Great module, thanks!

Igor MF
on 7/7/14, 5:59 PM
0
IT Libertas
On 3/13/16, 5:49 PM

The module for version 8 & 9: https://www.odoo.com/forum/help-1/question/solved-knowing-the-product-stock-location-92841

0
john
On 3/25/13, 7:41 AM

Your Mock-Up would be a perfect solution for us too. Im assuming you already know about using the more button ?

While on the product page you can use the 'more' button at the top of the page (next to print) and select 'stock by location' from the dropdown....

My issue is that this gives us 2000 locations and the filter is broke. You cant click the column header 'real stock' but you can click to sort the headers 'location type' and 'location name'.. also if you use the 'Advanced Search' and select either 'real stock' or 'real stock value' is greater than 0.00 the results dont change. The view still shows all the locations including those with 0.00 stock !

yes i know about that. but we have the same problem like you. and we have many stock locations too...

Stefan Reisich
on 3/25/13, 8:02 AM

Hi, same issues here. And I noticed as well that you can use advanced search to filter on real stock > "0.00", but that is not working....

patrick
on 3/25/13, 10:09 AM

hey stefan, thanks a lot for your module. However, it keeps showing me the stock numbers for only one record, meaning it always stays the same when I click through different products. Can you help me with this? Thanks again!

Philipp Johne
on 9/9/13, 12:32 PM

there was a bug in openerp 7. please update to the latest revision. it was fixed here: http://bazaar.launchpad.net/~openerp/openerp-web/7.0/revision/4027

Stefan Reisich
on 9/10/13, 9:30 AM

Thanks! Works great now! Love the community...

Philipp Johne
on 9/11/13, 6:05 AM
0
geert
On 12/10/13, 3:51 PM

Hi,

I'm quite interested in this functionality for an aircraft restoration warehouse inventory. Did you ever made an addon of this? How can I make my own addon based on your code?

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

4 follower(s)

Stats

Asked: 3/22/13, 1:05 PM
Seen: 5429 times
Last updated: 3/13/16, 5:49 PM