从继承的模型odoov9社区调用字段

2024-06-02 06:20:28 发布

您现在位置:Python中文网/ 问答频道 /正文

让我解释一下我想做什么。在

stock模块中,当您导航到任何操作(拾取)类型时,无论它是树视图还是表单视图,显示的一些字段都来自product.product,例如name。在

现在,模型product.product有一个名为price的字段,因此,我需要显示stock.picking运动的产品价格。在

由于stock.picking模型没有继承price字段,所以我创建了一个小模块,从product.product继承{},然后在stock.picking上显示。在

它是stockproduct旁边的第三个模块。在

现在,在我的models.py中,我声明:

# -*- 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')

在我的view.xml中,我将此字段添加到stock.picking

^{pr2}$

每次我尝试运行这个时,它都会让我进入控制台:

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 <module>
from . import models
File "/home/kristian/odoov9/motostion_addons/stock_move_price/models/__init__.py", line 1, in <module>
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

有什么办法让我做到这一点吗?在

我希望我已经解释过了,如果你还需要进一步的解释,请你问我。在

提前谢谢!在


Tags: inpyodoomoduleshomemodelsstockline
1条回答
网友
1楼 · 发布于 2024-06-02 06:20:28

尝试使用以下代码:

更换

price_unit = fields.Float( digits_compute=dp.get_precision('Product Price'), string='Price')

^{pr2}$

在导入部分的下面一行写下

import openerp.addons.decimal_precision as dp

然后重新启动Odoo服务器并升级您的自定义模块。在

编辑:

更换

_inherit = 'stock.move'

_inherit = 'stock.picking'

相关问题 更多 >