コード例 #1
0
ファイル: gcparse.py プロジェクト: timwswanson/tws-gnucash
def _timestamp_fromxml(cls, element):
    subelements = gcxml.create_subelement_map(element)

    date_string = gcxml.get_element_text(subelements["ts:date"])
    if "ts:ns" in subelements:
        nanos = gcxml.get_element_text(subelements["ts:ns"])
    else:
        nanos = None

    return cls.FromDateString(date_string, nanos=nanos)
コード例 #2
0
ファイル: gcparse.py プロジェクト: timwswanson/tws-gnucash
def _slot_fromxml(cls, element):
    subelements = gcxml.create_subelement_map(element)
    key = gcxml.get_element_text(subelements["slot:key"])

    value_element = subelements["slot:value"]
    slot_type = value_element.getAttribute("type")

    if slot_type == cls.FRAME:
        value = gcxml.apply_to_children(cls.FromXml, value_element)
    else:
        value = gcxml.get_element_text(value_element)

    return cls(key, value, slot_type)
コード例 #3
0
ファイル: gcparse.py プロジェクト: timwswanson/tws-gnucash
def _transaction_fromxml(cls, element):
    subelements = gcxml.create_subelement_map(element)
    transaction_id = gcxml.get_element_text(subelements["trn:id"])
    currency = gcdomain.Commodity.FromXml(subelements["trn:currency"])
    date_posted = gcdomain.Timestamp.FromXml(subelements["trn:date-posted"])
    date_entered = gcdomain.Timestamp.FromXml(subelements["trn:date-entered"])
    description = gcxml.get_element_text(subelements["trn:description"])

    if "trn:slots" in subelements:
        slots = gcxml.apply_to_children(gcdomain.Slot.FromXml, subelements["trn:slots"])
    else:
        slots = []

    splits = gcxml.apply_to_children(gcdomain.Split.FromXml, subelements["trn:splits"])

    return cls(transaction_id, currency, date_posted, date_entered, description, slots, splits)
コード例 #4
0
ファイル: gcparse.py プロジェクト: timwswanson/tws-gnucash
def _commodity_fromxml(cls, element):
    position = element.tagName

    subelements = gcxml.create_subelement_map(element)
    space = gcxml.get_element_text(subelements["cmdty:space"])
    commodity_id = gcxml.get_element_text(subelements["cmdty:id"])

    if position == cls.TOP_LEVEL:
        get_quotes = gcxml.get_element_text(subelements["cmdty:get_quotes"])
        quote_source = gcxml.get_element_text(subelements["cmdty:quote_source"])
        quote_tz = gcxml.get_element_text(subelements["cmdty:quote_tz"])
    else:
        get_quotes = None
        quote_source = None
        quote_tz = None

    return cls(position, space, commodity_id, get_quotes, quote_source, quote_tz)
コード例 #5
0
ファイル: gcparse.py プロジェクト: timwswanson/tws-gnucash
def _account_fromxml(cls, element):
    subelements = gcxml.create_subelement_map(element)
    name = gcxml.get_element_text(subelements["act:name"])
    account_id = gcxml.get_element_text(subelements["act:id"])
    account_type = gcxml.get_element_text(subelements["act:type"])

    if "act:commodity" in subelements:
        commodity = gcdomain.Commodity.FromXml(subelements["act:commodity"])
        commodity_scu = gcxml.get_element_text(subelements["act:commodity-scu"])
    else:
        commodity = None
        commodity_scu = None

    if "act:slots" in subelements:
        slots = gcxml.apply_to_children(gcdomain.Slot.FromXml, subelements["act:slots"])
    else:
        slots = []

    if "act:parent" in subelements:
        parent_id = gcxml.get_element_text(subelements["act:parent"])
    else:
        parent_id = None

    return cls(name, account_id, account_type, commodity, commodity_scu, slots, parent_id)
コード例 #6
0
ファイル: gcparse.py プロジェクト: timwswanson/tws-gnucash
def _book_fromxml(cls, document):
    book_element = document.documentElement.getElementsByTagName("gnc:book")[0]
    book_id = None
    commodities = []
    accounts = []
    transactions = []

    for subelement in [e for e in book_element.childNodes if e.nodeType == e.ELEMENT_NODE]:
        if subelement.tagName == "book:id":
            book_id = gcxml.get_element_text(subelement)
        elif subelement.tagName == "gnc:commodity":
            commodities.append(gcdomain.Commodity.FromXml(subelement))
        elif subelement.tagName == "gnc:account":
            accounts.append(gcdomain.Account.FromXml(subelement))
        elif subelement.tagName == "gnc:transaction":
            transactions.append(gcdomain.Transaction.FromXml(subelement))

    return cls(book_id, commodities, accounts, transactions)
コード例 #7
0
ファイル: gcparse.py プロジェクト: timwswanson/tws-gnucash
def _split_fromxml(cls, element):
    subelements = gcxml.create_subelement_map(element)
    split_id = gcxml.get_element_text(subelements["split:id"])
    reconciled_state = gcxml.get_element_text(subelements["split:reconciled-state"])
    value = gcxml.gnucash_string_to_decimal(gcxml.get_element_text(subelements["split:value"]))
    quantity = gcxml.gnucash_string_to_decimal(gcxml.get_element_text(subelements["split:quantity"]))
    account_id = gcxml.get_element_text(subelements["split:account"])

    if "split:memo" in subelements:
        memo = gcxml.get_element_text(subelements["split:memo"])
    else:
        memo = None

    if "split:reconcile-date" in subelements:
        reconcile_date = gcdomain.Timestamp.FromXml(subelements["split:reconcile-date"])
    else:
        reconcile_date = None

    return cls(split_id, memo, reconciled_state, reconcile_date, value, quantity, account_id)