send print to whatsapp

85 views
Skip to first unread message

Obed Monteros

unread,
Jul 21, 2021, 7:46:55 PM7/21/21
to Jam.py Users Mailing List
How can I send an invoice directly from the print button to WhatsApp with the phone number saved in the customer contact of the same invoice generated.
Thanks

Drazen D. Babic

unread,
Jul 21, 2021, 8:27:35 PM7/21/21
to Jam.py Users Mailing List
There is no such a feature Obed. But someone could develop something similar, ie:

D.

Andrew Yushev

unread,
Jul 22, 2021, 8:20:14 AM7/22/21
to Drazen D. Babic, Jam.py Users Mailing List
Hi,

You can get the file name of the file that the report generates by writing the on_after_generate event handler.

def on_after_generate(report):
    print(report.report_filename)

Then you should find a python library that can work with WhatsApp, as Drazen suggests and
try to write the code.

Regards,
Andrew Yushev

чт, 22 июл. 2021 г. в 03:27, Drazen D. Babic <bab...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "Jam.py Users Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jam-py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jam-py/dba7b2a1-474f-499d-bbd6-bd5aa8b6514dn%40googlegroups.com.

Danijel Kaurin

unread,
Jan 3, 2023, 3:09:34 PM1/3/23
to Jam.py Users Mailing List
Hi Andrew.

If for example I want to generate report and send it as an attachment on the customer email address on button click, how to generate that report and get report_url? Also, I need to send item.id.value as parameter for report creation.

customer_email.PNG

I wish you all a Happy New Year!

Regards

Danijel Kaurin

Drazen D. Babic

unread,
Jan 3, 2023, 8:48:29 PM1/3/23
to Jam.py Users Mailing List
Hi Danijel, 
I think first is to play with the library:

And then as Andrew mentioned, add in your report Server:
def on_after_generate(report):
    print(report.report_filename)

That will give you the report path which you can send:
/home/dbabic/Downloads/jam.py-5.4.119/demo/static/reports/customers_report_2023-01-04_09-43-22.320724.pdf

Not sure about the ID.

D.


Drazen D. Babic

unread,
Jan 4, 2023, 12:32:01 AM1/4/23
to Jam.py Users Mailing List
Ok,
spent some time on this. Added on Journal Invoices, Customer Email as a Lookup.
On Print Invoice report, added:
import smtplib
.
.
def on_after_generate(report):
    invoices = report.task.invoices.copy()
    invoices.set_where(id=report.id.value)
    invoices.open()
    customer_email = invoices.customer_email.display_text
    gmail_user = 'jam-p...@gmail.com'
    gmail_pwd = 'pwd'
    from_user = 'root'

    subject = 'Test'
    mess = report.report_filename
    message = 'From: %s\nTo: %s\nSubject: %s\n\n%s' % (gmail_user, customer_email, subject, mess)    
    server = smtplib.SMTP("localhost", 25)
    server.ehlo()
    server.sendmail(from_user, customer_email, message)
    server.close()    

And that will nicely send me the email with a link (output from mail command on Linux):
.
.
>N  21 jam-py-demo@gmail. Wed Jan  4 13:02  13/573   Test
? 21
Return-Path: <ro...@dbabic-VirtualBox.localdomain>
X-Original-To: dbabic@localhost
Delivered-To: dbabic@localhost
Received: from [127.0.1.1] (localhost [127.0.0.1])
    by dbabic-VirtualBox.localdomain (Postfix) with ESMTP id 78BDBFE88D
    for <dbabic@localhost>; Wed,  4 Jan 2023 13:02:01 +0800 (AWST)
From: jam-p...@gmail.com
To: dbabic@localhost
Subject: Test
Message-Id: <202301040502...@dbabic-VirtualBox.localdomain>
Date: Wed,  4 Jan 2023 13:02:01 +0800 (AWST)

/home/dbabic/Downloads/jam.py-5.4.119/demo/static/reports/invoice_2023-01-04_13-02-00.238351.pdf


However, this is the OS Path, so click on it will not open anything in the Web browser. This is just to show that email work with the file path.
The next step is to strip the path from report.report_filename and add the Web server name instead of the path...

The similar procedure would work for WhatsApp, etc...

Danijel Kaurin

unread,
Jan 4, 2023, 2:27:28 AM1/4/23
to Drazen D. Babic, Jam.py Users Mailing List
Hi Dražen.

Here are instructions. My main doubt is do we always need to show report parameter form for sending email with attachment. I rather thought to find way for generating report in background without opening parameter form...

It would be nice to have a code example for sending attachments.

Regards


--
You received this message because you are subscribed to a topic in the Google Groups "Jam.py Users Mailing List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jam-py/3nN0haHM2xE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jam-py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jam-py/5322d29f-eaee-4f77-9de4-95955c5ee7cen%40googlegroups.com.

Drazen D. Babic

unread,
Jan 4, 2023, 2:35:02 AM1/4/23
to Jam.py Users Mailing List
I'm confused, there is no Report Param Form for Invoice report. We just click on Reports/Print.

Danijel Kaurin

unread,
Jan 4, 2023, 2:51:00 AM1/4/23
to Drazen D. Babic, Jam.py Users Mailing List
I didn't explained well: I don't want to print report at all (pdf print screen), just to generate it and export to folder status/reports and catch report_filename.

You received this message because you are subscribed to the Google Groups "Jam.py Users Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jam-py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jam-py/ed29bb0a-39a2-4a67-8eea-04e42052ac78n%40googlegroups.com.
Message has been deleted

Danijel Kaurin

unread,
Jan 4, 2023, 9:24:40 AM1/4/23
to Jam.py Users Mailing List
Here is full code:

...

import smtplib  # for sending e-mail
from email.mime.multipart import MIMEMultipart # for composing MIME e-mail
from email.mime.text import MIMEText # for composing MIME text
from email.mime.application import MIMEApplication #novi dio modula!!!
from os.path import basename

def on_after_generate(report):
    filename = report.report_filename

    sender_pass = "pass"    # password for SMTP server
    sender_smtp = "mail.com"          # SMTP server
    sender_port = 587                       # SMTP port (here is SSL/TLS)
    sender_user = "mymail"     # STMP sender account
   
    email_one= "mail...@gmail.com"
    email_two= " emai...@gmail.com  "
   
    # Create message container - the correct MIME type is multipart/alternative.
    msg = MIMEMultipart('alternative')
    msg['Subject'] = "Novi dnevni izvještaj"
    msg['From'] = sender_user
    #msg['To'] = email
    msg['To'] = fiksni_email
    msg['Cc'] = user_email
   
    email_recipients_list=  email_one.split(",") +  email_two.split(",")
   
    # e-mail text (plain)
    mail_text = """Test
   
    test
    """ 
   
    # e-mail text (html)
    mail_html = """\
    <html>
        <head></head>
        <body>
            <p>Test,<br><br>
               Test
                <hr>
                <i style="font-size: 11px">Test</i>
            </p>
        </body>
    </html>"""
   
    with open(filename, 'rb') as f:
        part = MIMEApplication(f.read(), Name=basename(filename))
   
    # Record the MIME types of both parts - text/plain and text/html.
    part1 = MIMEText(mail_text, 'plain')
    part2 = MIMEText(mail_html, 'html')
    part['Content-Disposition'] = 'attachment; filename="{}"'.format(basename(filename))
   
    # Attach parts into message container.
    msg.attach(part1)
    msg.attach(part2)
    msg.attach(part)
   
    # Send the message via local SMTP server.
    s = smtplib.SMTP(sender_smtp, sender_port) # SMTP server params
    #dbabic
    s.starttls()    # start SMTP session (TLS)
    #dbabic
    s.login(sender_user, sender_pass) # login to SMTP server

    # sendmail function takes 3 arguments: sender's address, recipient's address
    # and message to send - here it is sent as one string.
    s.sendmail(sender_user,  email_recipients_list  , msg.as_string())
    s.quit()

Regards

Danijel Kaurin

Danijel Kaurin

unread,
Jan 8, 2023, 5:08:01 PM1/8/23
to Jam.py Users Mailing List
Hi Andrew.

I'm working on sending report as an attachment in email. I have button that trigger this:

function print(item) {
    task.customers_report.customers.value = item.selections;
    task.customers_report.print(false);
}

but I don't want to show report in browser, I only want it to be saved in projects folder and than sent in email. I wrote code for all that but I don't know how to prevent showing report in browser and force only saving in background. How to do that in this step: task.customers_report.print(false);?

Regards


Andrew Yushev

unread,
Jan 9, 2023, 1:48:04 PM1/9/23
to Danijel Kaurin, Jam.py Users Mailing List
Hi, Danijel

I think you must use server mrthod to generated the report.
The Report class in the server_classes module has the print_report method.
Try to use it.

Regards

пн, 9 янв. 2023 г. в 01:08, Danijel Kaurin <yonika...@gmail.com>:

Drazen D. Babic

unread,
Jan 9, 2023, 9:14:18 PM1/9/23
to Jam.py Users Mailing List
Hi Andrew, 
I think it is not about the server method but the issue with opening a pop up Window, which is not needed in this case.
For example, if this is added in Client Module for report:
function on_before_print_report(report) {
    report.alert('Not yet implemented!');
}
it WILL open a new window. It is about how to prevent the pop up opening.

Regards
D.

Andrew Yushev

unread,
Jan 10, 2023, 12:54:15 PM1/10/23
to Drazen D. Babic, Jam.py Users Mailing List
I think the other way is to set the report_url attribute of the report to None.

def on_after_generate(report):
    report.report_url = None

вт, 10 янв. 2023 г. в 05:14, Drazen D. Babic <bab...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "Jam.py Users Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jam-py+un...@googlegroups.com.

Danijel Kaurin

unread,
Jan 10, 2023, 4:39:20 PM1/10/23
to Jam.py Users Mailing List
Hi all.

The solution is simple:

function print(item) {
    task.customers_report.customers.value = item.selections;
    task.customers_report.print();
}

Calling print method without (true) or (false) don't load report in broswer. This is great!

Regards

Drazen D. Babic

unread,
Jan 10, 2023, 11:22:17 PM1/10/23
to Jam.py Users Mailing List
Hi Andrew,

this works with Demo.  So, would it be possible to have a report parameter for report.report_url = None?
That way the report could be emailed with no pop up window.
How to do that parameter?


Andrew Yushev

unread,
Jan 12, 2023, 12:17:05 PM1/12/23
to Drazen D. Babic, Jam.py Users Mailing List
Drazen, I don't think this parameter is needed.
Write the event handler. You need to write the event handler to email it.

ср, 11 янв. 2023 г. в 07:22, Drazen D. Babic <bab...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "Jam.py Users Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jam-py+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages