Esempio n. 1
0
def _timestamp_toxml(self, document, enclosing_tag):
  element = document.createElement(enclosing_tag)
  element.appendChild(gcxml.create_text_element(document, 'ts:date', self.date_string))
  if self.nanos:
    element.appendChild(gcxml.create_text_element(document, 'ts:ns', str(self.nanos)))

  return element
Esempio n. 2
0
def _commodity_toxml(self, document):
  element = document.createElement(self.position)

  if self.position == self.TOP_LEVEL:
    element.setAttribute('version', '2.0.0')

  element.appendChild(gcxml.create_text_element(document, 'cmdty:space', self.space))
  element.appendChild(gcxml.create_text_element(document, 'cmdty:id', self.commodity_id))

  if self.position == self.TOP_LEVEL:
    element.appendChild(gcxml.create_text_element(document, 'cmdty:get_quotes', self.get_quotes))
    element.appendChild(gcxml.create_text_element(document, 'cmdty:quote_source', self.quote_source))
    element.appendChild(gcxml.create_text_element(document, 'cmdty:quote_tz', self.quote_tz))

  return element
Esempio n. 3
0
def _slot_toxml(self, document):
  element = document.createElement('slot')
  element.appendChild(gcxml.create_text_element(document, 'slot:key', self.key))

  if self.slot_type == self.FRAME:
    value_element = document.createElement('slot:value')
    value_element.setAttribute('type', self.slot_type)
    for subslot in self.value:
      value_element.appendChild(subslot.toxml(document))
  else:
    value_element = gcxml.create_text_element(document, 'slot:value', self.value, 
        attributes=(('type', self.slot_type),))

  element.appendChild(value_element)
  return element
Esempio n. 4
0
def _transaction_toxml(self, document):
  element = document.createElement('gnc:transaction')
  element.setAttribute('version', '2.0.0')

  element.appendChild(gcxml.create_text_element(document, 'trn:id', self.transaction_id,
      attributes=(('type', 'guid'),)))
  element.appendChild(self.currency.toxml(document))
  element.appendChild(self.date_posted.toxml(document, 'trn:date-posted'))
  element.appendChild(self.date_entered.toxml(document, 'trn:date-entered'))
  element.appendChild(gcxml.create_text_element(document, 'trn:description', self.description))

  if self.slots:
    slots_element = document.createElement('trn:slots')
    for slot in self.slots:
      slots_element.appendChild(slot.toxml(document))
    element.appendChild(slots_element)

  splits_element = document.createElement('trn:splits')
  for split in self.splits:
    splits_element.appendChild(split.toxml(document))
  element.appendChild(splits_element)

  return element
Esempio n. 5
0
def _account_toxml(self, document):
  element = document.createElement('gnc:account')
  element.setAttribute('version', '2.0.0')

  element.appendChild(gcxml.create_text_element(document, 'act:name', self.name))
  element.appendChild(gcxml.create_text_element(document, 'act:id', self.account_id, 
      attributes=(('type', 'guid'),)))
  element.appendChild(gcxml.create_text_element(document, 'act:type', self.account_type))
  
  if self.commodity:
    element.appendChild(self.commodity.toxml(document))
    element.appendChild(gcxml.create_text_element(document, 'act:commodity-scu', self.commodity_scu))

  if self.slots:
    slots_element = document.createElement('act:slots')
    for slot in self.slots:
      slots_element.appendChild(slot.toxml(document))
    element.appendChild(slots_element)

  if self.parent_id:
    element.appendChild(gcxml.create_text_element(document, 'act:parent', self.parent_id,
        attributes=(('type', 'guid'),)))

  return element
Esempio n. 6
0
def _book_toxml(self, document):
  document_element = document.createElement('gnc-v2')
  for namespace in gcxml.XML_NAMESPACES:
    document_element.setAttributeNode(_create_namespace_attribute(document, namespace))
    
  document_element.appendChild(_create_countdata_element(document, 'book', 1))

  book_element = document.createElement('gnc:book')
  book_element.setAttribute('version', '2.0.0')
  book_element.appendChild(
      gcxml.create_text_element(document, 'book:id', self.book_id, (('type', 'guid'),)))
  book_element.appendChild(_create_countdata_element(document, 'account', len(self.accounts)))
  book_element.appendChild(
      _create_countdata_element(document, 'transaction', len(self.transactions)))

  for commodity in self.commodities:
    book_element.appendChild(commodity.toxml(document))
  for account in self.accounts:
    book_element.appendChild(account.toxml(document))
  for transaction in self.transactions:
    book_element.appendChild(transaction.toxml(document))

  document_element.appendChild(book_element)
  return document_element
Esempio n. 7
0
def _split_toxml(self, document):
  element = document.createElement('trn:split')

  element.appendChild(gcxml.create_text_element(document, 'split:id', self.split_id,
      attributes=(('type', 'guid'),)))

  if self.memo:
    element.appendChild(gcxml.create_text_element(document, 'split:memo', self.memo))

  element.appendChild(gcxml.create_text_element(document, 'split:reconciled-state',
      self.reconciled_state))
  
  if self.reconcile_date:
    element.appendChild(self.reconcile_date.toxml(document, 'split:reconcile-date'))

  element.appendChild(gcxml.create_text_element(document, 'split:value',
      gcxml.decimal_to_gnucash_string(self.value, 'value')))
  element.appendChild(gcxml.create_text_element(document, 'split:quantity',
      gcxml.decimal_to_gnucash_string(self.quantity, 'quantity')))
  element.appendChild(gcxml.create_text_element(document, 'split:account', self.account_id,
      attributes=(('type', 'guid'),)))

  return element