02.03.26
This commit is contained in:
@@ -181,33 +181,97 @@ class Incoming(DeactivableMixin, Workflow, ModelSQL, ModelView):
|
|||||||
def _split_mime_types(cls):
|
def _split_mime_types(cls):
|
||||||
return ['application/pdf']
|
return ['application/pdf']
|
||||||
|
|
||||||
|
# @classmethod
|
||||||
|
# def from_inbound_email(cls, email_, rule):
|
||||||
|
# message = email_.as_dict()
|
||||||
|
# attachments = message.get('attachments')
|
||||||
|
# active = False
|
||||||
|
# data = message.get('text', message.get('html'))
|
||||||
|
# logger.info("DATA_FROM_INBOUND_MAIL:%s",data)
|
||||||
|
# if isinstance(data, str):
|
||||||
|
# data = data.encode()
|
||||||
|
# body = message.get('text') or message.get('html') or ''
|
||||||
|
# if isinstance(body, str):
|
||||||
|
# body_bytes = body.encode('utf-8')
|
||||||
|
# else:
|
||||||
|
# body_bytes = body
|
||||||
|
# document = cls(
|
||||||
|
# active=active,
|
||||||
|
# name=message.get('subject', 'No Subject'),
|
||||||
|
# company=rule.document_incoming_company,
|
||||||
|
# data=data,
|
||||||
|
# type=rule.document_incoming_type if active else None,
|
||||||
|
# source='inbound_email',
|
||||||
|
# )
|
||||||
|
# children = []
|
||||||
|
# if attachments:
|
||||||
|
# for attachment in attachments:
|
||||||
|
# child = cls(
|
||||||
|
# name=attachment['filename'] or 'data.bin',
|
||||||
|
# company=rule.document_incoming_company,
|
||||||
|
# data=attachment['data'],
|
||||||
|
# type=rule.document_incoming_type,
|
||||||
|
# source='inbound_email')
|
||||||
|
# children.append(child)
|
||||||
|
# else:
|
||||||
|
# child = cls(
|
||||||
|
# name='mail_' + message.get('subject', 'No Subject') + '.txt',
|
||||||
|
# company=rule.document_incoming_company,
|
||||||
|
# data=body_bytes,
|
||||||
|
# type=rule.document_incoming_type,
|
||||||
|
# source='inbound_email',
|
||||||
|
# )
|
||||||
|
# children.append(child)
|
||||||
|
# document.children = children
|
||||||
|
# document.save()
|
||||||
|
# return document
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_inbound_email(cls, email_, rule):
|
def from_inbound_email(cls, email_, rule):
|
||||||
message = email_.as_dict()
|
message = email_.as_dict()
|
||||||
|
|
||||||
|
def clean(value):
|
||||||
|
if not value:
|
||||||
|
return value
|
||||||
|
return (
|
||||||
|
value
|
||||||
|
.replace('\n', ' ')
|
||||||
|
.replace('\r', ' ')
|
||||||
|
.replace("'", '')
|
||||||
|
.replace('"', '')
|
||||||
|
.strip()
|
||||||
|
)
|
||||||
|
|
||||||
|
subject = clean(message.get('subject', 'No Subject'))
|
||||||
|
|
||||||
attachments = message.get('attachments')
|
attachments = message.get('attachments')
|
||||||
active = False
|
active = False
|
||||||
data = message.get('text', message.get('html'))
|
data = message.get('text', message.get('html'))
|
||||||
logger.info("DATA_FROM_INBOUND_MAIL:%s",data)
|
logger.info("DATA_FROM_INBOUND_MAIL:%s", data)
|
||||||
|
|
||||||
if isinstance(data, str):
|
if isinstance(data, str):
|
||||||
data = data.encode()
|
data = data.encode()
|
||||||
|
|
||||||
body = message.get('text') or message.get('html') or ''
|
body = message.get('text') or message.get('html') or ''
|
||||||
if isinstance(body, str):
|
if isinstance(body, str):
|
||||||
body_bytes = body.encode('utf-8')
|
body_bytes = body.encode('utf-8')
|
||||||
else:
|
else:
|
||||||
body_bytes = body
|
body_bytes = body
|
||||||
|
|
||||||
document = cls(
|
document = cls(
|
||||||
active=active,
|
active=active,
|
||||||
name=message.get('subject', 'No Subject'),
|
name=subject,
|
||||||
company=rule.document_incoming_company,
|
company=rule.document_incoming_company,
|
||||||
data=data,
|
data=data,
|
||||||
type=rule.document_incoming_type if active else None,
|
type=rule.document_incoming_type if active else None,
|
||||||
source='inbound_email',
|
source='inbound_email',
|
||||||
)
|
)
|
||||||
|
|
||||||
children = []
|
children = []
|
||||||
if attachments:
|
if attachments:
|
||||||
for attachment in attachments:
|
for attachment in attachments:
|
||||||
|
filename = clean(attachment['filename'] or 'data.bin')
|
||||||
child = cls(
|
child = cls(
|
||||||
name=attachment['filename'] or 'data.bin',
|
name=filename,
|
||||||
company=rule.document_incoming_company,
|
company=rule.document_incoming_company,
|
||||||
data=attachment['data'],
|
data=attachment['data'],
|
||||||
type=rule.document_incoming_type,
|
type=rule.document_incoming_type,
|
||||||
@@ -215,13 +279,14 @@ class Incoming(DeactivableMixin, Workflow, ModelSQL, ModelView):
|
|||||||
children.append(child)
|
children.append(child)
|
||||||
else:
|
else:
|
||||||
child = cls(
|
child = cls(
|
||||||
name='mail_' + message.get('subject', 'No Subject') + '.txt',
|
name='mail_' + subject + '.txt',
|
||||||
company=rule.document_incoming_company,
|
company=rule.document_incoming_company,
|
||||||
data=body_bytes,
|
data=body_bytes,
|
||||||
type=rule.document_incoming_type,
|
type=rule.document_incoming_type,
|
||||||
source='inbound_email',
|
source='inbound_email',
|
||||||
)
|
)
|
||||||
children.append(child)
|
children.append(child)
|
||||||
|
|
||||||
document.children = children
|
document.children = children
|
||||||
document.save()
|
document.save()
|
||||||
return document
|
return document
|
||||||
@@ -284,7 +349,6 @@ class Incoming(DeactivableMixin, Workflow, ModelSQL, ModelView):
|
|||||||
default.setdefault('children')
|
default.setdefault('children')
|
||||||
return super().copy(documents, default=default)
|
return super().copy(documents, default=default)
|
||||||
|
|
||||||
|
|
||||||
def iter_pages(expression, size):
|
def iter_pages(expression, size):
|
||||||
ranges = set()
|
ranges = set()
|
||||||
for pages in expression.split(','):
|
for pages in expression.split(','):
|
||||||
|
|||||||
@@ -312,7 +312,7 @@ class Sale(metaclass=PoolMeta):
|
|||||||
id = 1
|
id = 1
|
||||||
for cont in shipment.container:
|
for cont in shipment.container:
|
||||||
if id == 1:
|
if id == 1:
|
||||||
info += ' Containers'
|
info += ' Container(s)'
|
||||||
if cont.container_no:
|
if cont.container_no:
|
||||||
info += ' ' + cont.container_no
|
info += ' ' + cont.container_no
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user