Example #1
0
 def total_records(self):
     sp_ids = get_relevant_supply_point_ids(self.domain,
                                            self.active_location)
     product_ids = get_product_ids_for_program(
         self.domain, self.program_id) if self.program_id else None
     return get_total_records(self.domain, sp_ids, STOCK_SECTION_TYPE,
                              product_ids)
Example #2
0
    def get_prod_data(self):
        sp_ids = get_relevant_supply_point_ids(self.domain,
                                               self.active_location)
        product_ids = get_product_ids_for_program(
            self.domain, self.program_id) if self.program_id else None

        ledger_values = get_wrapped_ledger_values(
            domain=self.domain,
            case_ids=sp_ids,
            section_id=STOCK_SECTION_TYPE,
            entry_ids=product_ids,
            pagination=self.pagination,
        )
        product_grouping = {}
        for ledger_value in ledger_values:
            consumption_helper = get_consumption_helper_from_ledger_value(
                Domain.get_by_name(self.domain), ledger_value)
            status = consumption_helper.get_stock_category()
            if ledger_value.entry_id in product_grouping:
                product_grouping[ledger_value.entry_id][status] += 1
                product_grouping[ledger_value.entry_id]['facility_count'] += 1

            else:
                product_grouping[ledger_value.entry_id] = {
                    'entry_id': ledger_value.entry_id,
                    'stockout': 0,
                    'understock': 0,
                    'overstock': 0,
                    'adequate': 0,
                    'nodata': 0,
                    'facility_count': 1
                }
                product_grouping[ledger_value.entry_id][status] = 1

        product_name_map = get_product_id_name_mapping(self.domain)
        rows = [[
            product_name_map.get(product['entry_id'], product['entry_id']),
            product['facility_count'],
            100.0 * product['stockout'] / product['facility_count'],
            100.0 * product['understock'] / product['facility_count'],
            100.0 * product['adequate'] / product['facility_count'],
            100.0 * product['overstock'] / product['facility_count'],
            100.0 * product['nodata'] / product['facility_count'],
        ] for product in product_grouping.values()]

        return sorted(rows, key=lambda r: r[0].lower())
Example #3
0
    def get_prod_data(self):
        sp_ids = get_relevant_supply_point_ids(self.domain, self.active_location)
        product_ids = get_product_ids_for_program(self.domain, self.program_id) if self.program_id else None

        ledger_values = get_wrapped_ledger_values(
            domain=self.domain,
            case_ids=sp_ids,
            section_id=STOCK_SECTION_TYPE,
            entry_ids=product_ids,
        )
        product_grouping = {}
        for ledger_value in ledger_values:
            consumption_helper = get_consumption_helper_from_ledger_value(
                Domain.get_by_name(self.domain), ledger_value
            )
            status = consumption_helper.get_stock_category()
            if ledger_value.entry_id in product_grouping:
                product_grouping[ledger_value.entry_id][status] += 1
                product_grouping[ledger_value.entry_id]['facility_count'] += 1

            else:
                product_grouping[ledger_value.entry_id] = {
                    'entry_id': ledger_value.entry_id,
                    'stockout': 0,
                    'understock': 0,
                    'overstock': 0,
                    'adequate': 0,
                    'nodata': 0,
                    'facility_count': 1
                }
                product_grouping[ledger_value.entry_id][status] = 1

        product_name_map = get_product_id_name_mapping(self.domain)
        rows = [[
            product_name_map.get(product['entry_id'], product['entry_id']),
            product['facility_count'],
            100.0 * product['stockout'] / product['facility_count'],
            100.0 * product['understock'] / product['facility_count'],
            100.0 * product['adequate'] / product['facility_count'],
            100.0 * product['overstock'] / product['facility_count'],
            100.0 * product['nodata'] / product['facility_count'],
        ] for product in product_grouping.values()]

        return sorted(rows, key=lambda r: r[0].lower())
Example #4
0
 def product_ids(self):
     if self.program_id:
         return get_product_ids_for_program(self.domain, self.program_id)
Example #5
0
 def product_ids(self):
     if self.program_id:
         return get_product_ids_for_program(self.domain, self.program_id)