2016-10-15 96 views
0

讓我解釋我想要做的事情。來自繼承的模型Odoo v9社區的調用字段

stock模塊,當導航到任何操作(拾取)的類型,它是一個樹或表單視圖,部分被示出的字段是從product.product,像,例如name

現在,型號product.product有一個字段price,所以,我需要顯示產品價格stock.picking運動。

由於stock.picking模型不繼承price場,我創建一個小模塊,爲繼承product.productprice,然後顯示它在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

<?xml version="1.0" encoding="utf-8"?> 
<openerp> 
<data> 

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

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

</data> 
</openerp> 

每次我嘗試運行此,它拋出我的控制檯:

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 

關於如何實現此目的的任何想法?

我希望我已經解釋了我自己,如果您需要進一步的解釋,請問我。

在此先感謝!

回答

1

與下面的代碼試試:

更換

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

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

而下面寫一行在進口部分

import openerp.addons.decimal_precision as dp 

然後重新啓動Odoo服務器升級您的自定義模塊。

編輯:

更換

_inherit = 'stock.move' 

_inherit = 'stock.picking' 
+0

你好,非常感謝你,但現在來看,它說場 '價格單位' 不存在:/,這是怪異,已經重新啓動odoo進程,我試圖升級模塊,但是這個錯誤出來了 – NeoVe

+0

沒錯,這是我的錯誤,將_inherit語句改爲stock。picking哈哈,現在錯誤說:ProgrammingError:外鍵約束「stock_picking_price_unit_fkey」不能實現 細節:鍵列「price_unit」和「ID」是不兼容的類型:數字和整數。 – NeoVe

+0

要問一個新的問題,謝謝。 – NeoVe

相關問題