dont write to immutable-dict
This commit is contained in:
parent
0d31e60772
commit
6b32c610f5
2 changed files with 46 additions and 27 deletions
|
@ -14,7 +14,7 @@ from trytond.modules.company.tests import create_company, set_company
|
|||
from trytond.modules.account.tests import create_chart, get_fiscalyear
|
||||
|
||||
|
||||
parsed_data_facturx = {
|
||||
parsed_data_facturx_extended = {
|
||||
'invoice_number': 'RE2024.01234',
|
||||
'invoice_date': date(2024, 6, 17),
|
||||
'note_list': [{
|
||||
|
@ -44,7 +44,7 @@ parsed_data_facturx = {
|
|||
'name': 'Name of Product 1',
|
||||
'description': 'Description of Product 1',
|
||||
'unit_net_price': {'amount': Decimal('1350.00')},
|
||||
'quantity': {'billed': Decimal('1.0')},
|
||||
'quantity': {'billed': Decimal('1.0'), 'unit_code': 'KGM'},
|
||||
'taxes': [{
|
||||
'type': 'VAT',
|
||||
'category_code': 'S',
|
||||
|
@ -76,7 +76,7 @@ parsed_data_facturx = {
|
|||
'code': '123',
|
||||
'description': 'Kilogram',
|
||||
'uom': 'kg',
|
||||
'value': '23'}],
|
||||
'value': Decimal('123.0')}],
|
||||
'classification': [{
|
||||
'code': '3c', 'name': 'product-class 1'}],
|
||||
'serialno': [{'lot': '22', 'serial': '1234'}],
|
||||
|
@ -96,6 +96,7 @@ parsed_data_facturx = {
|
|||
'basequantity': Decimal('1.0')},
|
||||
'quantity': {
|
||||
'billed': Decimal('1.5'),
|
||||
'unit_code': 'KGM',
|
||||
'package': Decimal('1.5')},
|
||||
'taxes': [{
|
||||
'type': 'VAT',
|
||||
|
@ -107,7 +108,7 @@ parsed_data_facturx = {
|
|||
'name': 'Name of Product 3',
|
||||
'description': 'Description of Product 3',
|
||||
'unit_net_price': {'amount': Decimal('150.00')},
|
||||
'quantity': {'billed': Decimal('2.0')},
|
||||
'quantity': {'billed': Decimal('2.0'), 'unit_code': 'MTR'},
|
||||
'taxes': [{
|
||||
'type': 'VAT',
|
||||
'category_code': 'S',
|
||||
|
@ -184,6 +185,20 @@ def set_invoice_sequences(fiscalyear):
|
|||
class DocumentTestCase(object):
|
||||
""" check import of xml + pdf files
|
||||
"""
|
||||
def prep_sorted_dict(self, data):
|
||||
""" sort dict by keys,
|
||||
konvert tuple to list to revert changes by self.parsed_data
|
||||
|
||||
Args:
|
||||
data (dict): dict-data
|
||||
"""
|
||||
return {
|
||||
k: (
|
||||
self.prep_sorted_dict(v) if isinstance(v, dict)
|
||||
else list(v) if isinstance(v, tuple)
|
||||
else v)
|
||||
for k, v in sorted(data.items(), key=lambda item: item[0])}
|
||||
|
||||
def prep_incomingdoc_run_worker(self):
|
||||
""" run tasks from queue
|
||||
"""
|
||||
|
@ -290,10 +305,10 @@ class DocumentTestCase(object):
|
|||
self.assertEqual(funcname, 'facturx_extended')
|
||||
|
||||
incoming._readxml_facturx_extended(xml_data)
|
||||
self.assertEqual(incoming.parsed_data, parsed_data_facturx)
|
||||
self.assertEqual(incoming.parsed_data, parsed_data_facturx_extended)
|
||||
|
||||
@with_transaction()
|
||||
def test_xmldoc_import_facturx(self):
|
||||
def test_xmldoc_import_facturx_extended(self):
|
||||
""" create incoming-document, load xml, detect type
|
||||
"""
|
||||
pool = Pool()
|
||||
|
@ -371,7 +386,8 @@ class DocumentTestCase(object):
|
|||
# check target of incoming invoice number
|
||||
invoice = document._process_supplier_invoice()
|
||||
self.assertEqual(invoice.number, 'RE2024.01234')
|
||||
self.assertTrue(not hasattr(invoice, 'reference'))
|
||||
self.assertEqual(document.xsd_type, 'Factur-X extended')
|
||||
self.assertEqual(invoice.reference, None)
|
||||
|
||||
config.number_target = 'reference'
|
||||
config.save()
|
||||
|
@ -379,7 +395,7 @@ class DocumentTestCase(object):
|
|||
invoice = document._process_supplier_invoice()
|
||||
self.assertEqual(invoice.type, 'in')
|
||||
self.assertEqual(invoice.reference, 'RE2024.01234')
|
||||
self.assertTrue(not hasattr(invoice, 'number'))
|
||||
self.assertEqual(invoice.number, None)
|
||||
self.assertEqual(invoice.invoice_date, date(2024, 6, 17))
|
||||
self.assertEqual(invoice.currency.name, 'usd')
|
||||
self.assertEqual(invoice.company.rec_name, 'm-ds')
|
||||
|
@ -407,9 +423,11 @@ class DocumentTestCase(object):
|
|||
# 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 = copy.deepcopy(parsed_data_facturx_extended)
|
||||
parsed_ori['seller_party']['party'] = invoice.party.id
|
||||
self.assertEqual(document.parsed_data, parsed_ori)
|
||||
self.assertEqual(
|
||||
self.prep_sorted_dict(document.parsed_data),
|
||||
self.prep_sorted_dict(parsed_ori))
|
||||
|
||||
attachment, = IrAttachment.search([
|
||||
('resource.party', '=', invoice.party, 'account.invoice'),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue