示例#1
0
    def get_data(start, end, venture, **kwargs):
        if not venture:
            return
        devices_ids = (
            DailyDevice.objects.filter(date__gte=start, date__lte=end, pricing_venture=venture)
            .values_list("pricing_device_id", flat=True)
            .distinct()
        )
        total_count = len(devices_ids)
        devices = Device.objects.filter(id__in=devices_ids)
        data = []
        for extracost in venture.get_extracost_details(start, end):
            row = [
                "{} (Extra Cost)".format(extracost.type.name),
                "",
                "",
                "{} - {}".format(extracost.start, extracost.end),
                "",
                currency(extracost.price),
                "",
                "",
                "",
                "",
            ]
            data.append(row)
        for usage in venture.get_daily_usages(start, end):
            row = ["", "", usage["name"], "", "", "", "", currency(usage["price"]), usage["count"]]
            data.append(row)
        for i, device in enumerate(devices):
            count, price, cost = venture.get_assets_count_price_cost(start, end, device_id=device.id)
            data.append(
                [
                    device.name,
                    "",
                    "",
                    device.sn,
                    device.barcode,
                    device.get_deprecated_status(start, end, venture),
                    currency(price),
                    currency(cost),
                    "",
                ]
            )
            for part in device.get_daily_parts(start, end):
                data.append(
                    [
                        "",
                        part["name"],
                        "",
                        "",
                        "",
                        part.get("deprecation", ""),
                        currency(part["price"]),
                        currency(part["cost"]),
                        "",
                    ]
                )

            for usage in device.get_daily_usages(start, end):
                data.append(["", "", usage["name"], "", "", "", "", currency(usage["price"]), usage["count"]])
            progress = (100 * i) // total_count
            yield progress, data
示例#2
0
    def get_data(start, end, venture, **kwargs):
        if not venture:
            return
        devices_ids = DailyDevice.objects.filter(
            date__gte=start,
            date__lte=end,
            pricing_venture=venture,
        ).values_list('pricing_device_id', flat=True).distinct()
        total_count = len(devices_ids)
        devices = Device.objects.filter(id__in=devices_ids)
        data = []
        for extracost in venture.get_extracost_details(start, end):
            row = [
                '{} (Extra Cost)'.format(extracost.type.name),
                '',
                '',
                '{} - {}'.format(extracost.start, extracost.end),
                '',
                currency(extracost.price),
                '',
                '',
                '',
                '',
            ]
            data.append(row)
        for usage in venture.get_daily_usages(start, end):
            row = [
                '',
                '',
                usage['name'],
                '',
                '',
                '',
                '',
                currency(usage['price']),
                usage['count'],
            ]
            data.append(row)
        for i, device in enumerate(devices):
            count, price, cost = venture.get_assets_count_price_cost(
                start,
                end,
                device_id=device.id,
            )
            data.append([
                device.name,
                '',
                '',
                device.sn,
                device.barcode,
                device.get_deprecated_status(start, end, venture),
                currency(price),
                currency(cost),
                '',
            ])
            for part in device.get_daily_parts(start, end):
                data.append([
                    '',
                    part['name'],
                    '',
                    '',
                    '',
                    part.get('deprecation', ''),
                    currency(part['price']),
                    currency(part['cost']),
                    '',
                ])

            for usage in device.get_daily_usages(start, end):
                data.append([
                    '',
                    '',
                    usage['name'],
                    '',
                    '',
                    '',
                    '',
                    currency(usage['price']),
                    usage['count'],
                ])
            progress = (100 * i) // total_count
            yield progress, data
示例#3
0
    def get_data(start, end, venture, **kwargs):
        '''
        Build and return list of lists contains full data for devices raport.
        Additional return a progress like a total count of rows in raport

        :param datetime.date start: Start date of the interval for the report
        :param datetime.date end: End date of the interval for the report
        :param class venture: Venture pricing model
        :returns tuple: progress and list of lists contains report data
        :rtype tuple:
        '''
        if not venture:
            return
        devices_ids = DailyDevice.objects.filter(
            date__gte=start,
            date__lte=end,
            pricing_venture=venture,
        ).values_list('pricing_device_id', flat=True).distinct()
        total_count = len(devices_ids)
        devices = Device.objects.filter(id__in=devices_ids)
        data = []
        for extracost in venture.get_extracost_details(start, end):
            row = [
                '{} (Extra Cost)'.format(extracost.type.name),
                '',
                '',
                '{} - {}'.format(extracost.start, extracost.end),
                '',
                currency(extracost.price),
                '',
                '',
                '',
            ]
            data.append(row)
        for usage in venture.get_daily_usages(start, end):
            row = [
                '',
                '',
                usage['name'],
                '',
                '',
                '',
                '',
                currency(usage['price']),
                usage['count'],
            ]
            data.append(row)
        for i, device in enumerate(devices):
            count, price, cost = venture.get_assets_count_price_cost(
                start,
                end,
                device_id=device.id,
            )
            data.append([
                device.name,
                '',
                '',
                device.sn,
                device.barcode,
                device.get_deprecated_status(start, end, venture),
                currency(price),
                currency(cost),
                '',
            ])

            for part in device.get_daily_parts(start, end):
                data.append([
                    '',
                    part['name'],
                    '',
                    '',
                    '',
                    part.get('deprecation', ''),
                    currency(part['price']),
                    currency(part['cost']),
                    '',
                ])

            for usage in device.get_daily_usages(start, end):
                data.append([
                    '',
                    '',
                    usage['name'],
                    '',
                    '',
                    '',
                    '',
                    currency(usage['price']),
                    usage['count'],
                ])
            progress = (100 * i) // total_count
            yield progress, data
示例#4
0
 def get_data(start, end, show_in_ralph=False, **kwargs):
     # 'show_in_ralph' == 'show only active' checkbox in gui
     ventures = Venture.objects.order_by('name')
     total_count = ventures.count() + 1  # additional step for post-process
     data = []
     totals = {}
     values = []
     for i, venture in enumerate(ventures):
         try:
             show_venture = ralph_venture.objects.get(
                 id=venture.venture_id,
             ).show_in_ralph
         except ralph_venture.DoesNotExist:
             show_venture = False
         if show_in_ralph and not show_venture:
             continue
         values_row = {}
         values.append(values_row)
         count, price, cost = venture.get_assets_count_price_cost(
             start, end,
         )
         path = '/'.join(
             v.name for v in venture.get_ancestors(include_self=True),
         )
         row = [
             venture.venture_id,
             path,
             show_venture,
             venture.department,
             venture.business_segment,
             venture.profit_center,
             count,
             currency(price),
             currency(cost),
         ]
         column = len(row)
         for usage_type in UsageType.objects.order_by('name'):
             count, price = venture.get_usages_count_price(
                 start,
                 end,
                 usage_type,
             )
             row.append(count)
             column += 1
             if usage_type.show_value_percentage:
                 row.append('')
                 totals[column] = totals.get(column, 0) + count
                 values_row[column] = count
                 column += 1
             if price is None:
                 row.append('NO PRICE')
             else:
                 row.append(currency(price))
             column += 1
             if usage_type.show_price_percentage:
                 row.append('')
                 totals[column] = totals.get(column, 0) + count
                 values_row[column] = price
                 column += 1
         for extra_cost_type in ExtraCostType.objects.order_by('name'):
             row.append(currency(venture.get_extra_costs(
                 start,
                 end,
                 extra_cost_type,
             )))
         progress = (100 * i) // total_count
         data.append(row)
         yield min(progress, 99), data
     for row, values_row in zip(data, values):
         for column, total in totals.iteritems():
             if total:
                 row[column] = '{:.2f}%'.format(
                     100 * values_row[column] / total,
                 )
     yield 100, data
 def get_data(start, end, show_in_ralph=False, **kwargs):
     ventures = Venture.objects.order_by('name')
     total_count = ventures.count() + 1  # additional step for post-process
     data = []
     totals = {}
     values = []
     for i, venture in enumerate(ventures):
         show_venture = ralph_venture.objects.get(
             id=venture.venture_id
         ).show_in_ralph
         if show_in_ralph and not show_venture:
             continue
         values_row = {}
         values.append(values_row)
         count, price, cost = venture.get_assets_count_price_cost(
             start, end,
         )
         path = '/'.join(
             v.name for v in venture.get_ancestors(include_self=True),
         )
         row = [
             venture.venture_id,
             path,
             show_in_ralph,
             venture.department,
             venture.business_segment,
             venture.profit_center,
             count,
             currency(price),
             currency(cost),
         ]
         column = len(row)
         for usage_type in UsageType.objects.order_by('name'):
             count, price = venture.get_usages_count_price(
                 start,
                 end,
                 usage_type,
             )
             row.append(count)
             column += 1
             if usage_type.show_value_percentage:
                 row.append('')
                 totals[column] = totals.get(column, 0) + count
                 values_row[column] = count
                 column += 1
             if price is None:
                 row.append('NO PRICE')
             else:
                 row.append(currency(price))
             column += 1
             if usage_type.show_price_percentage:
                 row.append('')
                 totals[column] = totals.get(column, 0) + count
                 values_row[column] = price
                 column += 1
         for extra_cost_type in ExtraCostType.objects.order_by('name'):
             row.append(currency(venture.get_extra_costs(
                 start,
                 end,
                 extra_cost_type,
             )))
         progress = (100 * i) // total_count
         data.append(row)
         yield min(progress, 99), data
     for row, values_row in zip(data, values):
         for column, total in totals.iteritems():
             if total:
                 row[column] = '{:.2f}%'.format(
                     100 * values_row[column] / total,
                 )
     yield 100, data
 def get_data(start, end, show_in_ralph=False, **kwargs):
     ventures = Venture.objects.root_nodes().order_by('name')
     total_count = ventures.count() + 1  # additional step for post-process
     data = []
     totals = {}
     values = []
     for i, venture in enumerate(ventures):
         show_venture = ralph_venture.objects.get(
             id=venture.venture_id
         ).show_in_ralph
         if show_in_ralph and not show_venture:
             continue
         values_row = {}
         values.append(values_row)
         count, price, cost = venture.get_assets_count_price_cost(
             start,
             end,
             descendants=True,
         )
         row = [
             venture.venture_id,
             venture.name,
             ralph_venture.objects.get(id=venture.venture_id).show_in_ralph,
             venture.department,
             venture.business_segment,
             venture.profit_center,
             count,
             currency(price),
             currency(cost),
         ]
         column = len(row)
         for usage_type in UsageType.objects.order_by('name'):
             count, price = venture.get_usages_count_price(
                 start,
                 end,
                 usage_type,
                 descendants=True,
             )
             row.append(count)
             column += 1
             if usage_type.show_value_percentage:
                 row.append('')
                 totals[column] = totals.get(column, 0) + count
                 values_row[column] = count
                 column += 1
             row.append(currency(price))
             column += 1
             if usage_type.show_price_percentage:
                 row.append('')
                 totals[column] = totals.get(column, 0) + price
                 values_row[column] = price
                 column += 1
         for extra_cost_type in ExtraCostType.objects.order_by('name'):
             row.append(currency(venture.get_extra_costs(
                 start,
                 end,
                 extra_cost_type,
                 descendants=True,
             )))
         progress = (100 * i) // total_count
         data.append(row)
         yield min(progress, 99), data
     for row, values_row in zip(data, values):
         for column, total in totals.iteritems():
             if total:
                 row[column] = '{:.2f}%'.format(
                     100 * values_row[column] / total,
                 )
     yield 100, data