se refleja el orden de los atributos del modelo en el xml
FossilOrigin-Name: 5ff5ebc397a11977916b7008ab4d5104a375290a5c5d0356098b69242378f1f8
This commit is contained in:
		| @@ -22,6 +22,7 @@ class ModelBase(object, metaclass=ModelMeta): | |||||||
|         obj._text = "" |         obj._text = "" | ||||||
|         obj._namespace_prefix = None |         obj._namespace_prefix = None | ||||||
|         obj._on_change_fields = defaultdict(list) |         obj._on_change_fields = defaultdict(list) | ||||||
|  |         obj._order_fields = [] | ||||||
|          |          | ||||||
|         def on_change_fields_for_function(): |         def on_change_fields_for_function(): | ||||||
|             # se recorre arbol buscando el primero |             # se recorre arbol buscando el primero | ||||||
| @@ -38,6 +39,8 @@ class ModelBase(object, metaclass=ModelMeta): | |||||||
|         # forzamos registros de campos al modelo |         # forzamos registros de campos al modelo | ||||||
|         # al instanciar |         # al instanciar | ||||||
|         for (key, v) in type(obj).__dict__.items(): |         for (key, v) in type(obj).__dict__.items(): | ||||||
|  |             if isinstance(v, fields.Field): | ||||||
|  |                 obj._order_fields.append(key) | ||||||
|  |  | ||||||
|             if isinstance(v, fields.Attribute) or isinstance(v, fields.Many2One) or isinstance(v, fields.Function): |             if isinstance(v, fields.Attribute) or isinstance(v, fields.Many2One) or isinstance(v, fields.Function): | ||||||
|                 if hasattr(v, 'default') and v.default is not None: |                 if hasattr(v, 'default') and v.default is not None: | ||||||
| @@ -98,7 +101,17 @@ class ModelBase(object, metaclass=ModelMeta): | |||||||
|  |  | ||||||
|         content = "" |         content = "" | ||||||
|  |  | ||||||
|         for value in self._fields.values(): |         ordered_fields = {} | ||||||
|  |         for name in self._order_fields: | ||||||
|  |             if name in self._fields: | ||||||
|  |                 ordered_fields[name] = True | ||||||
|  |             else: | ||||||
|  |                 for key in self._fields.keys(): | ||||||
|  |                     if key.startswith(name): | ||||||
|  |                         ordered_fields[key] = True | ||||||
|  |  | ||||||
|  |         for name in ordered_fields.keys(): | ||||||
|  |             value = self._fields[name] | ||||||
|             if hasattr(value, 'to_xml'): |             if hasattr(value, 'to_xml'): | ||||||
|                 content += value.to_xml() |                 content += value.to_xml() | ||||||
|             elif isinstance(value, str): |             elif isinstance(value, str): | ||||||
|   | |||||||
| @@ -21,10 +21,8 @@ def test_simple_invoice(): | |||||||
|  |  | ||||||
|     line = invoice.lines.create() |     line = invoice.lines.create() | ||||||
|     line.quantity = form.Quantity(1, '94') |     line.quantity = form.Quantity(1, '94') | ||||||
|  |     line.price = form.Amount(5_000) | ||||||
|     subtotal = line.taxtotal.subtotals.create() |     subtotal = line.taxtotal.subtotals.create() | ||||||
|     subtotal.percent = 19.0 |     subtotal.percent = 19.0 | ||||||
|     # TODO(bit4bit) el orden de los elementos |  | ||||||
|     # en el xml lo debe determinar la declaracion en los modelos |  | ||||||
|     line.price = form.Amount(5_000) |  | ||||||
|  |  | ||||||
|     assert '<Invoice><ID>323200000129</ID><IssueDate>2019-01-16T10:53:10-05:00</IssueDate><IssueTime>10:5310-05:00</IssueTime><AccountingSupplierParty><Party><ID>700085371</ID></Party></AccountingSupplierParty><AccountingCustomerParty><Party><ID>800199436</ID></Party></AccountingCustomerParty><InvoiceLine><InvoiceQuantity unitCode="NAR">1.0</InvoiceQuantity><TaxTotal><TaxSubTotal><TaxCategory><Percent>19.0</Percent><TaxScheme><ID>01</ID><Name>IVA</Name></TaxScheme></TaxCategory></TaxSubTotal></TaxTotal><Price><PriceAmount currencyID="COP">5000.0</PriceAmount></Price></InvoiceLine></Invoice>' == invoice.to_xml() |     assert '<Invoice><ID>323200000129</ID><IssueDate>2019-01-16T10:53:10-05:00</IssueDate><IssueTime>10:5310-05:00</IssueTime><AccountingSupplierParty><Party><ID>700085371</ID></Party></AccountingSupplierParty><AccountingCustomerParty><Party><ID>800199436</ID></Party></AccountingCustomerParty><InvoiceLine><InvoiceQuantity unitCode="NAR">1.0</InvoiceQuantity><TaxTotal><TaxSubTotal><TaxCategory><Percent>19.0</Percent><TaxScheme><ID>01</ID><Name>IVA</Name></TaxScheme></TaxCategory></TaxSubTotal></TaxTotal><Price><PriceAmount currencyID="COP">5000.0</PriceAmount></Price></InvoiceLine></Invoice>' == invoice.to_xml() | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user