02.02.26
This commit is contained in:
@@ -47,53 +47,11 @@ class Rule(metaclass=PoolMeta):
|
|||||||
DocumentIncoming = pool.get('document.incoming')
|
DocumentIncoming = pool.get('document.incoming')
|
||||||
return DocumentIncoming.fields_get(['type'])['type']['selection']
|
return DocumentIncoming.fields_get(['type'])['type']['selection']
|
||||||
|
|
||||||
# def run(self, email_):
|
|
||||||
# pool = Pool()
|
|
||||||
# DocumentIncoming = pool.get('document.incoming')
|
|
||||||
# super().run(email_)
|
|
||||||
# if (self.action == 'document.incoming|from_inbound_email'
|
|
||||||
# and self.document_incoming_process):
|
|
||||||
# document = email_.result
|
|
||||||
# DocumentIncoming.process([document], with_children=True)
|
|
||||||
|
|
||||||
def run(self, email_):
|
def run(self, email_):
|
||||||
pool = Pool()
|
pool = Pool()
|
||||||
DocumentIncoming = pool.get('document.incoming')
|
DocumentIncoming = pool.get('document.incoming')
|
||||||
super().run(email_)
|
super().run(email_)
|
||||||
|
if (self.action == 'document.incoming|from_inbound_email'
|
||||||
if self.action != 'document.incoming|from_inbound_email':
|
and self.document_incoming_process):
|
||||||
return
|
document = email_.result
|
||||||
|
DocumentIncoming.process([document], with_children=True)
|
||||||
data = email_.as_dict()
|
|
||||||
body = data.get('text') or data.get('html')
|
|
||||||
logger.info("BODY:%s",body)
|
|
||||||
attachments = data.get('attachments') or []
|
|
||||||
|
|
||||||
# 👉 S'il y avait des pièces jointes, le module standard a déjà créé les documents
|
|
||||||
if attachments:
|
|
||||||
if self.document_incoming_process and email_.result:
|
|
||||||
DocumentIncoming.process([email_.result], with_children=True)
|
|
||||||
return
|
|
||||||
|
|
||||||
# 🚨 Aucune pièce jointe → on crée un document depuis le corps du mail
|
|
||||||
|
|
||||||
if not body:
|
|
||||||
return # rien à créer
|
|
||||||
|
|
||||||
filename = (data.get('subject') or "email").strip()
|
|
||||||
filename = f"{filename}.txt"
|
|
||||||
|
|
||||||
document, = DocumentIncoming.create([{
|
|
||||||
'type': self.document_incoming_type,
|
|
||||||
'company': self.document_incoming_company.id
|
|
||||||
if self.document_incoming_company else None,
|
|
||||||
'filename': filename,
|
|
||||||
'data': body.encode('utf-8'),
|
|
||||||
'mime_type': 'text/plain',
|
|
||||||
'source': 'email',
|
|
||||||
}])
|
|
||||||
|
|
||||||
email_.result = document
|
|
||||||
|
|
||||||
if self.document_incoming_process:
|
|
||||||
DocumentIncoming.process([document], with_children=True)
|
|
||||||
Reference in New Issue
Block a user