def get_wrapped_ledger_values(domain, case_ids, section_id, entry_ids=None): # todo: figure out why this causes circular import from corehq.apps.reports.commtrack.util import StockLedgerValueWrapper query = LedgerES().domain(domain).section(section_id).case(case_ids) if entry_ids: query = query.entry(entry_ids) return [StockLedgerValueWrapper.wrap(row) for row in query.run().hits]
def get_aggregated_ledger_values(domain, case_ids, section_id, entry_ids=None): # todo: figure out why this causes circular import query = LedgerES().domain(domain).section(section_id).case(case_ids) if entry_ids: query = query.entry(entry_ids) terms = [AggregationTerm("entry_id", "entry_id")] return NestedTermAggregationsHelper( base_query=query, terms=terms, inner_most_aggregation=SumAggregation("balance", "balance") ).get_data()
def get_aggregated_ledger_values(domain, case_ids, section_id, entry_ids=None): # todo: figure out why this causes circular import query = LedgerES().domain(domain).section(section_id).case(case_ids) if entry_ids: query = query.entry(entry_ids) terms = [ AggregationTerm('entry_id', 'entry_id'), ] return NestedTermAggregationsHelper( base_query=query, terms=terms, inner_most_aggregation=SumAggregation('balance', 'balance'), ).get_data()
def products_with_ledgers(domain, case_ids, section_id, entry_ids=None): # returns entry ids/product ids that have associated ledgers query = LedgerES().domain(domain).section(section_id).case(case_ids) if entry_ids: query = query.entry(entry_ids) return set(query.values_list('entry_id', flat=True))
def get_total_records(domain, case_ids, section_id, entry_ids=None): query = LedgerES().domain(domain).section(section_id).case(case_ids) if entry_ids: query = query.entry(entry_ids) return query.count()