Faircot process
This commit is contained in:
@@ -295,23 +295,60 @@ class Incoming(DeactivableMixin, Workflow, ModelSQL, ModelView):
|
||||
@ModelView.button
|
||||
@Workflow.transition('processing')
|
||||
def process(cls, documents, with_children=False):
|
||||
logger.info(
|
||||
"DOCUMENT_INCOMING_PROCESS_CLICK documents=%s with_children=%s",
|
||||
[
|
||||
{
|
||||
'id': document.id,
|
||||
'name': document.name,
|
||||
'type': document.type,
|
||||
'state': document.state,
|
||||
}
|
||||
for document in documents
|
||||
],
|
||||
with_children)
|
||||
transaction = Transaction()
|
||||
context = transaction.context
|
||||
with transaction.set_context(
|
||||
queue_batch=context.get('queue_batch', True)):
|
||||
logger.info(
|
||||
"DOCUMENT_INCOMING_PROCESS_QUEUE documents=%s queue_batch=%s",
|
||||
[document.id for document in documents],
|
||||
transaction.context.get('queue_batch'))
|
||||
cls.__queue__.proceed(documents, with_children=with_children)
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
@Workflow.transition('done')
|
||||
def proceed(cls, documents, with_children=False):
|
||||
logger.info(
|
||||
"DOCUMENT_INCOMING_PROCEED_START documents=%s with_children=%s",
|
||||
[
|
||||
{
|
||||
'id': document.id,
|
||||
'name': document.name,
|
||||
'type': document.type,
|
||||
'state': document.state,
|
||||
'active': document.active,
|
||||
'result': str(document.result) if document.result else None,
|
||||
}
|
||||
for document in documents
|
||||
],
|
||||
with_children)
|
||||
pool = Pool()
|
||||
Attachment = pool.get('ir.attachment')
|
||||
results = defaultdict(list)
|
||||
attachments = []
|
||||
for document in documents:
|
||||
if document.result or not document.active:
|
||||
logger.info(
|
||||
"DOCUMENT_INCOMING_PROCEED_SKIP document=%s "
|
||||
"result=%s active=%s",
|
||||
document.id, document.result, document.active)
|
||||
continue
|
||||
logger.info(
|
||||
"DOCUMENT_INCOMING_PROCEED_DISPATCH document=%s method=%s",
|
||||
document.id, f'_process_{document.type}')
|
||||
document.result = getattr(document, f'_process_{document.type}')()
|
||||
results[document.result.__class__].append(document.result)
|
||||
attachment = Attachment(
|
||||
|
||||
Reference in New Issue
Block a user