MCPcopy Create free account
hub / github.com/Keeper-Security/Commander / execute

Method execute

keepercommander/commands/msp.py:778–884  ·  view source on GitHub ↗
(self, params, **kwargs)

Source from the content-addressed store, hash-verified

776 return max(dates) - min(dates) + 1 if dates else 30
777
778 def execute(self, params, **kwargs):
779 month_str = kwargs.get('month')
780 if not month_str:
781 dt = datetime.datetime.now()
782 month = dt.month
783 year = dt.year
784 month -= 1
785 if month < 1:
786 month += 12
787 year -= 1
788 else:
789 year_part, sep, month_part = month_str.partition('-')
790 try:
791 year = int(year_part)
792 month = int(month_part)
793 except:
794 logging.warning('Given month \"%s\" is not valid. YYYY-MM', month_str)
795 return
796 daily_counts = MSPBillingReportCommand.get_daily_snapshots(params, year, month)
797 title = f'Consumption Billing Statement: {calendar.month_name[month]} {year}'
798 headers = []
799 table = []
800
801 show_date = kwargs.get('show_date', False)
802 show_company = kwargs.get('show_company', False)
803 merged_counts = {} # type: Dict[DailySnapshot, Dict[int, Tuple[int, int]]]
804 for dc in daily_counts:
805 d = DailySnapshot(dc.mc_enterprise_id if show_company else 0, dc.date_no if show_date else 0)
806 merged_counts[d] = DailySnapshot.merge_units((merged_counts.get(d), daily_counts[dc]))
807
808 if show_date:
809 headers.append('date')
810 if show_company:
811 headers.extend(('company', 'company_id'))
812 headers.extend(('product', 'licenses', 'rate'))
813 if not show_date:
814 headers.extend(['avg_per_day', 'initial_licenses', 'final_licenses', 'max_licenses'])
815 plan_lookup = {x[0]: x for x in constants.MSP_PLANS}
816 storage_lookup = {x[0]: x for x in constants.MSP_FILE_PLANS}
817 addon_lookup = {}
818 addons = {x[0]: x for x in constants.MSP_ADDONS}
819 for a_id, a_name in MSPMixin.get_msp_addons(params).items():
820 if a_name in addons:
821 addon_lookup[a_id] = addons[a_name]
822 pricing = MSPMixin.get_msp_pricing(params)
823 for point in merged_counts:
824 day_str = str(datetime.date.fromordinal(point.date_no)) if show_date else ''
825 company = MSPBillingReportCommand.COMPANY_CACHE.get(point.mc_enterprise_id, '') if show_company else ''
826 start_snapshots, end_snapshots = (None, None) \
827 if show_date \
828 else MSPBillingReportCommand.get_bounding_snapshots(daily_counts, None if not show_company else point.mc_enterprise_id)
829 counts = merged_counts[point]
830 products = list(counts.keys())
831 products.sort()
832 for product in products:
833 row = []
834 if show_date:
835 row.append(day_str)

Callers

nothing calls this directly

Calls 15

DailySnapshotClass · 0.85
field_to_titleFunction · 0.85
dump_report_dataFunction · 0.85
warningMethod · 0.80
get_daily_snapshotsMethod · 0.80
merge_unitsMethod · 0.80
get_msp_addonsMethod · 0.80
get_msp_pricingMethod · 0.80
get_count_idMethod · 0.80
get_num_reported_daysMethod · 0.80
is_plan_idMethod · 0.80

Tested by

no test coverage detected