(xform)
Given an instance of an AbstractXFormInstance, extract the ledger actions and convert
    them to StockReportHelper objects.
Given an instance of an AbstractXFormInstance, extract the ledger actions and convert
    them to StockReportHelper objects.
Given an instance of an AbstractXFormInstance extract the ledger actions and convert them to StockReportHelper objects .
def get_all_stock_report_helpers_from_form(xform):
    """
    Given an instance of an AbstractXFormInstance, extract the ledger actions and convert
    them to StockReportHelper objects.
    """
    form_xml = xform.get_xml_element()
    commtrack_node_names = ('{%s}balance' % COMMTRACK_REPORT_XMLNS,
                            '{%s}transfer' % COMMTRACK_REPORT_XMLNS)

    def _extract_ledger_nodes_from_xml(node):
        """
        Goes through a parsed XML document and recursively pulls out any ledger XML blocks.
        """
        for child in node:
            if child.tag in commtrack_node_names:
                yield child
            else:
                for e in _extract_ledger_nodes_from_xml(child):
                    yield e

    for elem in _extract_ledger_nodes_from_xml(form_xml):
        report_type, ledger_json = convert_xml_to_json(elem, last_xmlns=COMMTRACK_REPORT_XMLNS)
        if ledger_json.get('@date'):
            try:
                ledger_json['@date'] = adjust_text_to_datetime(ledger_json['@date'])
            except iso8601.ParseError:
                pass
        yield _ledger_json_to_stock_report_helper(xform, report_type, ledger_json)
def get_all_stock_report_helpers_from_form ( xform ) : form_xml = xform . get_xml_element ( ) commtrack_node_names = ( '{%s}balance' % COMMTRACK_REPORT_XMLNS , '{%s}transfer' % COMMTRACK_REPORT_XMLNS ) def _extract_ledger_nodes_from_xml ( node ) : """
        Goes through a parsed XML document and recursively pulls out any ledger XML blocks.
        """ for child in node : if child . tag in commtrack_node_names : yield child else : for e in _extract_ledger_nodes_from_xml ( child ) : yield e for elem in _extract_ledger_nodes_from_xml ( form_xml ) : report_type , ledger_json = convert_xml_to_json ( elem , last_xmlns = COMMTRACK_REPORT_XMLNS ) if ledger_json . get ( '@date' ) : try : ledger_json [ '@date' ] = adjust_text_to_datetime ( ledger_json [ '@date' ] ) except iso8601 . ParseError : pass yield _ledger_json_to_stock_report_helper ( xform , report_type , ledger_json )