Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
1036 Lượt xem

Hi,

I successfully wrote the script that migrates our Odoo11 projects attachments to Odoo17, by using external API (unallowed link to Odoo docs)

Now I have to write a script, that will do some other data / field updating from Odoo11 to Odoo17.

I created test case according to docs above, that create a tag and then to update the same tag:

new_tag_id = models17.execute_kw(odoo17_db, uid17, odoo17_password, 'project.tags', 'create', [{
    'name': "Test",
    'display_name': "Test",
}])

models17.execute_kw(
    odoo17_db, uid17, odoo17_password,
    'project.tags', 'write',
    [[new_tag_id]],
    {'name': "Testing upd"}
)

It creates new Test tag, but I stuck at the error when updating:

;Error updating project 5644 tags: <Fault 1: 'Traceback (most recent call last):\n  File "/opt/odoo/odoo/odoo/addons/base/controllers/rpc.py", line 147, in xmlrpc_2\n    response = self._xmlrpc(service)\n               ^^^^^^^^^^^^^^^^^^^^^\n  File "/opt/odoo/odoo/odoo/addons/base/controllers/rpc.py", line 127, in _xmlrpc\n    result = dispatch_rpc(service, method, params)\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "/opt/odoo/odoo/odoo/http.py", line 389, in dispatch_rpc\n    return dispatch(method, params)\n           ^^^^^^^^^^^^^^^^^^^^^^^^\n  File "/opt/odoo/odoo/odoo/service/model.py", line 37, in dispatch\n    res = execute_kw(db, uid, *params[3:])\n          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "/opt/odoo/odoo/odoo/service/model.py", line 59, in execute_kw\n    return execute(db, uid, obj, method, *args, **kw or {})\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "/opt/odoo/odoo/odoo/service/model.py", line 65, in execute\n    res = execute_cr(cr, uid, obj, method, *args, **kw)\n          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "/opt/odoo/odoo/odoo/service/model.py", line 50, in execute_cr\n    result = retrying(partial(odoo.api.call_kw, recs, method, args, kw), env)\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "/opt/odoo/odoo/odoo/service/model.py", line 133, in retrying\n    result = func()\n             ^^^^^^\n  File "/opt/odoo/odoo/odoo/api.py", line 468, in call_kw\n    result = _call_kw_multi(method, model, args, kwargs)\n
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "/opt/odoo/odoo/odoo/api.py", line 453, in _call_kw_multi\n    result = method(recs, *args, **kwargs)\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nTypeError: BaseModel.write() got an unexpected keyword argument \'name\'\n'>

I tried different fields on project.project and project.tags, simple and related, checked that they are Read-only: false etc. yet no way - the same error. 

BTW: I have permissions to CRUD either project and project tags. I can do it by using external API. Actually I have almost all possible permissions.


What I am doing wrong, what else to check?
brgds & looking forward

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi Janeks,

Following the example on the Official documentation. You are almost there, keep it up!

You can see that your format needs a little bit of tweak near the list.

models17.execute_kw(

    odoo17_db, uid17, odoo17_password,

    'project.tags', 'write',

    [[new_tag_id]],

    {'name': "Testing upd"}  # this should be inside the list

)

Replace it with

models17.execute_kw(

    odoo17_db, uid17, odoo17_password,

    'project.tags', 'write',

    [[new_tag_id], {'name': "Testing upd"}] # I moved it up into the list

)

hope this helps

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

Andry, you are great!

Thanks a lot!

Fixed.

While I had written a lot of different other language scripts / code, this is my second Python script, so I am a bit blind on such argument syntax details yet + AI recommendations, that directed my focus to wrong directions.

Ảnh đại diện
Huỷ bỏ

Happy if it helps. Would you do me a favor to upvote or mark my answer as solved? Thanks.

Bài viết liên quan Trả lời Lượt xem Hoạt động
6
thg 12 23
45876
0
thg 2 24
3600
1
thg 4 18
3574
0
thg 10 24
189
1
thg 6 24
1378