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>
looks good, we would use this.......
so vote for me to make this question more important... I need help with this...
i know... i cant see the option though !
just click on the arrow up, left of the question title :-)
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...
context bug is finally fixed: http://bazaar.launchpad.net/~openerp/openerp-web/7.0/revision/4027