我在Odoo 10上工作了幾個月後,我製作了一個依賴於某些Odoo模塊的自定義模塊。 今天我想創建一個用戶手冊,因爲我的工作幾乎完成了,所以我決定創建一個新的數據庫,從零開始,並能夠一步一步解釋如何安裝模塊以及它如何工作... The問題是,我得到這個錯誤:Odoo 10安裝模塊時出現KeyError
Odoo Server Error
Traceback (most recent call last):
File "/opt/odoo/odoo-10.0/odoo/http.py", line 638, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/opt/odoo/odoo-10.0/odoo/http.py", line 675, in dispatch
result = self._call_function(**self.params)
File "/opt/odoo/odoo-10.0/odoo/http.py", line 331, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/opt/odoo/odoo-10.0/odoo/service/model.py", line 119, in wrapper
return f(dbname, *args, **kwargs)
File "/opt/odoo/odoo-10.0/odoo/http.py", line 324, in checked_call
result = self.endpoint(*a, **kw)
File "/opt/odoo/odoo-10.0/odoo/http.py", line 933, in __call__
return self.method(*args, **kw)
File "/opt/odoo/odoo-10.0/odoo/http.py", line 504, in response_wrap
response = f(*args, **kw)
File "/opt/odoo/odoo-10.0/addons/web/controllers/main.py", line 882, in call_button
action = self._call_kw(model, method, args, {})
File "/opt/odoo/odoo-10.0/addons/web/controllers/main.py", line 870, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/opt/odoo/odoo-10.0/odoo/api.py", line 681, in call_kw
return call_kw_multi(method, model, args, kwargs)
File "/opt/odoo/odoo-10.0/odoo/api.py", line 672, in call_kw_multi
result = method(recs, *args, **kwargs)
File "/opt/odoo/odoo-10.0/odoo/addons/base/module/module.py", line 410, in button_immediate_install
return self._button_immediate_function(type(self).button_install)
File "/opt/odoo/odoo-10.0/odoo/addons/base/module/module.py", line 484, in _button_immediate_function
modules.registry.Registry.new(self._cr.dbname, update_module=True)
File "/opt/odoo/odoo-10.0/odoo/modules/registry.py", line 78, in new
odoo.modules.load_modules(registry._db, force_demo, status, update_module)
File "/opt/odoo/odoo-10.0/odoo/modules/loading.py", line 339, in load_modules
loaded_modules, update_module)
File "/opt/odoo/odoo-10.0/odoo/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 "/opt/odoo/odoo-10.0/odoo/modules/loading.py", line 135, in load_module_graph
registry.setup_models(cr, partial=True)
File "/opt/odoo/odoo-10.0/odoo/modules/registry.py", line 293, in setup_models
model._setup_fields(partial)
File "/opt/odoo/odoo-10.0/odoo/models.py", line 2836, in _setup_fields
field.setup_full(self)
File "/opt/odoo/odoo-10.0/odoo/fields.py", line 491, in setup_full
self._setup_related_full(model)
File "/opt/odoo/odoo-10.0/odoo/fields.py", line 528, in _setup_related_full
field = target._fields[name]
KeyError: 'workorder_id'
現在我不知道,但似乎有一個問題,當Odoo應導入我的文件,因爲在數據庫中根本沒有創造我的表,所以我不不知道它們是否因爲這個錯誤而未被創建,或者如果這個錯誤是因爲我的表不在數據庫中。 無論如何,我試圖評論這個workorder_id出現在哪裏,但它沒有改變任何東西,錯誤仍然存在,我嘗試着重新嘗試重新啓動服務器,但幾乎沒有任何改變。 我已經看到很多關於繼承的主題,但我不認爲這是事實,workorder_id是我自己的領域,它用在我自己的模型中。
這裏是使用了這一領域的車型:
class ControlPart(models.Model):
"""
Modèle pour la vue de la pièce contrôlée.
"""
_name = 'spc.control.part'
name = fields.Char(string='Piece name')
starting_date = fields.Date(string='Starting date')
ending_date = fields.Date(string='Ending date')
basket_position = fields.Char(string='Basket position')
piece_number = fields.Integer(string='Piece number')
note = fields.Text(string='Notes')
# operation_workorder_id = fields.Many2one('spc.fabrication.order', string='Fabrication order',
# related='operation_id.workorder_id')
# operation_workorder_id_product_id = fields.Many2one('product.product', string='Product code',
# related='operation_id.workorder_id.product_id')
operation_id = fields.Many2one('spc.operation', ondelete='restrict', string='Operation')
person_id = fields.Many2one('spc.person', ondelete='restrict', string='Operator')
workcenter_id = fields.Many2one('mrp.workcenter', ondelete='restrict', string='Workcenter code')
control_measure_ids = fields.One2many('spc.control.measure', 'control_part_id', ondelete='restrict', string='Measures')
class Operation (models.Model):
"""
Modèle pour la vue des opérations.
"""
_name = 'spc.operation'
name = fields.Char(string='Operation name')
number = fields.Integer(string='Number')
pcerp_number = fields.Char(string='Pro Concept number')
#workorder_id = fields.Many2one('spc.fabrication.order', ondelete='restrict', string='Fabrication Order')
感謝您的時間!
編輯: 因此,經過一段時間尋找問題,與我的同事,我們並沒有真正發現什麼是錯的。我們假設Odoo在重新啓動服務時沒有重新加載文件,因爲我們試圖在文件中放入一些錯誤的代碼,並且Odoo完全忽略了它。 也許某些東西仍然在內存中,並且它使用相同的文件,所以我們終於通過殺死所有進程來設法解決問題。 我希望這仍然可以幫助。
你在o2m領域使用過嗎? – Cherif
不,我只在Many2one字段 – Isariamkia
中使用它,只是創建這個字段不會導致這個錯誤,你在哪裏使用它。 – Cherif