Help

14

Module/Function that shows/returns stock locations in products

Avatar
Stefan Reisich

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

6 Comments
Avatar
Discard
Avatar
john
-

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

Avatar
Stefan Reisich
-

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

Avatar
john
-

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

Avatar
Stefan Reisich
-

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

Avatar
Stefan Reisich
-

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

Avatar
Stefan Reisich
-
4 Answers
5
Avatar
Stefan Reisich
Best Answer

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>
1 Comment
Avatar
Discard
Avatar
Igor MF
-

Great module, thanks!

0
Avatar
IT Libertas
Best Answer

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

Avatar
Discard
0
Avatar
john
Best Answer

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 !

5 Comments
Avatar
Discard
Avatar
Stefan Reisich
-

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

Avatar
patrick
-

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

Avatar
Philipp Johne
-

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!

Avatar
Stefan Reisich
-

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

Avatar
Philipp Johne
-

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

0
Avatar
geert
Best Answer

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?

Avatar
Discard