예제 #1
0
class GroupByCharFieldPlusTimeSeries(ReportGenerator):
    report_model = SalesWithFlag
    date_field = 'doc_date'
    group_by = 'flag'
    columns = ['flag', SlickReportField.create(Sum, 'quantity')]

    time_series_pattern = 'monthly'
    time_series_columns = [SlickReportField.create(Sum, 'quantity')]
예제 #2
0
    def test_group_by_and_foreign_key_field(self):
        report = ReportGenerator(
            report_model=SimpleSales,
            group_by='client',
            columns=[
                'name', 'contact_id', 'contact__address',
                SlickReportField.create(Sum, 'value'), '__total__'
            ],
            # time_series_pattern='monthly',
            date_field='doc_date',
            # time_series_columns=['__debit__', '__credit__', '__balance__', '__total__']
        )

        self.assertTrue(report._report_fields_dependencies)
        data = report.get_report_data()
        # import pdb;
        # pdb.set_trace()
        self.assertNotEqual(data, [])
        self.assertEqual(data[0]['name'], 'Client 1')
        self.assertEqual(data[1]['name'], 'Client 2')
        self.assertEqual(data[2]['name'], 'Client 3')

        self.assertEqual(data[0]['contact_id'], 1)
        self.assertEqual(data[1]['contact_id'], 2)
        self.assertEqual(data[2]['contact_id'], 3)

        self.assertEqual(data[0]['sum__value'], 300)

        self.assertEqual(Client.objects.get(pk=1).contact.address, 'Street 1')
        self.assertEqual(data[0]['contact__address'], 'Street 1')
        self.assertEqual(data[1]['contact__address'], 'Street 2')
        self.assertEqual(data[2]['contact__address'], 'Street 3')
예제 #3
0
class SimpleListReport(SlickReportView):
    report_model = Transaction
    report_title = 'Report'
    date_field = 'date'
    template_name = 'app/report/report_select.html'

    group_by = 'category__name'
    columns = [
        'category__name',
        SlickReportField.create(Sum,
                                'value',
                                name='value__sum',
                                verbose_name='Price'),
    ]

    # crosstab_model = 'client'
    # crosstab_columns = [SlickReportField.create(Sum, 'value', name='value__sum', verbose_name=_('Sales'))]
    # crosstab_compute_reminder = True  # if False the "Reminder" Column will not be computed

    chart_settings = [
        {
            'type': 'pie',
            'data_source': ['value__sum'],
            'plot_total': True,  # Plot total works here too
            'title_source': ['category__name'],
            'title': 'Per categories pie',
        },
        {
            'type': 'bar',
            'data_source': ['value__sum'],
            'title_source': ['category__name'],
            'title': 'Per categories bar',
        },
    ]
예제 #4
0
class CrosstabOnClient(GenericGenerator):
    group_by = 'product'
    columns = ['name', '__total_quantity__']
    crosstab_model = 'client'
    # crosstab_columns = ['__total_quantity__']
    crosstab_columns = [
        SlickReportField.create(Sum,
                                'quantity',
                                name='value__sum',
                                verbose_name=_('Sales'))
    ]
예제 #5
0
class TaxSales(SlickReportView):
    # report_model = SimpleSales
    queryset = ComplexSales.objects.all()
    date_field = 'doc_date'
    group_by = 'tax__name'
    columns = ['tax__name', SlickReportField.create(Count, 'tax', name='tax__count', verbose_name=_('Sales'))]
    chart_settings = [
        {
            'type': 'pie',
            'date_source': 'tax__count',
            'title_source': 'tax__name',
        }
    ]
예제 #6
0
class ProductClientSalesMatrix2(ReportGenerator):
    report_model = SimpleSales
    date_field = 'doc_date'

    group_by = 'product'
    columns = ['slug', 'name']

    crosstab_model = 'client'
    crosstab_columns = [
        SlickReportField.create(Sum,
                                'value',
                                name='value__sum',
                                verbose_name=_('Sales'))
    ]
예제 #7
0
    def test_joined_per_day(self):
        field_registry.register(SlickReportField.create(Count, 'id', 'count__id'))
        report_generator = ReportGenerator(report_model=UserJoined,
                                           date_field='date_joined',
                                           group_by='date_joined',
                                           start_date=datetime.date(2020, 1, 1),
                                           end_date=datetime.date(2020, 1, 10),
                                           columns=['date_joined', 'count__id'],
                                           )

        data = report_generator.get_report_data()
        self.assertEqual(len(data), 3)
        self.assertEqual(data[0]['count__id'], 1)
        self.assertEqual(data[1]['count__id'], 1)
        self.assertEqual(data[2]['count__id'], 2)
예제 #8
0
    def test_many_to_many_group_by(self):
        field_registry.register(SlickReportField.create(Count, 'tax__name', 'tax__count'))

        report_generator = ReportGenerator(report_model=ComplexSales,
                                           date_field='doc_date',
                                           group_by='tax__name',
                                           columns=['tax__name', 'tax__count'],
                                           )
        data = report_generator.get_report_data()
        self.assertEqual(len(data), 3)
        self.assertEqual(data[0]['tax__name'], 'State')
        self.assertEqual(data[0]['tax__count'], 3)
        self.assertEqual(data[1]['tax__name'], 'Vat reduced')
        self.assertEqual(data[1]['tax__count'], 2)
        self.assertEqual(data[2]['tax__name'], 'Vat full')
        self.assertEqual(data[2]['tax__count'], 1)
예제 #9
0
class CrossTabColumnOnFly(SlickReportView):
    report_title = 'awesome report title'
    report_model = SimpleSales
    date_field = 'doc_date'

    group_by = 'product'
    columns = ['slug', 'name']

    crosstab_model = 'client'
    crosstab_columns = [SlickReportField.create(Sum, 'value', name='value__sum', verbose_name=_('Sales'))]

    chart_settings = [
        {
            'type': 'pie',
            'date_source': 'value__sum',
            'title_source': 'name',
        }
    ]
예제 #10
0
    def test_group_by_traverse(self):
        report = ReportGenerator(
            report_model=SimpleSales,
            group_by='product__category',
            columns=[
                'product__category',
                SlickReportField.create(Sum, 'value'), '__total__'
            ],
            # time_series_pattern='monthly',
            date_field='doc_date',
            # time_series_columns=['__debit__', '__credit__', '__balance__', '__total__']
        )

        self.assertTrue(report._report_fields_dependencies)
        data = report.get_report_data()
        # import pdb;
        # pdb.set_trace()
        self.assertNotEqual(data, [])
        self.assertEqual(data[0]['product__category'], 'small')
        self.assertEqual(data[1]['product__category'], 'big')
예제 #11
0
 def test_creating_a_report_field_on_the_fly_wo_name(self):
     from django.db.models import Sum
     name = SlickReportField.create(Sum, 'value')
     self.assertNotIn(name, field_registry.get_all_report_fields_names())
예제 #12
0
class GroupByCharField(ReportGenerator):
    report_model = SalesWithFlag
    date_field = 'doc_date'
    group_by = 'flag'
    columns = ['flag', '__balance__', SlickReportField.create(Sum, 'quantity')]