This commit is contained in:
2026-02-01 20:58:57 +01:00
parent 4513ce8ac7
commit f5d6d4ef55
3 changed files with 55 additions and 3 deletions

View File

@@ -22,6 +22,7 @@ class AutomationDocument(ModelSQL, ModelView, Workflow):
('invoice', 'Invoice'),
('statement_of_facts', 'Statement of Facts'),
('weight_report', 'Weight Report'),
('controller', 'Controller'),
('bol', 'Bill of Lading'),
('controller_invoice', 'Controller Invoice'),
], 'Type')

View File

@@ -46,11 +46,51 @@ class Rule(metaclass=PoolMeta):
DocumentIncoming = pool.get('document.incoming')
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_):
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
if self.action != 'document.incoming|from_inbound_email':
return
data = email_.as_dict()
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
body = data.get('text') or data.get('html')
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)

View File

@@ -23,6 +23,8 @@ class Incoming(metaclass=PoolMeta):
super().__setup__()
cls.type.selection.append(
('weight_report', "Weight Report"))
cls.type.selection.append(
('controller', "Controller"))
@classmethod
def _get_results(cls):
@@ -39,6 +41,15 @@ class Incoming(metaclass=PoolMeta):
WR.run_metadata([wr])
return wr
def _process_controller(self):
WR = Pool().get('automation.document')
wr = WR()
wr.document = self.id
wr.type = 'controller'
wr.state = 'draft'
WR.save([wr])
return wr
# @property
# def supplier_invoice_company(self):