def create_reports(self, rt_sub_bill_received, current_year_invoice_filter, current_year_unpaid_invoice_filter): from functools import partial from django.contrib.auth import get_user_model from creme import reports # from creme.reports.constants import ( # RFT_FIELD, # RFT_RELATION, # RGA_SUM, # RGT_FK, # RGT_MONTH, # ) from creme.reports.constants import RFT_FIELD, RFT_RELATION from creme.reports.core.graph.fetcher import SimpleGraphFetcher from creme.reports.models import Field admin = get_user_model().objects.get_admin() ReportGraph = reports.get_rgraph_model() total_no_vat_cell = EntityCellRegularField.build( Invoice, 'total_no_vat') if total_no_vat_cell is None: logger.warning('Invoice seems not having a field "total_no_vat" ' '=> no Report/ReportGraph created.') return def create_report_columns(report): create_field = partial(Field.objects.create, report=report, type=RFT_FIELD) create_field(name='name', order=1) create_field(name=rt_sub_bill_received.id, order=2, type=RFT_RELATION) create_field(name='number', order=3) create_field(name='status', order=4) create_field(name='total_no_vat', order=5) create_field(name='issuing_date', order=6) create_field(name='expiration_date', order=7) create_report = partial(reports.get_report_model().objects.create, user=admin, ct=Invoice) create_graph = partial(ReportGraph.objects.create, user=admin) # Create current year invoices report ---------------------------------- invoices_report1 = create_report( name=_('All invoices of the current year'), filter=current_year_invoice_filter, ) create_report_columns(invoices_report1) cell_key = total_no_vat_cell.key rgraph1 = create_graph( name=_('Sum of current year invoices total without taxes / month'), linked_report=invoices_report1, # abscissa_cell_value='issuing_date', abscissa_type=RGT_MONTH, abscissa_cell_value='issuing_date', abscissa_type=ReportGraph.Group.MONTH, # ordinate_type=RGA_SUM, ordinate_type=ReportGraph.Aggregator.SUM, ordinate_cell_key=cell_key, ) create_graph( name= _('Sum of current year invoices total without taxes / invoices status' ), linked_report=invoices_report1, # abscissa_cell_value='status', abscissa_type=RGT_FK, abscissa_cell_value='status', abscissa_type=ReportGraph.Group.FK, # ordinate_type=RGA_SUM, ordinate_type=ReportGraph.Aggregator.SUM, ordinate_cell_key=cell_key, ) ibci1 = SimpleGraphFetcher(graph=rgraph1).create_brick_config_item() BrickHomeLocation.objects.create(brick_id=ibci1.brick_id, order=11) # Create current year and unpaid invoices report ----------------------- invoices_report2 = create_report( name=_('Invoices unpaid of the current year'), filter=current_year_unpaid_invoice_filter, ) create_report_columns(invoices_report2) rgraph3 = create_graph( name= _('Sum of current year and unpaid invoices total without taxes / month' ), linked_report=invoices_report2, # abscissa_cell_value='issuing_date', abscissa_type=RGT_MONTH, abscissa_cell_value='issuing_date', abscissa_type=ReportGraph.Group.MONTH, # ordinate_type=RGA_SUM, ordinate_type=ReportGraph.Aggregator.SUM, ordinate_cell_key=cell_key, ) ibci3 = SimpleGraphFetcher(rgraph3).create_brick_config_item() BrickHomeLocation.objects.create(brick_id=ibci3.brick_id, order=12)
class GraphCreation(generic.AddingInstanceToEntityPopup): model = ReportGraph form_class = ReportGraphForm title = _('Create a graph for «{entity}»') entity_id_url_kwarg = 'report_id' entity_classes = reports.get_report_model()
# -*- coding: utf-8 -*- from django.utils.translation import gettext_lazy as _ from creme import reports from creme.creme_core.gui.custom_form import CustomFormDescriptor from .forms import report as r_froms Report = reports.get_report_model() REPORT_CREATION_CFORM = CustomFormDescriptor( id='reports-report_creation', model=Report, verbose_name=_('Creation form for report (step 1)'), excluded_fields=('ct', 'filter'), extra_sub_cells=[r_froms.FilteredCTypeSubCell(model=Report)], ) REPORT_EDITION_CFORM = CustomFormDescriptor( id='reports-report_edition', model=Report, form_type=CustomFormDescriptor.EDITION_FORM, verbose_name=_('Edition form for report'), excluded_fields=('ct', 'filter'), extra_sub_cells=[r_froms.FilterSubCell(model=Report)]) del Report
def create_reports(self, rt_sub_bill_received, current_year_invoice_filter, current_year_unpaid_invoice_filter): from functools import partial from django.contrib.auth import get_user_model from django.contrib.contenttypes.models import ContentType from creme import reports from creme.reports.constants import RFT_FIELD, RFT_RELATION, RGT_FK, RGT_MONTH # from creme.reports.models import Report, Field, ReportGraph from creme.reports.models import Field admin = get_user_model().objects.get_admin() def create_report_columns(report): create_field = partial(Field.objects.create, report=report, type=RFT_FIELD) create_field(name='name', order=1) create_field(name=rt_sub_bill_received.id, order=2, type=RFT_RELATION) create_field(name='number', order=3) create_field(name='status', order=4) create_field(name='total_no_vat', order=5) create_field(name='issuing_date', order=6) create_field(name='expiration_date', order=7) # create_report = partial(Report.objects.create, user=admin, create_report = partial( reports.get_report_model().objects.create, user=admin, ct=ContentType.objects.get_for_model(Invoice), ) # create_graph = partial(ReportGraph.objects.create, user=admin) create_graph = partial(reports.get_rgraph_model().objects.create, user=admin) # Create current year invoices report ---------------------------------- invoices_report1 = create_report( name=_('All invoices of the current year'), filter=current_year_invoice_filter, ) create_report_columns(invoices_report1) rgraph1 = create_graph( name=_('Sum of current year invoices total without taxes / month'), linked_report=invoices_report1, abscissa='issuing_date', ordinate='total_no_vat__sum', type=RGT_MONTH, is_count=False, ) create_graph( name= _('Sum of current year invoices total without taxes / invoices status' ), linked_report=invoices_report1, abscissa='status', ordinate='total_no_vat__sum', type=RGT_FK, is_count=False, ) ibci = rgraph1.create_instance_brick_config_item() BrickHomeLocation.objects.create(brick_id=ibci.brick_id, order=11) # Create current year and unpaid invoices report ----------------------- invoices_report2 = create_report( name=_('Invoices unpaid of the current year'), filter=current_year_unpaid_invoice_filter, ) create_report_columns(invoices_report2) rgraph = create_graph( name= _('Sum of current year and unpaid invoices total without taxes / month' ), linked_report=invoices_report2, abscissa='issuing_date', ordinate='total_no_vat__sum', type=RGT_MONTH, is_count=False, ) ibci = rgraph.create_instance_brick_config_item() BrickHomeLocation.objects.create(brick_id=ibci.brick_id, order=12)
def create_report_n_graphes(self, rt_obj_emit_orga): "Create the report 'Opportunities' and 2 ReportGraphs." from django.contrib.auth import get_user_model from creme import reports from creme.creme_core.utils.meta import FieldInfo # from creme.reports import constants as rep_constants from creme.reports.constants import RFT_FIELD, RFT_RELATION from creme.reports.core.graph.fetcher import SimpleGraphFetcher from creme.reports.models import Field admin = get_user_model().objects.get_admin() if reports.report_model_is_custom(): logger.info( 'Report model is custom => no Opportunity report is created.') return # Create the report ---------------------------------------------------- report = reports.get_report_model().objects.create( name=_('Opportunities'), user=admin, ct=Opportunity, ) # TODO: helper method(s) (see EntityFilterCondition) create_field = partial(Field.objects.create, report=report, type=RFT_FIELD) create_field(name='name', order=1) create_field(name='estimated_sales', order=2) create_field(name='made_sales', order=3) create_field(name='sales_phase__name', order=4) create_field(name=rt_obj_emit_orga.id, order=5, type=RFT_RELATION) # Create 2 graphs ------------------------------------------------------ if reports.rgraph_model_is_custom(): logger.info('ReportGraph model is custom' ' => no Opportunity report-graph is created.') return sales_cell = EntityCellRegularField.build(Opportunity, 'estimated_sales') if sales_cell is None: logger.warning( 'Opportunity seems not having a field "estimated_sales"' ' => no ReportGraph created.') return ReportGraph = reports.get_rgraph_model() # TODO: helper method (range only on DateFields etc...) create_graph = partial( ReportGraph.objects.create, linked_report=report, user=admin, # ordinate_type=rep_constants.RGA_SUM, ordinate_type=ReportGraph.Aggregator.SUM, ordinate_cell_key=sales_cell.key, ) esales_vname = FieldInfo(Opportunity, 'estimated_sales').verbose_name rgraph1 = create_graph( name=_('Sum {estimated_sales} / {sales_phase}').format( estimated_sales=esales_vname, sales_phase=FieldInfo(Opportunity, 'sales_phase').verbose_name, ), # abscissa_type=rep_constants.RGT_FK, abscissa_type=ReportGraph.Group.FK, abscissa_cell_value='sales_phase', ) rgraph2 = create_graph( name=_( 'Sum {estimated_sales} / Quarter (90 days on {closing_date})'). format( estimated_sales=esales_vname, closing_date=FieldInfo(Opportunity, 'closing_date').verbose_name, ), # abscissa_type=rep_constants.RGT_RANGE, abscissa_type=ReportGraph.Group.RANGE, abscissa_cell_value='closing_date', abscissa_parameter='90', ) # Create 2 instance block items for the 2 graphs ----------------------- brick_id1 = SimpleGraphFetcher( rgraph1).create_brick_config_item().brick_id brick_id2 = SimpleGraphFetcher( rgraph2).create_brick_config_item().brick_id create_bdl = partial( BrickDetailviewLocation.objects.create_if_needed, zone=BrickDetailviewLocation.RIGHT, model=Opportunity, ) create_bdl(brick=brick_id1, order=4) create_bdl(brick=brick_id2, order=6) create_hbl = BrickHomeLocation.objects.create create_hbl(brick_id=brick_id1, order=5) create_hbl(brick_id=brick_id2, order=6)
def create_report_n_graphes(self, rt_obj_emit_orga): "Create the report 'Opportunities' and 2 ReportGraphs." from django.contrib.auth import get_user_model from creme.creme_core.utils.meta import FieldInfo from creme import reports from creme.reports import constants as rep_constants from creme.reports.models import Field admin = get_user_model().objects.get_admin() if reports.report_model_is_custom(): logger.info( 'Report model is custom => no Opportunity report is created.') return # Create the report ---------------------------------------------------- report = reports.get_report_model() \ .objects.create(name=_('Opportunities'), user=admin, ct=Opportunity) # TODO: helper method(s) (see EntityFilterCondition) create_field = partial(Field.objects.create, report=report, type=rep_constants.RFT_FIELD) create_field(name='name', order=1) create_field(name='estimated_sales', order=2) create_field(name='made_sales', order=3) create_field(name='sales_phase__name', order=4) create_field(name=rt_obj_emit_orga.id, order=5, type=rep_constants.RFT_RELATION) # Create 2 graphs ----------------------------------------------------- if reports.rgraph_model_is_custom(): logger.info( 'ReportGraph model is custom => no Opportunity report-graph is created.' ) return # TODO: helper method ('sum' => is_count=False, range only on DateFields etc...) create_graph = partial( reports.get_rgraph_model().objects.create, linked_report=report, user=admin, is_count=False, ordinate='estimated_sales__sum', ) esales_vname = FieldInfo(Opportunity, 'estimated_sales').verbose_name rgraph1 = create_graph( name=_('Sum {estimated_sales} / {sales_phase}').format( estimated_sales=esales_vname, sales_phase=FieldInfo(Opportunity, 'sales_phase').verbose_name, ), abscissa='sales_phase', type=rep_constants.RGT_FK, ) rgraph2 = create_graph( name=_( 'Sum {estimated_sales} / Quarter (90 days on {closing_date})'). format( estimated_sales=esales_vname, closing_date=FieldInfo(Opportunity, 'closing_date').verbose_name, ), abscissa='closing_date', type=rep_constants.RGT_RANGE, days=90, ) # Create 2 instance block items for the 2 graphs ---------------------- brick_id1 = rgraph1.create_instance_brick_config_item().brick_id brick_id2 = rgraph2.create_instance_brick_config_item().brick_id create_bdl = partial( BrickDetailviewLocation.objects.create_if_needed, zone=BrickDetailviewLocation.RIGHT, model=Opportunity, ) create_bdl(brick=brick_id1, order=4) create_bdl(brick=brick_id2, order=6) BrickHomeLocation.objects.create(brick_id=brick_id1, order=5) BrickHomeLocation.objects.create(brick_id=brick_id2, order=6)