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
    def rows(self):
        rows = {}
        if self.config["location_id"]:
            supply_points = get_supply_points(self.config["location_id"], self.config["domain"])
            products = self.unique_products(supply_points)
            for product in products:
                rows[product.code] = []

            for d in get_second_week(self.config["startdate"], self.config["enddate"]):
                for product in products:
                    st = StockTransaction.objects.filter(
                        case_id__in=supply_points.values_list("supply_point_id", flat=True),
                        sql_product=product,
                        report__date__range=[d["start_date"], d["end_date"]],
                        type="stockonhand",
                        stock_on_hand=0,
                    ).count()

                    rows[product.code].append({"x": d["start_date"], "y": st})
        return rows
    def rows(self):
        rows = {}
        if self.config['location_id']:
            supply_points = get_supply_points(self.config['location_id'], self.config['domain'])
            products = self.unique_products(supply_points, all=True)
            for product in products:
                rows[product.code] = []

            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):
                for product in products:
                    st = StockTransaction.objects.filter(
                        case_id__in=supply_points.values_list('supply_point_id', flat=True),
                        sql_product=product,
                        report__date__range=[d['start_date'], d['end_date']],
                        type='stockonhand',
                        stock_on_hand=0).count()

                    rows[product.code].append({'x': d['start_date'], 'y': st})
        return rows