Odoo 10:在Many2one字段中动态输入值 [英] Odoo 10: enter value in Many2one field dynamically
问题描述
我添加了我的models.py:
I added in my models.py :
commercial_group = fields.Many2one("simcard.simcard")
并在我的views.xml中:
and in my views.xml :
<field name="commercial_group" widget="selection"/>
然后我试图在我的模型中创建一个新记录,如下所示:
And then i am trying to create a new record in my model like this :
record.sudo().create({
"icc": icc.text,
"imsi": imsi.text,
"msisdn": msisdn.text,
"lte_status": lte_status.text,
"life_cycle_status": life_cycle_status.text,
"sim_model": simmodel.text,
"gprs_status": gprsStatus.text,
"consumption_monthly_data_limit": consumption_monthly_data_limit.text,
"consumption_monthly_data_value": consumption_monthly_data_value.text,
"consumption_monthly_data_thrReached": consumption_monthly_data_thrReached.text,
"commercial_group": commercial_group.text,
"country": country.text,
"operator": operator.text
})
http.request.env.cr.commit()
我在日志中收到此错误:
and i get this error in my logs :
INFO test odoo.sql_db: bad query: INSERT INTO "simcard_simcard" ("id", "consumption_monthly_data_limit", "consumption_monthly_data_thrReached", "msisdn", "country", "lte_status", "consumption_monthly_data_value", "life_cycle_status", "icc", "gprs_status", "sim_model", "operator", "commercial_group", "imsi", "create_uid", "write_uid", "create_date", "write_date") VALUES(nextval('simcard_simcard_id_seq'), '0', '0', '34590169', 'CH', 'false', '0', 'ACTIVE', '89293165951', '2', 'M2M Plug-in', 're', '1GB_dynPool_Plus_LTE', '29782', 1, 1, (now() at time zone 'UTC'), (now() at time zone 'UTC')) RETURNING id
2018-09-19 13:44:27,441 5714 ERROR test odoo.http: Exception during JSON request handling.
Traceback (most recent call last):
File "/Users/anubhavjhalani/odoo10/odoo/http.py", line 642, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/Users/anubhavjhalani/odoo10/odoo/http.py", line 684, in dispatch
result = self._call_function(**self.params)
File "/Users/anubhavjhalani/odoo10/odoo/http.py", line 334, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/Users/anubhavjhalani/odoo10/odoo/service/model.py", line 101, in wrapper
return f(dbname, *args, **kwargs)
File "/Users/anubhavjhalani/odoo10/odoo/http.py", line 327, in checked_call
result = self.endpoint(*a, **kw)
File "/Users/anubhavjhalani/odoo10/odoo/http.py", line 942, in __call__
return self.method(*args, **kw)
File "/Users/anubhavjhalani/odoo10/odoo/http.py", line 507, in response_wrap
response = f(*args, **kw)
File "/Users/anubhavjhalani/odoo10/addons/web/controllers/main.py", line 895, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/Users/anubhavjhalani/odoo10/addons/web/controllers/main.py", line 887, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/Users/anubhavjhalani/odoo10/odoo/api.py", line 689, in call_kw
return call_kw_multi(method, model, args, kwargs)
File "/Users/anubhavjhalani/odoo10/odoo/api.py", line 680, in call_kw_multi
result = method(recs, *args, **kwargs)
File "/Users/anubhavjhalani/odoo10/addons/simcard/models/models.py", line 259, in sync
parse.parseXml(subscriptionDatas)
File "/Users/anubhavjhalani/odoo10/addons/simcard/models/parse.py", line 71, in parseXml
"operator": operator.text
File "/Users/anubhavjhalani/odoo10/odoo/models.py", line 3846, in create
record = self.browse(self._create(old_vals))
File "/Users/anubhavjhalani/odoo10/odoo/models.py", line 3941, in _create
cr.execute(query, tuple(u[2] for u in updates if len(u) > 2))
File "/Users/anubhavjhalani/odoo10/odoo/sql_db.py", line 154, in wrapper
return f(self, *args, **kwargs)
File "/Users/anubhavjhalani/odoo10/odoo/sql_db.py", line 231, in execute
res = self._obj.execute(query, params)
DataError: invalid input syntax for integer: "1GB_dynPool_Plus_LTE"
^
错误在于在Commercial_group字段中插入值,因为当我从record.sudo().create()语句中删除此字段时,我没有得到任何错误.
The error is in inserting the value in Commercial_group field because when i remove this field from record.sudo().create() statement, i dont get any error.
我在这里错过了任何要点吗?
Am i missing any point here ??
推荐答案
我认为您需要根据从SOAP响应中获得的文本为商业组创建新记录,然后创建ID为的主记录.新创建的记录,请看下面:
I think you need to create a new record for commercial group according to the text that you get from the SOAP response and then create the main record with the id of the newly created record, Look below:
com_grp = self.env['simcard.simcard'].create({'name': commercial_group.text})
然后将其插入您的主记录中:
Then insert this in your main record:
"commercial_group": com_grp.id
而不是commercial_group.text
这篇关于Odoo 10:在Many2one字段中动态输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!