def rows(self):
        rows = {}
        if self.config['location_id']:
            supply_points = get_descendants(self.config['location_id'])
            products = self.unique_products(supply_points, all=True)
            code_name_map = {}
            for product in products:
                rows[product.code] = []
                code_name_map[product.code] = product.name

            enddate = self.config['enddate']
            startdate = self.config['startdate'] if 'custom_date' in self.config else enddate - timedelta(days=90)
            for d in get_second_week(startdate, enddate):
                txs = list(StockTransaction.objects.filter(
                    case_id__in=list(supply_points.values_list('supply_point_id', flat=True)),
                    sql_product__in=list(products),
                    report__date__range=[d['start_date'], d['end_date']],
                    report__domain=self.config['domain'],
                    type='stockonhand',
                    stock_on_hand=0
                ).values('sql_product__code').annotate(count=Count('case_id')))
                for product in products:
                    if not any([product.code == tx['sql_product__code'] for tx in txs]):
                        rows[product.code].append({'x': d['start_date'], 'y': 0})
                for tx in txs:
                    rows[tx['sql_product__code']].append(
                        {
                            'x': d['start_date'],
                            'y': tx['count'],
                            'name': code_name_map[tx['sql_product__code']]
                        }
                    )
        return rows
Example #2
0
    def rows(self):
        rows = {}
        if self.config['location_id']:
            supply_points = get_descendants(self.config['location_id'])
            products = self.unique_products(supply_points, all=True)
            code_name_map = {}
            for product in products:
                rows[product.code] = []
                code_name_map[product.code] = product.name

            enddate = self.config['enddate']
            startdate = self.config['startdate'] if 'custom_date' in self.config else enddate - timedelta(days=90)
            for d in get_second_week(startdate, enddate):
                txs = list(StockTransaction.objects.filter(
                    case_id__in=list(supply_points.values_list('supply_point_id', flat=True)),
                    sql_product__in=list(products),
                    report__date__range=[d['start_date'], d['end_date']],
                    report__domain=self.config['domain'],
                    type='stockonhand',
                    stock_on_hand=0
                ).values('sql_product__code').annotate(count=Count('case_id')))
                for product in products:
                    if not any([product.code == tx['sql_product__code'] for tx in txs]):
                        rows[product.code].append({'x': d['start_date'], 'y': 0})
                for tx in txs:
                    rows[tx['sql_product__code']].append(
                        {
                            'x': d['start_date'],
                            'y': tx['count'],
                            'name': code_name_map[tx['sql_product__code']]
                        }
                    )
        return rows
Example #3
0
    def rendered_content(self):
        location = SQLLocation.objects.get(
            location_id=self.config['location_id'])
        if location.location_type.administrative:
            locations = get_descendants(self.config['location_id'])
            products = self.unique_products(locations, all=True)
        else:
            products = location.products
        programs = {
            program.get_id: program.name
            for program in Program.by_domain(self.domain)
        }
        headers = []
        if 'report_type' in self.config:
            from custom.ewsghana.reports.specific_reports.stock_status_report import MonthOfStockProduct
            headers = [
                h.html for h in MonthOfStockProduct(self.config).headers
            ]

        result = {}
        for idx, product in enumerate(products, start=1):
            program = programs[product.program_id]
            product_dict = {
                'name':
                product.name,
                'code':
                product.code,
                'idx':
                idx if not headers else
                headers.index(product.code) if product.code in headers else -1,
                'checked':
                self.config['program'] is None
                or self.config['program'] == product.program_id
            }
            if program in result:
                result[program]['product_list'].append(product_dict)
                if result[program]['all'] and not product_dict['checked']:
                    result[program]['all'] = False
            else:
                result[program] = {
                    'product_list': [product_dict],
                    'all': product_dict['checked']
                }

        for _, product_dict in result.iteritems():
            product_dict['product_list'].sort(key=lambda prd: prd['name'])
        return render_to_string(
            'ewsghana/partials/product_selection_pane.html', {
                'products_by_program':
                result,
                'is_rendered_as_email':
                self.config.get('is_rendered_as_email', False),
                'hide_columns':
                self.hide_columns
            })
    def rows(self):
        rows = []
        if self.config['location_id']:
            locations = get_descendants(self.config['location_id'])
            unique_products = self.unique_products(locations, all=True).order_by('code')

            for product in unique_products:
                with_stock = self.config['with_stock'].get(product.product_id, 0)
                without_stock = self.config['without_stock'].get(product.product_id, 0)
                without_data = self.config['all'] - with_stock - without_stock
                rows.append({"product_code": product.code,
                             "product_name": product.name,
                             "total": self.config['all'],
                             "with_stock": with_stock,
                             "without_stock": without_stock,
                             "without_data": without_data})
        return rows
Example #5
0
    def rows(self):
        rows = []
        if self.config['location_id']:
            locations = get_descendants(self.config['location_id'])
            unique_products = self.unique_products(locations, all=True).order_by('code')

            for product in unique_products:
                with_stock = self.config['with_stock'].get(product.product_id, 0)
                without_stock = self.config['without_stock'].get(product.product_id, 0)
                without_data = self.config['all'] - with_stock - without_stock
                rows.append({"product_code": product.code,
                             "product_name": product.name,
                             "total": self.config['all'],
                             "with_stock": with_stock,
                             "without_stock": without_stock,
                             "without_data": without_data})
        return rows
Example #6
0
    def rendered_content(self):
        location = SQLLocation.objects.get(location_id=self.config['location_id'])
        if location.location_type.administrative:
            locations = get_descendants(self.config['location_id'])
            products = self.unique_products(locations, all=True)
        else:
            products = location.products
        programs = {program.get_id: program.name for program in Program.by_domain(self.domain)}
        headers = []
        if 'report_type' in self.config:
            from custom.ewsghana.reports.specific_reports.stock_status_report import MonthOfStockProduct
            headers = [h.html for h in MonthOfStockProduct(self.config).headers]

        result = {}
        for idx, product in enumerate(products, start=1):
            program = programs[product.program_id]
            product_dict = {
                'name': product.name,
                'code': product.code,
                'idx': idx if not headers else headers.index(product.code) if product.code in headers else -1,
                'checked': self.config['program'] is None or self.config['program'] == product.program_id
            }
            if program in result:
                result[program]['product_list'].append(product_dict)
                if result[program]['all'] and not product_dict['checked']:
                    result[program]['all'] = False
            else:
                result[program] = {
                    'product_list': [product_dict],
                    'all': product_dict['checked']
                }

        for _, product_dict in result.iteritems():
            product_dict['product_list'].sort(key=lambda prd: prd['name'])
        return render_to_string('ewsghana/partials/product_selection_pane.html', {
            'products_by_program': result,
            'is_rendered_as_email': self.config.get('is_rendered_as_email', False),
            'hide_columns': self.hide_columns
        })
Example #7
0
 def get_locations(self, loc_id, domain):
     return [loc.supply_point_id for loc in get_descendants(loc_id)]
Example #8
0
 def get_locations(self, loc_id, domain):
     return get_descendants(loc_id)
Example #9
0
 def get_locations(self, loc_id, domain):
     return [loc.supply_point_id for loc in get_descendants(loc_id)]
Example #10
0
 def get_locations(self, loc_id, domain):
     return get_descendants(loc_id)