add test for created invoice
This commit is contained in:
parent
98e66000a9
commit
4a93608329
1 changed files with 160 additions and 140 deletions
|
@ -4,6 +4,7 @@
|
||||||
# this repository contains the full copyright notices and license terms.
|
# this repository contains the full copyright notices and license terms.
|
||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
|
import copy
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from datetime import date
|
from datetime import date
|
||||||
from trytond.tests.test_tryton import with_transaction
|
from trytond.tests.test_tryton import with_transaction
|
||||||
|
@ -13,141 +14,7 @@ from trytond.modules.company.tests import create_company, set_company
|
||||||
from trytond.modules.account.tests import create_chart, get_fiscalyear
|
from trytond.modules.account.tests import create_chart, get_fiscalyear
|
||||||
|
|
||||||
|
|
||||||
def set_invoice_sequences(fiscalyear):
|
parsed_data_facturx = {
|
||||||
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])
|
|
||||||
|
|
||||||
def prep_prodcat_category(self, company):
|
|
||||||
""" create product category
|
|
||||||
"""
|
|
||||||
pool = Pool()
|
|
||||||
ProdCat = pool.get('product.category')
|
|
||||||
Account = pool.get('account.account')
|
|
||||||
Tax = pool.get('account.tax')
|
|
||||||
|
|
||||||
# get accounts expense/revenue
|
|
||||||
acc_exp, acc_rev, acc_tax, = Account.search([
|
|
||||||
('name', 'in', ['Main Revenue', 'Main Expense', 'Main Tax'])
|
|
||||||
], order=[('name', 'ASC')])
|
|
||||||
self.assertEqual(acc_exp.name, 'Main Expense')
|
|
||||||
self.assertEqual(acc_rev.name, 'Main Revenue')
|
|
||||||
self.assertEqual(acc_tax.name, 'Main Tax')
|
|
||||||
|
|
||||||
# check tax
|
|
||||||
tax, = Tax.search([])
|
|
||||||
self.assertEqual(tax.name, '20% VAT')
|
|
||||||
self.assertEqual(tax.invoice_account.name, 'Main Tax')
|
|
||||||
self.assertEqual(tax.credit_note_account.name, 'Main Tax')
|
|
||||||
tax_19, = Tax.copy([tax], {
|
|
||||||
'name': '19% VAT', 'rate': Decimal('0.19')})
|
|
||||||
tax_7, = Tax.copy([tax], {
|
|
||||||
'name': '7% VAT', 'rate': Decimal('0.07')})
|
|
||||||
|
|
||||||
p_cat, p_cat_19, tax_7, = ProdCat.create([{
|
|
||||||
'name': 'Accounting',
|
|
||||||
'accounting': True,
|
|
||||||
'account_parent': False,
|
|
||||||
'account_expense': acc_exp.id,
|
|
||||||
'account_revenue': acc_rev.id,
|
|
||||||
'taxes_parent': False,
|
|
||||||
'customer_taxes': [('add', [tax.id])],
|
|
||||||
'supplier_taxes': [('add', [tax.id])],
|
|
||||||
}, {
|
|
||||||
'name': 'Accounting 19%',
|
|
||||||
'accounting': True,
|
|
||||||
'account_parent': False,
|
|
||||||
'account_expense': acc_exp.id,
|
|
||||||
'account_revenue': acc_rev.id,
|
|
||||||
'taxes_parent': False,
|
|
||||||
'customer_taxes': [('add', [tax_19.id])],
|
|
||||||
'supplier_taxes': [('add', [tax_19.id])],
|
|
||||||
}, {
|
|
||||||
'name': 'Accounting 7%',
|
|
||||||
'accounting': True,
|
|
||||||
'account_parent': False,
|
|
||||||
'account_expense': acc_exp.id,
|
|
||||||
'account_revenue': acc_rev.id,
|
|
||||||
'taxes_parent': False,
|
|
||||||
'customer_taxes': [('add', [tax_7.id])],
|
|
||||||
'supplier_taxes': [('add', [tax_7.id])],
|
|
||||||
}])
|
|
||||||
self.assertEqual(p_cat.name, 'Accounting')
|
|
||||||
self.assertEqual(p_cat.accounting, True)
|
|
||||||
self.assertEqual(p_cat.account_parent, False)
|
|
||||||
self.assertEqual(p_cat.taxes_parent, False)
|
|
||||||
self.assertEqual(p_cat.account_expense.name, 'Main Expense')
|
|
||||||
self.assertEqual(p_cat.account_revenue.name, 'Main Revenue')
|
|
||||||
self.assertEqual(p_cat.customer_taxes[0].name, '20% VAT')
|
|
||||||
self.assertEqual(p_cat.supplier_taxes[0].name, '20% VAT')
|
|
||||||
return [p_cat, p_cat_19, tax_7]
|
|
||||||
|
|
||||||
@with_transaction()
|
|
||||||
def test_xmldoc_check_xml_read_facturx_extended(self):
|
|
||||||
""" add incoming-dcument in memory, read xml into 'parsed_data'
|
|
||||||
"""
|
|
||||||
pool = Pool()
|
|
||||||
IncDocument = pool.get('document.incoming')
|
|
||||||
|
|
||||||
with open(os.path.join(
|
|
||||||
os.path.split(__file__)[0],
|
|
||||||
'facturx-extended.xml'), 'rb') as fhdl:
|
|
||||||
xml_txt = fhdl.read()
|
|
||||||
|
|
||||||
incoming = IncDocument(data=xml_txt)
|
|
||||||
(xsdtype, funcname, xml_data) = incoming._facturx_detect_content()
|
|
||||||
self.assertEqual(xsdtype, 'Factur-X extended')
|
|
||||||
self.assertEqual(funcname, 'facturx_extended')
|
|
||||||
|
|
||||||
incoming._readxml_facturx_extended(xml_data)
|
|
||||||
self.assertEqual(incoming.parsed_data, {
|
|
||||||
'invoice_number': 'RE2024.01234',
|
'invoice_number': 'RE2024.01234',
|
||||||
'invoice_date': date(2024, 6, 17),
|
'invoice_date': date(2024, 6, 17),
|
||||||
'note_list': [{
|
'note_list': [{
|
||||||
|
@ -286,7 +153,144 @@ class DocumentTestCase(object):
|
||||||
'taxbase': Decimal('2850.00'),
|
'taxbase': Decimal('2850.00'),
|
||||||
'taxtotal': Decimal('505.5'),
|
'taxtotal': Decimal('505.5'),
|
||||||
'grand': Decimal('3355.50'),
|
'grand': Decimal('3355.50'),
|
||||||
'duepayable': Decimal('3355.50')}})
|
'duepayable': Decimal('3355.50')}}
|
||||||
|
|
||||||
|
|
||||||
|
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])
|
||||||
|
|
||||||
|
def prep_prodcat_category(self, company):
|
||||||
|
""" create product category
|
||||||
|
"""
|
||||||
|
pool = Pool()
|
||||||
|
ProdCat = pool.get('product.category')
|
||||||
|
Account = pool.get('account.account')
|
||||||
|
Tax = pool.get('account.tax')
|
||||||
|
|
||||||
|
# get accounts expense/revenue
|
||||||
|
acc_exp, acc_rev, acc_tax, = Account.search([
|
||||||
|
('name', 'in', ['Main Revenue', 'Main Expense', 'Main Tax'])
|
||||||
|
], order=[('name', 'ASC')])
|
||||||
|
self.assertEqual(acc_exp.name, 'Main Expense')
|
||||||
|
self.assertEqual(acc_rev.name, 'Main Revenue')
|
||||||
|
self.assertEqual(acc_tax.name, 'Main Tax')
|
||||||
|
|
||||||
|
# check tax
|
||||||
|
tax, = Tax.search([])
|
||||||
|
self.assertEqual(tax.name, '20% VAT')
|
||||||
|
self.assertEqual(tax.invoice_account.name, 'Main Tax')
|
||||||
|
self.assertEqual(tax.credit_note_account.name, 'Main Tax')
|
||||||
|
tax_19, = Tax.copy([tax], {
|
||||||
|
'name': '19% VAT', 'rate': Decimal('0.19')})
|
||||||
|
tax_7, = Tax.copy([tax], {
|
||||||
|
'name': '7% VAT', 'rate': Decimal('0.07')})
|
||||||
|
|
||||||
|
p_cat, p_cat_19, tax_7, = ProdCat.create([{
|
||||||
|
'name': 'Accounting',
|
||||||
|
'accounting': True,
|
||||||
|
'account_parent': False,
|
||||||
|
'account_expense': acc_exp.id,
|
||||||
|
'account_revenue': acc_rev.id,
|
||||||
|
'taxes_parent': False,
|
||||||
|
'customer_taxes': [('add', [tax.id])],
|
||||||
|
'supplier_taxes': [('add', [tax.id])],
|
||||||
|
}, {
|
||||||
|
'name': 'Accounting 19%',
|
||||||
|
'accounting': True,
|
||||||
|
'account_parent': False,
|
||||||
|
'account_expense': acc_exp.id,
|
||||||
|
'account_revenue': acc_rev.id,
|
||||||
|
'taxes_parent': False,
|
||||||
|
'customer_taxes': [('add', [tax_19.id])],
|
||||||
|
'supplier_taxes': [('add', [tax_19.id])],
|
||||||
|
}, {
|
||||||
|
'name': 'Accounting 7%',
|
||||||
|
'accounting': True,
|
||||||
|
'account_parent': False,
|
||||||
|
'account_expense': acc_exp.id,
|
||||||
|
'account_revenue': acc_rev.id,
|
||||||
|
'taxes_parent': False,
|
||||||
|
'customer_taxes': [('add', [tax_7.id])],
|
||||||
|
'supplier_taxes': [('add', [tax_7.id])],
|
||||||
|
}])
|
||||||
|
self.assertEqual(p_cat.name, 'Accounting')
|
||||||
|
self.assertEqual(p_cat.accounting, True)
|
||||||
|
self.assertEqual(p_cat.account_parent, False)
|
||||||
|
self.assertEqual(p_cat.taxes_parent, False)
|
||||||
|
self.assertEqual(p_cat.account_expense.name, 'Main Expense')
|
||||||
|
self.assertEqual(p_cat.account_revenue.name, 'Main Revenue')
|
||||||
|
self.assertEqual(p_cat.customer_taxes[0].name, '20% VAT')
|
||||||
|
self.assertEqual(p_cat.supplier_taxes[0].name, '20% VAT')
|
||||||
|
return [p_cat, p_cat_19, tax_7]
|
||||||
|
|
||||||
|
@with_transaction()
|
||||||
|
def test_xmldoc_check_xml_read_facturx_extended(self):
|
||||||
|
""" add incoming-dcument in memory, read xml into 'parsed_data'
|
||||||
|
"""
|
||||||
|
pool = Pool()
|
||||||
|
IncDocument = pool.get('document.incoming')
|
||||||
|
|
||||||
|
with open(os.path.join(
|
||||||
|
os.path.split(__file__)[0],
|
||||||
|
'facturx-extended.xml'), 'rb') as fhdl:
|
||||||
|
xml_txt = fhdl.read()
|
||||||
|
|
||||||
|
incoming = IncDocument(data=xml_txt)
|
||||||
|
(xsdtype, funcname, xml_data) = incoming._facturx_detect_content()
|
||||||
|
self.assertEqual(xsdtype, 'Factur-X extended')
|
||||||
|
self.assertEqual(funcname, 'facturx_extended')
|
||||||
|
|
||||||
|
incoming._readxml_facturx_extended(xml_data)
|
||||||
|
self.assertEqual(incoming.parsed_data, parsed_data_facturx)
|
||||||
|
|
||||||
@with_transaction()
|
@with_transaction()
|
||||||
def test_xmldoc_import_facturx(self):
|
def test_xmldoc_import_facturx(self):
|
||||||
|
@ -296,6 +300,7 @@ class DocumentTestCase(object):
|
||||||
IncDocument = pool.get('document.incoming')
|
IncDocument = pool.get('document.incoming')
|
||||||
Configuration = pool.get('document.incoming.configuration')
|
Configuration = pool.get('document.incoming.configuration')
|
||||||
Party = pool.get('party.party')
|
Party = pool.get('party.party')
|
||||||
|
IrAttachment = pool.get('ir.attachment')
|
||||||
|
|
||||||
company = create_company('m-ds')
|
company = create_company('m-ds')
|
||||||
with set_company(company):
|
with set_company(company):
|
||||||
|
@ -397,4 +402,19 @@ class DocumentTestCase(object):
|
||||||
# run the usual call: process workers
|
# run the usual call: process workers
|
||||||
self.prep_incomingdoc_run_worker()
|
self.prep_incomingdoc_run_worker()
|
||||||
|
|
||||||
|
self.assertEqual(document.result.__name__, 'account.invoice')
|
||||||
|
self.assertEqual(document.result.reference, 'RE2024.01234')
|
||||||
|
# seller-party was already created by 'invoice.save()'
|
||||||
|
# a few lines above,
|
||||||
|
# the party-id in 'seller_party' means: dont create this party
|
||||||
|
parsed_ori = copy.deepcopy(parsed_data_facturx)
|
||||||
|
parsed_ori['seller_party']['party'] = invoice.party.id
|
||||||
|
self.assertEqual(document.parsed_data, parsed_ori)
|
||||||
|
|
||||||
|
attachment, = IrAttachment.search([
|
||||||
|
('resource.party', '=', invoice.party, 'account.invoice'),
|
||||||
|
('type', '=', 'data')])
|
||||||
|
self.assertEqual(attachment.data, document.data)
|
||||||
|
self.assertEqual(attachment.name, 'facturx-extended.xml')
|
||||||
|
|
||||||
# end DocumentTestCase
|
# end DocumentTestCase
|
||||||
|
|
Loading…
Reference in a new issue