Odoo 10: enter value in Many2one field dynamically

2024/11/16 4:32:23

I added in my models.py :

commercial_group = fields.Many2one("simcard.simcard")

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_exceptionreturn super(JsonRequest, self)._handle_exception(exception)File "/Users/anubhavjhalani/odoo10/odoo/http.py", line 684, in dispatchresult = self._call_function(**self.params)File "/Users/anubhavjhalani/odoo10/odoo/http.py", line 334, in _call_functionreturn checked_call(self.db, *args, **kwargs)File "/Users/anubhavjhalani/odoo10/odoo/service/model.py", line 101, in wrapperreturn f(dbname, *args, **kwargs)File "/Users/anubhavjhalani/odoo10/odoo/http.py", line 327, in checked_callresult = 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_wrapresponse = f(*args, **kw)File "/Users/anubhavjhalani/odoo10/addons/web/controllers/main.py", line 895, in call_kwreturn self._call_kw(model, method, args, kwargs)File "/Users/anubhavjhalani/odoo10/addons/web/controllers/main.py", line 887, in _call_kwreturn call_kw(request.env[model], method, args, kwargs)File "/Users/anubhavjhalani/odoo10/odoo/api.py", line 689, in call_kwreturn call_kw_multi(method, model, args, kwargs)File "/Users/anubhavjhalani/odoo10/odoo/api.py", line 680, in call_kw_multiresult = method(recs, *args, **kwargs)File "/Users/anubhavjhalani/odoo10/addons/simcard/models/models.py", line 259, in syncparse.parseXml(subscriptionDatas)File "/Users/anubhavjhalani/odoo10/addons/simcard/models/parse.py", line 71, in parseXml"operator": operator.textFile "/Users/anubhavjhalani/odoo10/odoo/models.py", line 3846, in createrecord = self.browse(self._create(old_vals))File "/Users/anubhavjhalani/odoo10/odoo/models.py", line 3941, in _createcr.execute(query, tuple(u[2] for u in updates if len(u) > 2))File "/Users/anubhavjhalani/odoo10/odoo/sql_db.py", line 154, in wrapperreturn f(self, *args, **kwargs)File "/Users/anubhavjhalani/odoo10/odoo/sql_db.py", line 231, in executeres = self._obj.execute(query, params)
DataError: invalid input syntax for integer: "1GB_dynPool_Plus_LTE"^

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 ??

Answer

Try this,

"commercial_group": commercial_group.id

instead of commercial_group.text because Many2one store as a id not text...

https://en.xdnf.cn/q/119573.html

Related Q&A

How to erode this thresholded image using OpenCV

I am trying to first remove the captcha numbers by thresholding and then eroding it ,to get slim continuous lines to get better output. Problem:the eroded image is not continuous as u can see Original …

Searching for only the first value in an array in a csv file

So i am creating a account login system which searches a database for a username (and its relevant password) and, if found, will log the user on.This is what the csv file currently looks like[dom, ente…

how to write a single row cell by cell and fill it in csv file

I have a CSV file that only has column headers:cat mycsv.csvcol_1@@@col_2@@@col_3@@@col_3I have to fill a single row with None values in each cell of the CSV file. Can someone suggest me the best-optim…

Greedy String Tiling in Python

I am trying to learn greedy string tiling in algorithmI have two lists as follows:a=[a,b,c,d,e,f] b=[d,e,a,b,c,f]i would like to retrieve c=[a,b,c,d,e]Another example would be a = [1,2,3,4,5,6,7,8,9,1,…

Python - efficient way to create 20 variables?

I need to create 20 variables in Python. That variables are all needed, they should initially be empty strings and the empty strings will later be replaced with other strings. I cann not create the var…

Whatsapp asking for updating chrome version

I am trying to open whatsapp with selenium and python, it was working fine until today. In headless or non, whatsapp is now asking to update chrome, when I try to do so, Chrome throws this error: An er…

how to find the longest N words from a list, using python?

I am now studying Python, and I am trying to solve the following exercise:Assuming there is a list of words in a text file, My goal is to print the longest N words in this list.Where there are several …

([False, True] and [True, True]) evaluates to [True, True]

I have observed the following behavior in python 3: >>> ([False, True] and [True, True]) [True, True]>>> ([False, True] or [True, True]) [False, True]I was expecting exactly the oppos…

Uploading an image to Flask server

I am struggling bit with Flask and uploading a file, here is my Flask code so far:@app.route(/api/user/update/, methods=[PUT]) @auth.login_required def update_user():# check if the post request has the…

Enemy Projectiles Arent Appending On Screen

I have here my script that targets the player what ever position he is at but the projectiles arent showing on my screen VIDEO. He isnt attacking at all, I dont know why. I am in my main loop I draw t…