(self)
Get the allowed number of mobile workers based on plan version.
Get the allowed number of mobile workers based on plan version.
Get the allowed number of mobile workers based on plan version .
def response_mobile_worker_creation(self):
        """
        Get the allowed number of mobile workers based on plan version.
        """
        from corehq.apps.accounting.models import FeatureType, FeatureRate, UNLIMITED_FEATURE_USAGE
        num_users = CommCareUser.total_by_domain(self.domain.name, is_active=True)
        try:
            user_rate = self.new_plan_version.feature_rates.filter(
                feature__feature_type=FeatureType.USER).latest('date_created')
            if user_rate.monthly_limit == UNLIMITED_FEATURE_USAGE:
                return
            num_allowed = user_rate.monthly_limit
            num_extra = num_users - num_allowed
            if num_extra > 0:
                from corehq.apps.accounting.models import DefaultProductPlan
                if self.new_plan_version != DefaultProductPlan.get_default_plan_version():
                    return _fmt_alert(
                        ungettext(
                            "You have %(num_extra)d Mobile Worker over the monthly "
                            "limit of %(monthly_limit)d for this new plan. There "
                            "will be an additional monthly charge of USD "
                            "%(excess_fee)s per Mobile Worker, totalling USD "
                            "%(monthly_total)s per month, if you select this plan.",

                            "You have %(num_extra)d Mobile Workers over the "
                            "monthly limit of %(monthly_limit)d for this new plan. "
                            "There will be an additional monthly charge "
                            "of USD %(excess_fee)s per Mobile Worker, totalling "
                            "USD %(monthly_total)s per month, if you "
                            "select this plan.",
                            num_extra
                        ) % {
                            'num_extra': num_extra,
                            'monthly_limit': user_rate.monthly_limit,
                            'excess_fee': user_rate.per_excess_fee,
                            'monthly_total': user_rate.per_excess_fee * num_extra,
                        }
                    )
                else:
                    return _fmt_alert(
                        ungettext(
                            "Community plans include %(monthly_limit)s Mobile Workers by default. "
                            "Because you have %(num_extra)d extra Mobile Worker, "
                            "all your project's Mobile Workers will be deactivated. "
                            "You can re-activate these manually after downgrade. "
                            "Each active Mobile Worker over %(monthly_limit)s will result "
                            "in an additional charge of USD %(excess_fee)s, totalling "
                            "USD %(monthly_total)s per month.",

                            "Community plans include %(monthly_limit)s Mobile Workers by default. "
                            "Because you have %(num_extra)d extra Mobile Workers, "
                            "all your project's Mobile Workers will be deactivated. "
                            "You can re-activate these manually after downgrade. "
                            "Each active Mobile Worker over %(monthly_limit)s will result "
                            "in an additional charge of USD %(excess_fee)s, totalling "
                            "USD %(monthly_total)s per month.",
                            num_extra
                        ) % {
                            'num_extra': num_extra,
                            'monthly_limit': user_rate.monthly_limit,
                            'excess_fee': user_rate.per_excess_fee,
                            'monthly_total': user_rate.per_excess_fee * num_extra,
                        }
                    )
        except FeatureRate.DoesNotExist:
            log_accounting_error(
                "It seems that the plan %s did not have rate for Mobile "
                "Workers. This is problematic."
                % self.new_plan_version.plan.name
            )
def response_mobile_worker_creation ( self ) : from corehq . apps . accounting . models import FeatureType , FeatureRate , UNLIMITED_FEATURE_USAGE num_users = CommCareUser . total_by_domain ( self . domain . name , is_active = True ) try : user_rate = self . new_plan_version . feature_rates . filter ( feature__feature_type = FeatureType . USER ) . latest ( 'date_created' ) if user_rate . monthly_limit == UNLIMITED_FEATURE_USAGE : return num_allowed = user_rate . monthly_limit num_extra = num_users - num_allowed if num_extra > 0 : from corehq . apps . accounting . models import DefaultProductPlan if self . new_plan_version != DefaultProductPlan . get_default_plan_version ( ) : return _fmt_alert ( ungettext ( "You have %(num_extra)d Mobile Worker over the monthly " "limit of %(monthly_limit)d for this new plan. There " "will be an additional monthly charge of USD " "%(excess_fee)s per Mobile Worker, totalling USD " "%(monthly_total)s per month, if you select this plan." , "You have %(num_extra)d Mobile Workers over the " "monthly limit of %(monthly_limit)d for this new plan. " "There will be an additional monthly charge " "of USD %(excess_fee)s per Mobile Worker, totalling " "USD %(monthly_total)s per month, if you " "select this plan." , num_extra ) % { 'num_extra' : num_extra , 'monthly_limit' : user_rate . monthly_limit , 'excess_fee' : user_rate . per_excess_fee , 'monthly_total' : user_rate . per_excess_fee * num_extra , } ) else : return _fmt_alert ( ungettext ( "Community plans include %(monthly_limit)s Mobile Workers by default. " "Because you have %(num_extra)d extra Mobile Worker, " "all your project's Mobile Workers will be deactivated. " "You can re-activate these manually after downgrade. " "Each active Mobile Worker over %(monthly_limit)s will result " "in an additional charge of USD %(excess_fee)s, totalling " "USD %(monthly_total)s per month." , "Community plans include %(monthly_limit)s Mobile Workers by default. " "Because you have %(num_extra)d extra Mobile Workers, " "all your project's Mobile Workers will be deactivated. " "You can re-activate these manually after downgrade. " "Each active Mobile Worker over %(monthly_limit)s will result " "in an additional charge of USD %(excess_fee)s, totalling " "USD %(monthly_total)s per month." , num_extra ) % { 'num_extra' : num_extra , 'monthly_limit' : user_rate . monthly_limit , 'excess_fee' : user_rate . per_excess_fee , 'monthly_total' : user_rate . per_excess_fee * num_extra , } ) except FeatureRate . DoesNotExist : log_accounting_error ( "It seems that the plan %s did not have rate for Mobile " "Workers. This is problematic." % self . new_plan_version . plan . name )