-
Notifications
You must be signed in to change notification settings - Fork 10
/
mailing_mailing.py
75 lines (65 loc) · 3.73 KB
/
mailing_mailing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/python
# encoding: utf-8
import xmlrpclib
usernameFrom = 'admin' # Odoo From user
pwdFrom = 'admin' # Odoo From password
dbFrom = 'odoo' # Odoo From base de datos
urlFrom = 'http://localhost:8069' # Odoo From URL
usernameTo = 'admin' # Odoo To user
pwdTo = 'admin' # Odoo To password
dbTo = 'odoo' # Odoo To base de datos
urlTo = 'http://localhost:8069' # Odoo To URL
valsFrom = {'fields': ['subject', 'preview', 'body_html', 'state', 'sent_date']}
commonFrom = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(urlFrom))
commonFrom.version()
uidFrom = commonFrom.authenticate(dbFrom, usernameFrom, pwdFrom, {})
commonTo = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(urlTo))
commonTo.version()
uidTo = commonTo.authenticate(dbTo, usernameTo, pwdTo, {})
modelsFrom = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(urlFrom))
modelsTo = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(urlTo))
mailing_ids_from = modelsFrom.execute_kw(dbFrom, uidFrom, pwdFrom, 'mailing.mailing', 'search', [[('state', '=', 'done')]], {'order': 'id asc'}) # Ajustar dominio de búsqueda de acuerdo a las necesidades
print(mailing_ids_from)
for mail in mailing_ids_from:
print(mail)
from_id = modelsFrom.execute_kw(dbFrom, uidFrom, pwdFrom, 'mailing.mailing', 'read', [mail], valsFrom)
to_mail = modelsTo.execute_kw(dbTo, uidTo, pwdTo, 'mailing.mailing', 'create', [{
'subject': from_id[0]['subject'],
'preview': from_id[0]['preview'],
'sent_date': from_id[0]['sent_date'],
'body_html': from_id[0]['body_html'],
'body_arch': from_id[0]['body_html'],
'state': from_id[0]['state'],
}])
mailings = modelsFrom.execute_kw(dbFrom, uidFrom, pwdFrom, 'mailing.trace', 'search', [[('mass_mailing_id', '=', mail)]])
for mass_mail in mailings:
# Versión 14 o anteriores
prev_mail = modelsFrom.execute_kw(dbFrom, uidFrom, pwdFrom, 'mailing.trace', 'read', [mass_mail], {'fields': ['email', 'sent', 'opened', 'clicked', 'message_id', 'res_id', 'state']})
# Versión 15 o posteriores
#prev_mail = modelsFrom.execute_kw(dbFrom, uidFrom, pwdFrom, 'mailing.trace', 'read', [mass_mail], {'fields': ['email', 'sent_datetime', 'open_datetime', 'inks_click_datetime', 'message_id', 'res_id', 'trace_status']})
# Versión 14 o anteriores
#new_mail = modelsTo.execute_kw(dbTo, uidTo, pwdTo, 'mailing.trace', 'create', [{
# 'email': prev_mail[0]['email'],
# 'sent': prev_mail[0]['sent'],
# 'opened': prev_mail[0]['opened'],
# 'clicked': prev_mail[0]['clicked'],
# 'mass_mailing_id': to_mail,
# 'message_id': prev_mail[0]['message_id'],
# 'model': 'mailing.contact',
# 'trace_type': 'mail',
# 'res_id': prev_mail[0]['res_id'],
# 'state': prev_mail[0]['state']
#}])
# Versión 15 o posteriores
new_mail = modelsTo.execute_kw(dbTo, uidTo, pwdTo, 'mailing.trace', 'create', [{
'email': prev_mail[0]['email'],
'sent_datetime': prev_mail[0]['sent'],
'open_datetime': prev_mail[0]['opened'],
'links_click_datetime': prev_mail[0]['clicked'],
'mass_mailing_id': to_mail,
'message_id': prev_mail[0]['message_id'],
'model': 'mailing.contact',
'trace_type': 'mail',
'res_id': prev_mail[0]['res_id'],
'trace_status': prev_mail[0]['state'].replace('opened', 'open').replace('ignored', 'sent') # En odoo 15+ state se llama trace_status y tiene valores distintos, ajustar a cada necesidad si hace falta
}])