I have the following code:
class product_product(osv.osv):
_name = 'product.product'
_inherit = 'product.product'
def test(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 = {
'test': fields.function(test, type='one2many', relation='stock.location', string='Stock by Location'),
}
product_product()
and:
<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="lot" position="before" version="7.0">
<group string="Locations" attrs="{'invisible': [('type', '=', 'service')]}" groups="base.group_user">
<field name="test" nolabel="1" context="{'product_id': active_id, 'only_with_stock': True}">
<tree string="Stock Location">
<field name="complete_name"/>
<field name="stock_real"/>
<field name="stock_virtual" invisible="'product_id' not in context"/>
</tree>
</field>
</group>
</group>
</field>
</record>
</data>
</openerp>
The test()
function works well. It creates a one2many
field with the stock locations. The complete_name
field in the treeview is ok but the stock_real
and stock_virtual
fields are empty(0.00). I think because this fields calls _product_value()
from stock/stock.py
and _product_value()
needs the product_id
passed in the context
. But it is not passed.
What I'm doing wrong?
by using context: https://learnopenerp.blogspot.com/2018/01/get-parent-form-value-in-one2many-form.html