02.02.26
This commit is contained in:
@@ -62,25 +62,28 @@ class AutomationDocument(ModelSQL, ModelView, Workflow):
|
|||||||
def run_ocr(cls, docs):
|
def run_ocr(cls, docs):
|
||||||
for doc in docs:
|
for doc in docs:
|
||||||
try:
|
try:
|
||||||
# Décoder le fichier depuis le champ Binary
|
if doc.type == 'weight_report':
|
||||||
file_data = doc.document.data or b""
|
# Décoder le fichier depuis le champ Binary
|
||||||
logger.info(f"File size: {len(file_data)} bytes")
|
file_data = doc.document.data or b""
|
||||||
logger.info(f"First 20 bytes: {file_data[:20]}")
|
logger.info(f"File size: {len(file_data)} bytes")
|
||||||
logger.info(f"Last 20 bytes: {file_data[-20:]}")
|
logger.info(f"First 20 bytes: {file_data[:20]}")
|
||||||
|
logger.info(f"Last 20 bytes: {file_data[-20:]}")
|
||||||
|
|
||||||
file_name = doc.document.name or "document"
|
file_name = doc.document.name or "document"
|
||||||
|
|
||||||
# Envoyer le fichier au service OCR
|
# Envoyer le fichier au service OCR
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
"http://automation-service:8006/ocr",
|
"http://automation-service:8006/ocr",
|
||||||
files={"file": (file_name, io.BytesIO(file_data))}
|
files={"file": (file_name, io.BytesIO(file_data))}
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
data = response.json()
|
data = response.json()
|
||||||
logger.info("RUN_OCR_RESPONSE:%s",data)
|
logger.info("RUN_OCR_RESPONSE:%s",data)
|
||||||
doc.ocr_text = data.get("ocr_text", "")
|
doc.ocr_text = data.get("ocr_text", "")
|
||||||
doc.state = "ocr_done"
|
doc.state = "ocr_done"
|
||||||
doc.notes = (doc.notes or "") + "OCR done\n"
|
doc.notes = (doc.notes or "") + "OCR done\n"
|
||||||
|
else:
|
||||||
|
doc.ocr_text = (file_data or b'').decode('utf-8', errors='replace')
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
doc.state = "error"
|
doc.state = "error"
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class Incoming(metaclass=PoolMeta):
|
|||||||
wr.state = 'draft'
|
wr.state = 'draft'
|
||||||
WR.save([wr])
|
WR.save([wr])
|
||||||
WR.run_ocr([wr])
|
WR.run_ocr([wr])
|
||||||
WR.run_metadata([wr])
|
# WR.run_metadata([wr])
|
||||||
|
|
||||||
return wr
|
return wr
|
||||||
|
|
||||||
|
|||||||
@@ -115,15 +115,17 @@ this repository contains the full copyright notices and license terms. -->
|
|||||||
<field name="controller"/>
|
<field name="controller"/>
|
||||||
<button name="send" string="Send email to controller"/>
|
<button name="send" string="Send email to controller"/>
|
||||||
<newline/>
|
<newline/>
|
||||||
<label name="result"/>
|
<label name="add_bl"/>
|
||||||
<field name="result"/>
|
<field name="add_bl"/>
|
||||||
|
<newline/>
|
||||||
<label name="add_invoice"/>
|
<label name="add_invoice"/>
|
||||||
<field name="add_invoice"/>
|
<field name="add_invoice"/>
|
||||||
<newline/>
|
<newline/>
|
||||||
|
<label name="result"/>
|
||||||
|
<field name="result"/>
|
||||||
|
<newline/>
|
||||||
<label name="instructions"/>
|
<label name="instructions"/>
|
||||||
<field name="instructions" widget="html_viewer" colspan="4" height="100"/>
|
<field name="instructions" widget="Email" colspan="4" height="100"/>
|
||||||
<label name="add_bl"/>
|
|
||||||
<field name="add_bl"/>
|
|
||||||
<newline/>
|
<newline/>
|
||||||
<label name="returned_id"/>
|
<label name="returned_id"/>
|
||||||
<field name="returned_id"/>
|
<field name="returned_id"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user