# -*- 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.exceptions import UserError from trytond.modules.company.tests import create_company, set_company from trytond.modules.account.tests import create_chart, get_fiscalyear def set_invoice_sequences(fiscalyear): pool = Pool() Sequence = pool.get('ir.sequence.strict') SequenceType = pool.get('ir.sequence.type') InvoiceSequence = pool.get('account.fiscalyear.invoice_sequence') ModelData = pool.get('ir.model.data') sequence = Sequence( name=fiscalyear.name, sequence_type=SequenceType(ModelData.get_id( 'account_invoice', 'sequence_type_account_invoice')), company=fiscalyear.company, ) sequence.save() fiscalyear.invoice_sequences = [] invoice_sequence = InvoiceSequence() invoice_sequence.fiscalyear = fiscalyear invoice_sequence.in_invoice_sequence = sequence invoice_sequence.in_credit_note_sequence = sequence invoice_sequence.out_invoice_sequence = sequence invoice_sequence.out_credit_note_sequence = sequence invoice_sequence.save() return fiscalyear 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) def prep_fiscalyear(self, company1): """ prepare fiscal year, sequences... """ pool = Pool() FiscalYear = pool.get('account.fiscalyear') fisc_year = get_fiscalyear(company1, today=date(2025, 1, 15)) set_invoice_sequences(fisc_year) fisc_year.save() FiscalYear.create_period([fisc_year]) @with_transaction() def test_xmldoc_import_facturx(self): """ create incoming-document, load xml, detect type """ pool = Pool() IncDocument = pool.get('document.incoming') Configuration = pool.get('document.incoming.configuration') Party = pool.get('party.party') company = create_company('m-ds') with set_company(company): create_chart(company=company, tax=True) self.prep_fiscalyear(company) config = Configuration() config.save() self.assertEqual(config.create_supplier, True) self.assertEqual(config.accept_other_company, False) 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'\n' + b'