21.03.26
This commit is contained in:
@@ -24,6 +24,8 @@ import jwt
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from trytond.exceptions import UserWarning, UserError
|
from trytond.exceptions import UserWarning, UserError
|
||||||
from trytond.modules.purchase_trade.numbers_to_words import quantity_to_words, amount_to_currency_words, format_date_en
|
from trytond.modules.purchase_trade.numbers_to_words import quantity_to_words, amount_to_currency_words, format_date_en
|
||||||
|
import requests
|
||||||
|
import io
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -550,12 +552,10 @@ class AssayImporter:
|
|||||||
# -----------------------------
|
# -----------------------------
|
||||||
# HEADER
|
# HEADER
|
||||||
# -----------------------------
|
# -----------------------------
|
||||||
def _update_assay(self, data):
|
def _update_assay(self, data, assay):
|
||||||
Party = Pool().get('party.party')
|
Party = Pool().get('party.party')
|
||||||
metadata = data.get('document_metadata', {})
|
metadata = data.get('document_metadata', {})
|
||||||
|
|
||||||
assay = self.Assay()
|
|
||||||
|
|
||||||
assay.reference = metadata.get('report_reference')
|
assay.reference = metadata.get('report_reference')
|
||||||
assay.date = self._parse_date(metadata.get('issue_date'))
|
assay.date = self._parse_date(metadata.get('issue_date'))
|
||||||
assay.type = self._map_type(metadata.get('status'))
|
assay.type = self._map_type(metadata.get('status'))
|
||||||
@@ -1109,6 +1109,17 @@ class Line(metaclass=PoolMeta):
|
|||||||
if line.assays:
|
if line.assays:
|
||||||
for assay in line.assays:
|
for assay in line.assays:
|
||||||
if not assay.lines and assay.document:
|
if not assay.lines and assay.document:
|
||||||
|
file_data = assay.document or b""
|
||||||
|
logger.info(f"File size: {len(file_data)} bytes")
|
||||||
|
file_name = assay.file_name or "document"
|
||||||
|
|
||||||
|
response = requests.post(
|
||||||
|
"http://62.72.36.116:8006/ocr-parse-assay",
|
||||||
|
files={"file": (file_name, io.BytesIO(file_data))}
|
||||||
|
)
|
||||||
|
response.raise_for_status()
|
||||||
|
f = response.json()
|
||||||
|
logger.info("RUN_OCR_RESPONSE:%s",f)
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
importer = AssayImporter()
|
importer = AssayImporter()
|
||||||
importer.import_from_json(data,assay)
|
importer.import_from_json(data,assay)
|
||||||
|
|||||||
Reference in New Issue
Block a user