parent
6321864b45
commit
2ce484cdde
17
shipment.py
17
shipment.py
|
@ -14,6 +14,7 @@ from email.mime.multipart import MIMEMultipart
|
|||
from email.mime.text import MIMEText
|
||||
from trytond.wizard import Wizard, StateView, Button, StateTransition
|
||||
import logging
|
||||
import re
|
||||
|
||||
try:
|
||||
import qrcode
|
||||
|
@ -28,6 +29,13 @@ __all__ = ['ShipmentOut', 'SendLink', 'SendLinkStart']
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def format_emails(email):
|
||||
if not email:
|
||||
return []
|
||||
values = re.split(r'[,;]', email)
|
||||
return [v.strip() for v in values]
|
||||
|
||||
|
||||
class ShipmentWebLinkMixin(object):
|
||||
|
||||
encrypted_url = fields.Function(fields.Char('Encrypted URL'),
|
||||
|
@ -123,13 +131,14 @@ class ShipmentWebLinkMixin(object):
|
|||
Move.draft(moves)
|
||||
if not send_mail:
|
||||
return
|
||||
email = email or shipment.get_to_email()
|
||||
|
||||
if from_ is None:
|
||||
from_ = config.get('email', 'from')
|
||||
for shipment in shipments:
|
||||
shipment_email = email or shipment.get_to_email()
|
||||
shipment.encrypted_url = shipment.get_encrypted_url()
|
||||
user = User(Transaction().user)
|
||||
if not email:
|
||||
if not shipment_email:
|
||||
if raise_error:
|
||||
cls.raise_user_error('missing_link_email',
|
||||
shipment.rec_name)
|
||||
|
@ -139,9 +148,9 @@ class ShipmentWebLinkMixin(object):
|
|||
return
|
||||
msg, title = shipment.get_email_shipment_flask(user)
|
||||
msg['From'] = from_
|
||||
msg['To'] = email
|
||||
msg['To'] = shipment_email
|
||||
msg['Subject'] = Header(title, 'utf-8')
|
||||
sendmail_transactional(from_, [email], msg)
|
||||
sendmail_transactional(from_, format_emails(shipment_email), msg)
|
||||
|
||||
def get_encrypted_id(self, name=None):
|
||||
fernet = self.get_fernet()
|
||||
|
|
Loading…
Reference in New Issue