Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
7 Ответы
11297 Представления

Hello,
How can I create planned activities via external API?
Odoo version 11

Аватар
Отменить

Thank you Yenthe, I would like to link to CRM  

Regards,  

Em sex, 24 de ago de 2018 às 04:04, Yenthe <yenthespam@gmail.com> escreveu:

A new answer on Creating a planned activity via the external API has been posted. Click here to access the post :

See post

--
Yenthe

Sent by Odoo S.A. using Odoo.

Лучший ответ

Hi Geraldo,

You can do this through XML-RPC by setting the correct values for the creation. I've made a proof of concept that shows the whole process to do it. You just have to get the right activity types and ids, which I didn't do in my example as I do not know where you want to link to:

import xmlrpclib

username = 'admin' # The Odoo user
pwd = 'admin' # The password of the Odoo user
dbname = 'v11' # The Odoo database

# OpenERP Common login Service proxy object 
sock_common = xmlrpclib.ServerProxy ('http://localhost:8069/xmlrpc/common')
uid = sock_common.login(dbname, username, pwd)

# replace localhost with the address of the server if it is not on the same server
# OpenERP Object manipulation service 
sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object')

activity_record = {
'activity_type_id': 1,
'res_id': 1,
'res_model_id': 1,
'date_deadline': '2018-08-30',
'user_id': 1,
'note': 'The activity message'

}

# Calling the remote ORM create method to create a record 
result = sock.execute(dbname, uid, pwd,'mail.activity', 'create', activity_record)
print('Inserted new activity! Id: ' + str(result))


Regards,

Yenthe

Аватар
Отменить

Thanks a lot Yenthe! This helped me create an automated action that creates an activity :)

Лучший ответ

I'm trying to adapt this to an automatic action, but I'm having this error:

ValueError: <class 'KeyError'>: "mail_activity" while evaluating"activity_record = {\n'activity_type_id': 4,\n'res_id': record.id,\n'res_model_id': model.id,\n'date_deadline': record.date_due,\n'user_id': 1,\n'note': 'Pagar a Fatura',\n'summary': 'PAGAR FATURA'\n}\n\nenv['mail_activity'].create(activity_record)"

My code in automated action:

activity_record = {
'activity_type_id': 4,
'res_id': record.id,
'res_model_id': model.id,
'date_deadline': record.date_due,
'user_id': 1,
'note': 'Pagar a Fatura',
'summary': 'PAGAR FATURA'
}
env['mail_activity'].create(activity_record)
Can you help me, please?
Аватар
Отменить
Автор Лучший ответ

Thank you Yenthe, I would like to link to CRM  


Regards,  
Аватар
Отменить
Лучший ответ

For the person working in automated actions, you may need to do something like this in order to set the res_model_id because it isn't always easily accessible from the other models (ex - mail.message):

env.cr.execute("SELECT id FROM ir_model WHERE model = '" + record.model + "';")
fetch = env.cr.fetchall()
env['mail.activity'].create({ 
    'activity_type_id': 1,     #Email Activity
    'res_model_id': str(fetch)[2:-3],
    'res_id': record.res_id, 
    'user_id': record.create_uid.id,
    'note': record.body,
})

Аватар
Отменить
Related Posts Ответы Просмотры Активность
0
сент. 18
4616
1
июн. 18
3566
0
мар. 23
1474
2
янв. 23
4287
1
нояб. 22
2940