在记录创建时,运行 在另一个模块中创建记录的函数 - odoo 13
On record creation, run a function to create a record in another module - odoo 13
当使用 create 方法在我的模块中创建记录时,我试图创建一家新公司,但我无法让它工作:
@api.model
def create(self, vals):
for n_record in self:
company_info ={
'company_type': 'company',
'name': n_record.new_company_name,
'vat': n_record.company_ vat
}
record = n_record.env['base.view_partner_form'].create(company_info)
return record
我收到这个错误,我无法理解它:
Odoo Server Error
Traceback (most recent call last):
........
........
File "/usr/lib/python3/dist-packages/odoo/http.py", line 339, in checked_call
result = self.endpoint(*a, **kw)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 915, in __call__
return self.method(*args, **kw)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 515, in response_wrap
response = f(*args, **kw)
File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 1322, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 1314, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/usr/lib/python3/dist-packages/odoo/api.py", line 385, in call_kw
result = _call_kw_model_create(method, model, args, kwargs)
File "/usr/lib/python3/dist-packages/odoo/api.py", line 366, in _call_kw_model_create
return result.id if isinstance(args[0], Mapping) else result.ids
AttributeError: 'NoneType' object has no attribute 'id'
我需要帮助来理解错误。
编辑
通过将我的代码更改为:
,我克服了错误
@api.model
def create(self, vals):
company_info ={
'company_type': 'company',
'name': self.new_company_name,
'vat': self.company_vat
}
record = self.env['res.partner'].create(company_info)
return record
不过我现在收到这个错误:
Something went wrong! Contacts require a name
我不确定,但我想我传递的是名字 'name': self.new_company_name,
编辑 2
(谢谢@NiyasRaphy)
已将 'name': self.new_company_name,
更改为 'name': vals['new_company_name']
正在创建公司,但表格卡住且未保存。
感谢 @NiyasRaphy 和 @Prakash 在 odoo forms
@api.model
def create(self, vals):
company_info ={
'company_type': 'company',
'name': vals['new_company_name'],
'vat': vals['company_vat'],
}
self.env['res.partner'].create(company_info)
result = super(my_class_name, self).create(vals)
return result
当使用 create 方法在我的模块中创建记录时,我试图创建一家新公司,但我无法让它工作:
@api.model
def create(self, vals):
for n_record in self:
company_info ={
'company_type': 'company',
'name': n_record.new_company_name,
'vat': n_record.company_ vat
}
record = n_record.env['base.view_partner_form'].create(company_info)
return record
我收到这个错误,我无法理解它:
Odoo Server Error
Traceback (most recent call last):
........
........
File "/usr/lib/python3/dist-packages/odoo/http.py", line 339, in checked_call
result = self.endpoint(*a, **kw)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 915, in __call__
return self.method(*args, **kw)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 515, in response_wrap
response = f(*args, **kw)
File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 1322, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 1314, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/usr/lib/python3/dist-packages/odoo/api.py", line 385, in call_kw
result = _call_kw_model_create(method, model, args, kwargs)
File "/usr/lib/python3/dist-packages/odoo/api.py", line 366, in _call_kw_model_create
return result.id if isinstance(args[0], Mapping) else result.ids
AttributeError: 'NoneType' object has no attribute 'id'
我需要帮助来理解错误。
编辑
通过将我的代码更改为:
,我克服了错误 @api.model
def create(self, vals):
company_info ={
'company_type': 'company',
'name': self.new_company_name,
'vat': self.company_vat
}
record = self.env['res.partner'].create(company_info)
return record
不过我现在收到这个错误:
Something went wrong! Contacts require a name
我不确定,但我想我传递的是名字 'name': self.new_company_name,
编辑 2
(谢谢@NiyasRaphy)
已将 'name': self.new_company_name,
更改为 'name': vals['new_company_name']
正在创建公司,但表格卡住且未保存。
感谢 @NiyasRaphy 和 @Prakash 在 odoo forms
@api.model
def create(self, vals):
company_info ={
'company_type': 'company',
'name': vals['new_company_name'],
'vat': vals['company_vat'],
}
self.env['res.partner'].create(company_info)
result = super(my_class_name, self).create(vals)
return result