Call field from inherited model Odoo v9 community
<p>Let me explain what I'm trying to do.</p>

<p>On <code>stock</code> module, when You navigate to whatever operation (picking) type, being it a tree or form view, some of the fields that are shown are from <code>product.product</code>, like, for example <code>name</code>.</p>

<p>Now, the model <code>product.product</code> has a field called <code>price</code>, so, I need to show product price on <code>stock.picking</code> movements.</p>

<p>Since the <code>stock.picking</code> model doesn't inherit the <code>price</code> field, I'm creating a little module, to inherit <code>price</code> from <code>product.product</code>, and then show it on <code>stock.picking</code>.</p>

<p>It is a third module beside <code>stock</code> and <code>product</code>.</p>

<p>Now, in my <code>models.py</code> I declare:</p>

<pre><code># -*- coding: utf-8 -*-

from openerp import models, fields, api

class StockMove(models.Model):
    _inherit = 'stock.move'

    @api.onchange('name','product_id','move_line_tax_ids','product_uom_qty')

    price_unit = fields.Float( digits_compute=dp.get_precision('Product Price'), string='Price')
</code></pre>

<p>In my <code>view.xml</code> I add this field to <code>stock.picking</code>:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; 
&lt;openerp&gt;
&lt;data&gt;

&lt;record id="view_stock_move_tree" model="ir.ui.view"&gt;
    &lt;field name="name"&gt;Stock Move Price Tree&lt;/field&gt;
    &lt;field name="model"&gt;stock.picking&lt;/field&gt;
    &lt;field name="inherit_id" ref="stock.vpicktree"/&gt;
    &lt;field name="arch" type="xml"&gt;
        &lt;field name="state" position="before"&gt;
            &lt;field name="price_unit"/&gt;
        &lt;/field&gt;
    &lt;/field&gt; 
&lt;/record&gt;

&lt;record id="view_stock_move_form" model="ir.ui.view"&gt;
    &lt;field name="name"&gt;Stock Move Price Form&lt;/field&gt;
    &lt;field name="model"&gt;stock.picking&lt;/field&gt;
    &lt;field name="inherit_id" ref="stock.view_picking_form"/&gt;
    &lt;field name="arch" type="xml"&gt;
        &lt;field name="state" position="before"&gt;
                &lt;field name="price_unit"/&gt;
            &lt;/field&gt;
    &lt;/field&gt;
&lt;/record&gt;

&lt;/data&gt;
&lt;/openerp&gt;
</code></pre>

<p>Every time I try to run this, it throws me on console:</p>

<pre><code>2016-10-15 05:23:44,821 21578 ERROR argentina werkzeug: Error on request:
Traceback (most recent call last):
File "/home/kristian/.virtualenvs/odoo_danisan/lib/python2.7/site-packages/werkzeug/serving.py", line 177, in run_wsgi
execute(self.server.app)
File "/home/kristian/.virtualenvs/odoo_danisan/lib/python2.7/site-packages/werkzeug/serving.py", line 165, in execute
application_iter = app(environ, start_response)
File "/home/kristian/odoov9/odoo-9.0/openerp/service/server.py", line 246, in app
return self.app(e, s)
File "/home/kristian/odoov9/odoo-9.0/openerp/service/wsgi_server.py", line 184, in application
return application_unproxied(environ, start_response)
File "/home/kristian/odoov9/odoo-9.0/openerp/service/wsgi_server.py", line 170, in application_unproxied
result = handler(environ, start_response)
File "/home/kristian/odoov9/odoo-9.0/openerp/http.py", line 1495, in __call__
return self.dispatch(environ, start_response)
File "/home/kristian/odoov9/odoo-9.0/openerp/http.py", line 1644, in dispatch
ir_http = request.registry['ir.http']
File "/home/kristian/odoov9/odoo-9.0/openerp/http.py", line 365, in registry
return openerp.modules.registry.RegistryManager.get(self.db) if self.db else None
File "/home/kristian/odoov9/odoo-9.0/openerp/modules/registry.py", line 355, in get
update_module)
File "/home/kristian/odoov9/odoo-9.0/openerp/modules/registry.py", line 386, in new
openerp.modules.load_modules(registry._db, force_demo, status, update_module)
File "/home/kristian/odoov9/odoo-9.0/openerp/modules/loading.py", line 334, in load_modules
force, status, report, loaded_modules, update_module)
File "/home/kristian/odoov9/odoo-9.0/openerp/modules/loading.py", line 237, in load_marked_modules
loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks)
File "/home/kristian/odoov9/odoo-9.0/openerp/modules/loading.py", line 123, in load_module_graph
load_openerp_module(package.name)
File "/home/kristian/odoov9/odoo-9.0/openerp/modules/module.py", line 331, in load_openerp_module
__import__('openerp.addons.' + module_name)
File "/home/kristian/odoov9/odoo-9.0/openerp/modules/module.py", line 61, in load_module
mod = imp.load_module('openerp.addons.' + module_part, f, path, descr)
File "/home/kristian/odoov9/motostion_addons/stock_move_price/__init__.py", line 7, in &lt;module&gt;
from . import models
File "/home/kristian/odoov9/motostion_addons/stock_move_price/models/__init__.py", line 1, in &lt;module&gt;
from . import models
File "/home/kristian/odoov9/motostion_addons/stock_move_price/models/models.py", line 10
price_unit = fields.Float( digits_compute=dp.get_precision('Product Price'), string='Price')
         ^
SyntaxError: invalid syntax
</code></pre>

<p>Any ideas on how can I achieve this?</p>

<p>I hope I've explained myself, if You need further explanation just ask me please.</p>

<p>Thanks in advance!</p>

<p>Try with following code:</p>

<p>Replace</p>

<pre><code>price_unit = fields.Float( digits_compute=dp.get_precision('Product Price'), string='Price')
</code></pre>

<p>with</p>

<pre><code>price_unit = fields.Float(string='Price', digits=dp.get_precision('Product Price'))
</code></pre>

<p>And write below line in import section</p>

<pre><code>import openerp.addons.decimal_precision as dp
</code></pre>

<p>Afterwards restart Odoo server and upgrade your custom module.</p>

<p>EDIT:</p>

<p>Replace </p>

<pre><code>_inherit = 'stock.move'
</code></pre>

<p>with</p>

<pre><code>_inherit = 'stock.picking'
</code></pre>

python inheritance openerp odoo-9