Esempio n. 1
0
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)
Esempio n. 2
0
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)
Esempio n. 3
0
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)
Esempio n. 4
0
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)
Esempio n. 5
0
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)
Esempio n. 6
0
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)