read parties of supplier+company from xml + tests
This commit is contained in:
parent
8a48fb7236
commit
0a4e933188
6 changed files with 338 additions and 13 deletions
|
@ -7,7 +7,34 @@ 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):
|
||||
|
@ -26,16 +53,38 @@ class DocumentTestCase(object):
|
|||
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],
|
||||
|
@ -52,6 +101,36 @@ class DocumentTestCase(object):
|
|||
b'<?xml version="1.0" encoding="UTF-8"?>\n' +
|
||||
b'<rsm:CrossIndustryInvoice xmlns'))
|
||||
|
||||
# no supplier-party in db
|
||||
self.assertEqual(
|
||||
Party.search_count([('name', '=', 'Name of the Supplier')]),
|
||||
0)
|
||||
|
||||
# check fail if missing supplier
|
||||
config.create_supplier = False
|
||||
config.save()
|
||||
self.assertRaisesRegex(
|
||||
UserError,
|
||||
"Supplier party 'Name of the Supplier, 12345, " +
|
||||
"Street of Supplier No 1, Berlin' not found. " +
|
||||
"Auto-creation is currently turned off.",
|
||||
document._process_supplier_invoice)
|
||||
|
||||
config.create_supplier = True
|
||||
config.accept_other_company = False
|
||||
config.save()
|
||||
|
||||
# check fail if invoice is not for our company
|
||||
self.assertRaisesRegex(
|
||||
UserError,
|
||||
"The buyer party 'Our Company, 23456, Address Line 1; " +
|
||||
"Address Line 2, Potsdam' differs from the corporate party.",
|
||||
document._process_supplier_invoice)
|
||||
|
||||
config.create_supplier = True
|
||||
config.accept_other_company = True
|
||||
config.save()
|
||||
|
||||
invoice = document._process_supplier_invoice()
|
||||
print('\n## invoice:', (invoice,))
|
||||
self.assertEqual(invoice.type, 'in')
|
||||
|
@ -64,6 +143,13 @@ class DocumentTestCase(object):
|
|||
invoice.comment,
|
||||
'Code=1, Some notes to the customer.\n' +
|
||||
'Code=22, Subject=42, Goes to field comment.')
|
||||
self.assertEqual(invoice.party.rec_name, 'Name of the Supplier')
|
||||
self.assertEqual(invoice.account.rec_name, 'Main Payable')
|
||||
|
||||
# now we have the supplier-party
|
||||
self.assertEqual(
|
||||
Party.search_count([('name', '=', 'Name of the Supplier')]),
|
||||
1)
|
||||
invoice.save()
|
||||
|
||||
print('\n## invoice:', invoice)
|
||||
|
|
|
@ -54,19 +54,19 @@
|
|||
</ram:IncludedSupplyChainTradeLineItem>
|
||||
<ram:ApplicableHeaderTradeAgreement>
|
||||
<ram:SellerTradeParty>
|
||||
<ram:Name>Name of the Comany</ram:Name>
|
||||
<ram:Name>Name of the Supplier</ram:Name>
|
||||
<ram:SpecifiedLegalOrganization>
|
||||
</ram:SpecifiedLegalOrganization>
|
||||
<ram:PostalTradeAddress>
|
||||
<ram:PostcodeCode>12345</ram:PostcodeCode>
|
||||
<ram:LineOne>Street of Company No 1</ram:LineOne>
|
||||
<ram:LineOne>Street of Supplier No 1</ram:LineOne>
|
||||
<ram:CityName>Berlin</ram:CityName>
|
||||
<ram:CountryID>DE</ram:CountryID>
|
||||
<ram:CountrySubDivisionName>Berlin</ram:CountrySubDivisionName>
|
||||
</ram:PostalTradeAddress>
|
||||
</ram:SellerTradeParty>
|
||||
<ram:BuyerTradeParty>
|
||||
<ram:Name>Customer Company</ram:Name>
|
||||
<ram:Name>Our Company</ram:Name>
|
||||
<ram:SpecifiedLegalOrganization>
|
||||
</ram:SpecifiedLegalOrganization>
|
||||
<ram:PostalTradeAddress>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue