lims, lims_email, lims_account_invoice, lims_sale: set email attachment name differently

This commit is contained in:
Adrián Bernardi 2021-12-23 18:13:55 -03:00
parent ae9c7c217b
commit 115c5ff020
4 changed files with 37 additions and 36 deletions

View File

@ -4,9 +4,10 @@
# the full copyright notices and license terms.
import logging
from datetime import datetime
from email import encoders
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
from sql import Literal
from trytond.model import Workflow, ModelView, ModelSQL, fields, Unique
@ -674,24 +675,23 @@ class Entry(Workflow, ModelSQL, ModelView):
if not to_addrs:
return None
msg = MIMEMultipart()
msg = MIMEMultipart('mixed')
msg['From'] = from_addr
hidden = True # TODO: HARDCODE!
if not hidden:
msg['To'] = ', '.join(to_addrs)
msg['Subject'] = subject
msg_body = MIMEBase('text', 'plain')
msg_body = MIMEText('text', 'plain')
msg_body.set_payload(body.encode('UTF-8'), 'UTF-8')
msg.attach(msg_body)
attachment = MIMEApplication(
attachment_data['content'],
Name=attachment_data['filename'], _subtype="pdf")
attachment.add_header('content-disposition', 'attachment',
filename=('utf-8', '', attachment_data['filename']))
attachment = MIMEBase('application', 'octet-stream')
attachment.set_payload(attachment_data['content'])
encoders.encode_base64(attachment)
attachment.add_header('Content-Disposition', 'attachment',
filename=attachment_data['filename'])
msg.attach(attachment)
return msg
def send_msg(self, from_addr, to_addrs, msg):

View File

@ -3,9 +3,10 @@
# The COPYRIGHT file at the top level of this repository contains
# the full copyright notices and license terms.
from datetime import datetime
from email import encoders
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
from time import time
import logging
@ -185,25 +186,24 @@ class Invoice(metaclass=PoolMeta):
if not to_addrs:
return None
msg = MIMEMultipart()
msg = MIMEMultipart('mixed')
msg['From'] = from_addr
hidden = True # TODO: HARDCODE!
if not hidden:
msg['To'] = ', '.join(to_addrs)
msg['Subject'] = subject
msg_body = MIMEBase('text', 'plain')
msg_body = MIMEText('text', 'plain')
msg_body.set_payload(body.encode('UTF-8'), 'UTF-8')
msg.attach(msg_body)
for attachment_data in attachments_data:
attachment = MIMEApplication(
attachment_data['content'],
Name=attachment_data['filename'], _subtype="pdf")
attachment.add_header('content-disposition', 'attachment',
filename=('utf-8', '', attachment_data['filename']))
attachment = MIMEBase('application', 'octet-stream')
attachment.set_payload(attachment_data['content'])
encoders.encode_base64(attachment)
attachment.add_header('Content-Disposition', 'attachment',
filename=attachment_data['filename'])
msg.attach(attachment)
return msg
def send_msg(self, from_addr, to_addrs, msg):

View File

@ -3,9 +3,10 @@
# the full copyright notices and license terms.
import logging
from datetime import datetime
from email import encoders
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
from string import Template
from trytond.model import ModelSQL, ModelView, fields
@ -578,22 +579,22 @@ class SendResultsReport(Wizard):
if not to_addrs:
return None
msg = MIMEMultipart()
msg = MIMEMultipart('mixed')
msg['From'] = from_addr
if not hide_recipients:
msg['To'] = ', '.join(to_addrs)
msg['Subject'] = subject
msg_body = MIMEBase('text', 'plain')
msg_body = MIMEText('text', 'plain')
msg_body.set_payload(body.encode('UTF-8'), 'UTF-8')
msg.attach(msg_body)
for attachment_data in attachments_data:
attachment = MIMEApplication(
attachment_data['content'],
Name=attachment_data['filename'], _subtype="pdf")
attachment.add_header('content-disposition', 'attachment',
filename=('utf-8', '', attachment_data['filename']))
attachment = MIMEBase('application', 'octet-stream')
attachment.set_payload(attachment_data['content'])
encoders.encode_base64(attachment)
attachment.add_header('Content-Disposition', 'attachment',
filename=attachment_data['filename'])
msg.attach(attachment)
return msg

View File

@ -2,10 +2,10 @@
# The COPYRIGHT file at the top level of this repository contains
# the full copyright notices and license terms.
import logging
from email import encoders
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
from email.header import Header
from trytond.model import ModelSQL, ModelView, fields
from trytond.wizard import Wizard, StateView, StateTransition, Button
@ -155,22 +155,22 @@ class Sale(metaclass=PoolMeta):
if not (from_addr or to_addr):
return None
msg = MIMEMultipart()
msg = MIMEMultipart('mixed')
msg['From'] = from_addr
msg['To'] = to_addr
msg['Reply-to'] = reply_to
msg['Subject'] = Header(subject, 'utf-8')
msg['Subject'] = subject
msg_body = MIMEBase('text', 'plain')
msg_body = MIMEText('text', 'plain')
msg_body.set_payload(body.encode('UTF-8'), 'UTF-8')
msg.attach(msg_body)
attachment = MIMEApplication(attachment_data['content'],
Name=attachment_data['filename'], _subtype="pdf")
attachment.add_header('content-disposition', 'attachment',
filename=('utf-8', '', attachment_data['filename']))
attachment = MIMEBase('application', 'octet-stream')
attachment.set_payload(attachment_data['content'])
encoders.encode_base64(attachment)
attachment.add_header('Content-Disposition', 'attachment',
filename=attachment_data['filename'])
msg.attach(attachment)
return msg
@staticmethod