Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Send the same reports as there are in "Reporting->Phone Calls Analysis" Daily via an email

By
Anti Nuga
on 3/14/16, 5:30 AM 316 views

And I'd like to add domains to it (e.g. domain="[('date','=',time.strftime('%Y-%m-%d')),('state','=','done')]" ). I have tried making email templates using crm.phonecall.report.graph module, but with no success.

Create an automated action (scheduler) that runs every day. Make it browse through the records and search for the reports you need (your date filtering). Send the e-mail with the send_mail function and simply attach the report to the e-mail.

Yenthe
on 3/14/16, 5:34 AM

Could you elaborate a bit more? I've never done any automated actions, so a little guide would be awesome.

Anti Nuga
on 3/14/16, 6:28 AM
0
Anti Nuga
On 5/16/16, 6:40 AM

Managed to do it using API and Python. You can make it run daily/weekly/montly by using cron.(Im running this in an Ubuntu server)

References: 

https://www.odoo.com/documentation/8.0/api_integration.html
https://docs.python.org/2/library/email-examples.html


Code: 

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time
import datetime
from datetime import date
import xmlrpclib
from xmlrpclib import ServerProxy
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
SERVER = 'SERVERADDRESS'
db = 'DBNAME'
user_id = 'admin'
password = 'password'
#Connecting to the server
server = ServerProxy(SERVER+'/xmlrpc/common')
uid = server.login(db, user_id, password)
server = ServerProxy(SERVER+'/xmlrpc/object')
start = 'today'
stop = 'tomorrow'
#Example query
#returns a dictionary or False
query = server.execute_kw(db, uid, password,
'crm.phonecall', 'search_read',
[[['date','>=',start],['date','<=',stop],['state','ilike','done']]],
{'fields': ['user_id']})
#PARSE YOUR DATA
msg = MIMEMultipart('alternative')
COMMASPACE = ', '
people = ['person1@space.com','person2@otherplace.com']
me = 'me@me.me'
msg['Subject'] = 'SUBJECT'
msg['From'] = me
msg['To'] = COMMASPACE.join(people)
html = """\
<html>
    <head>
        <style></style>
    </head>
    <body>Parsed data from the query goes here. You can use CSS.</body>
</html>
"""
part1 = MIMEText(html, 'html')
msg.attach(part1)
# Send the message via our own SMTP server, but don't include the
# envelope header.
s = smtplib.SMTP('SMTPADDRESS')
s.starttls()
s.login('me@me.me', 'password123')
s.sendmail('me@me.me', people, msg.as_string())
s.quit()

If you share your solution, it would benefit others. (And your 'solution' would be worth the correct answer!!).

Bista Solutions US, Ray Carnes
on 5/17/16, 10:56 PM

Edited

Anti Nuga
on 5/18/16, 7:28 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 3/14/16, 5:30 AM
Seen: 316 times
Last updated: 5/16/16, 6:40 AM