76 lines
2.3 KiB
Python
76 lines
2.3 KiB
Python
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
|
# this repository contains the full copyright notices and license terms.
|
|
|
|
from trytond.i18n import gettext
|
|
from trytond.model import fields
|
|
from trytond.modules.document_incoming.exceptions import (
|
|
DocumentIncomingProcessError)
|
|
from trytond.pool import Pool, PoolMeta
|
|
import json
|
|
|
|
|
|
class IncomingConfiguration(metaclass=PoolMeta):
|
|
__name__ = 'document.incoming.configuration'
|
|
|
|
default_controller = fields.Many2One('party.party', "Default Controller")
|
|
|
|
|
|
class Incoming(metaclass=PoolMeta):
|
|
__name__ = 'document.incoming'
|
|
|
|
@classmethod
|
|
def __setup__(cls):
|
|
super().__setup__()
|
|
cls.type.selection.append(
|
|
('weight_report', "Weight Report"))
|
|
|
|
@classmethod
|
|
def _get_results(cls):
|
|
return super()._get_results() | {'automation.document'}
|
|
|
|
def _process_weight_report(self):
|
|
WR = Pool().get('automation.document')
|
|
wr = WR()
|
|
wr.document = self.id
|
|
wr.type = 'weight_report'
|
|
wr.state = 'draft'
|
|
WR.save([wr])
|
|
WR.run_ocr([wr])
|
|
WR.run_metadata([wr])
|
|
|
|
metadata = wr.metadata_json
|
|
|
|
# DEBUG: Vérifiez le type et contenu
|
|
print(f"Type de metadata: {type(metadata)}")
|
|
print(f"Contenu de metadata: {metadata}")
|
|
|
|
# Si c'est une chaîne, parsez-la
|
|
if isinstance(metadata, str):
|
|
try:
|
|
metadata = json.loads(metadata)
|
|
except json.JSONDecodeError as e:
|
|
raise DocumentIncomingProcessError(
|
|
gettext('document_incoming.msg_invalid_json',
|
|
document=self.rec_name,
|
|
error=str(e)))
|
|
|
|
# Maintenant metadata devrait être un dict
|
|
if not isinstance(metadata, dict):
|
|
raise DocumentIncomingProcessError(
|
|
gettext('document_incoming.msg_no_metadata',
|
|
document=self.rec_name))
|
|
|
|
# Créez le rapport - CORRECT, pas besoin de save() supplémentaire
|
|
WeightReport = Pool().get('weight.report')
|
|
WeightReport.create_from_json(metadata)
|
|
|
|
return wr
|
|
|
|
# @property
|
|
# def supplier_invoice_company(self):
|
|
# pass
|
|
|
|
# @property
|
|
# def supplier_invoice_party(self):
|
|
# pass
|