Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
296 มุมมอง

Hello, 


Looking into the documentation, there it not written if we can call the duplicate method as you can see in the picture 




Is there a way to directly duplicate an object with the api and get the ID of the new created object ?


-- 


I found another solution but it's more complexe automation 



Create a Webhook: 


And call Server Action: 


Create another automation, when new Task is created, send a json (included the ID) to an http address.


But the system has to do 2 independent steps

And multiplying the steps increase the chance to have bugs


It should works, but not very good.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

The Duplicate action you are referring to is simply defined as

<a class="dropdown-item" role="menuitem" name="copy" type="object">Duplicate</a>

in https://github.com/odoo/odoo/blob/b0e8cb21577966108ce3885e4fbcb7314d965660/addons/project/views/project_project_views.xml#L425

-> It's the generic copy() method used all over the place to duplicate records. project.project slightly modified  it though: https://github.com/odoo/odoo/blob/b0e8cb21577966108ce3885e4fbcb7314d965660/addons/project/models/project_project.py#L457


Still, this will work perfectly fine:

import xmlrpc.client

url = 'https://odoo.example.com'
db = 'example-odoo-dbname'
username = 'username'
password = 'password'

project_id = 42 # the project id to copy

# Auth
common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))
uid = common.authenticate(db, username, password, {})

# Copy project
models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))
result = models.execute_kw(db, uid, password, 'project.project', 'copy', [[project_id]])

print(result) # list of new project.project ids

In order to get the project.project object, just search/browse/read for it with the result.


See also https://www.odoo.com/documentation/18.0/de/developer/reference/external_api.html

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
พ.ค. 25
328
1
ก.ย. 23
2115
0
ก.ค. 23
1186
2
พ.ย. 22
2285
3
ม.ค. 22
6135