76 lines
2.7 KiB
Python
76 lines
2.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
# This file is part of the document-incoming-invoice-xml-module
|
|
# from m-ds for Tryton. The COPYRIGHT file at the top level of
|
|
# this repository contains the full copyright notices and license terms.
|
|
|
|
import os.path
|
|
from datetime import date
|
|
from trytond.tests.test_tryton import with_transaction
|
|
from trytond.pool import Pool
|
|
from trytond.modules.company.tests import create_company, set_company
|
|
|
|
|
|
class DocumentTestCase(object):
|
|
""" check import of xml + pdf files
|
|
"""
|
|
def prep_incomingdoc_run_worker(self):
|
|
""" run tasks from queue
|
|
"""
|
|
Queue = Pool().get('ir.queue')
|
|
|
|
while True:
|
|
tasks = Queue.search([])
|
|
if not tasks:
|
|
break
|
|
for task in tasks:
|
|
task.run()
|
|
Queue.delete(tasks)
|
|
|
|
@with_transaction()
|
|
def test_xmldoc_import_facturx(self):
|
|
""" create incoming-document, load xml, detect type
|
|
"""
|
|
pool = Pool()
|
|
IncDocument = pool.get('document.incoming')
|
|
|
|
company = create_company('m-ds')
|
|
with set_company(company):
|
|
|
|
to_create = []
|
|
with open(os.path.join(
|
|
os.path.split(__file__)[0],
|
|
'facturx-extended.xml'), 'rb') as fhdl:
|
|
to_create.append({
|
|
'data': fhdl.read(),
|
|
'name': 'facturx-extended.xml',
|
|
'type': 'supplier_invoice'})
|
|
|
|
document, = IncDocument.create(to_create)
|
|
self.assertEqual(document.mime_type, 'application/xml')
|
|
self.assertEqual(document.company.id, company.id)
|
|
self.assertTrue(document.data.startswith(
|
|
b'<?xml version="1.0" encoding="UTF-8"?>\n' +
|
|
b'<rsm:CrossIndustryInvoice xmlns'))
|
|
|
|
invoice = document._process_supplier_invoice()
|
|
print('\n## invoice:', (invoice,))
|
|
self.assertEqual(invoice.type, 'in')
|
|
self.assertEqual(invoice.number, 'RE2024.01234')
|
|
self.assertEqual(invoice.invoice_date, date(2024, 6, 17))
|
|
self.assertEqual(invoice.currency.name, 'usd')
|
|
self.assertEqual(invoice.company.rec_name, 'm-ds')
|
|
self.assertEqual(invoice.description, 'Description of invoice')
|
|
self.assertEqual(
|
|
invoice.comment,
|
|
'Code=1, Some notes to the customer.\n' +
|
|
'Code=22, Subject=42, Goes to field comment.')
|
|
invoice.save()
|
|
|
|
print('\n## invoice:', invoice)
|
|
|
|
# 'process' will queue the job to workers
|
|
IncDocument.process([document])
|
|
# run the usual call: process workers
|
|
self.prep_incomingdoc_run_worker()
|
|
|
|
# end DocumentTestCase
|