我想通過自定義模塊修改Odoo的功能。事情是改變項目任務複製功能。從本質上講,當從具有工作摘要的任務的模板創建新項目時,工作摘要不會被複制(我想保留它們)。我發現複製任務的功能,但我陷入了這個...TypeError修改Odoo 8本地模塊
這是我得到的錯誤(我不明白,因爲它是指duplicate_template()當我不修改該方法從項目類):
Traceback (most recent call last): File "/opt/odoo/odoo-server/openerp/http.py", line 540, in
_handle_exception
return super(JsonRequest, self)._handle_exception(exception) File "/opt/odoo/odoo-server/openerp/http.py", line 577, in dispatch
result = self._call_function(**self.params) File "/opt/odoo/odoo-server/openerp/http.py", line 313, in _call_function
return checked_call(self.db, *args, **kwargs) File "/opt/odoo/odoo-server/openerp/service/model.py", line 118, in wrapper
return f(dbname, *args, **kwargs) File "/opt/odoo/odoo-server/openerp/http.py", line 310, in checked_call
return self.endpoint(*a, **kw) File "/opt/odoo/odoo-server/openerp/http.py", line 806, in __call__
return self.method(*args, **kw) File "/opt/odoo/odoo-server/openerp/http.py", line 406, in response_wrap
response = f(*args, **kw) File "/opt/odoo/odoo-server/addons/web/controllers/main.py", line 948, in call_button
action = self._call_kw(model, method, args, {}) File "/opt/odoo/odoo-server/addons/web/controllers/main.py", line 936, in
_call_kw
return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs) File "/opt/odoo/odoo-server/openerp/api.py", line 268, in wrapper
return old_api(self, *args, **kwargs) File "/opt/odoo/odoo-server/openerp/api.py", line 399, in old_api
result = method(recs, *args, **kwargs)
TypeError: duplicate_template() takes at least 4 arguments (2 given)
這裏是我的代碼:
mymodule.py
import openerp
from openerp import models,fields,api
from openerp.osv import fields, osv
class task(osv.osv):
_inherit="project.task"
@api.multi
def copy_data(self, default=None, context=None):
if default is None:
default = {}
current = self.browse(cr, uid, id, context=context)
if not default.get('name'):
default['name'] = _("%s (copy)") % current.name
if 'remaining_hours' not in default:
default['remaining_hours'] = current.planned_hours
default['work_ids'] = current.work_ids
return super(task, self).copy_data(cr, uid, id, default, context)
default['work_ids'] = current.work_ids was added by me - it was not included in original function.
有關我爲什麼會出錯的任何想法?
非常感謝您的幫助!
親切的問候。
即使你的答案是完全傲慢,這是非常有幫助的。我會再次閱讀文檔。只是要說清楚:我沒有期望任何人爲我免費編寫代碼。謝謝。 –