(monthly_fee, edition, verbose, apps)
Ensures that all the necessary SoftwareProductRates are created for the plan.
Ensures that all the necessary SoftwareProductRates are created for the plan.
Ensures that all the necessary SoftwareProductRates are created for the plan .
def _ensure_product_rate(monthly_fee, edition, verbose, apps):
    """
    Ensures that all the necessary SoftwareProductRates are created for the plan.
    """
    if verbose:
        log_accounting_info('Ensuring Product Rates')

    SoftwareProductRate = apps.get_model('accounting', 'SoftwareProductRate')

    product_name = 'CommCare %s' % edition
    if edition == SoftwarePlanEdition.ENTERPRISE:
        product_name = "Dimagi Only %s" % product_name

    product_rate = SoftwareProductRate(monthly_fee=monthly_fee)
    try:
        # TODO - remove after squashing migrations
        SoftwareProduct = apps.get_model('accounting', 'SoftwareProduct')
        product = SoftwareProduct(name=product_name, product_type='CommCare')
        try:
            product = SoftwareProduct.objects.get(name=product.name)
            if verbose:
                log_accounting_info(
                    "Product '%s' already exists. Using existing product to add rate."
                    % product.name
                )
        except SoftwareProduct.DoesNotExist:
            if verbose:
                log_accounting_info("Creating Product: %s" % product)
            product.save()
        product_rate.product = product

        if verbose:
            log_accounting_info("Corresponding product rate of $%d created." % product_rate.monthly_fee)

        return product, product_rate

    except LookupError:
        product_rate.name = product_name
        if verbose:
            log_accounting_info("Corresponding product rate of $%d created." % product_rate.monthly_fee)
        return None, product_rate
def _ensure_product_rate ( monthly_fee , edition , verbose , apps ) : if verbose : log_accounting_info ( 'Ensuring Product Rates' ) SoftwareProductRate = apps . get_model ( 'accounting' , 'SoftwareProductRate' ) product_name = 'CommCare %s' % edition if edition == SoftwarePlanEdition . ENTERPRISE : product_name = "Dimagi Only %s" % product_name product_rate = SoftwareProductRate ( monthly_fee = monthly_fee ) try : # TODO - remove after squashing migrations SoftwareProduct = apps . get_model ( 'accounting' , 'SoftwareProduct' ) product = SoftwareProduct ( name = product_name , product_type = 'CommCare' ) try : product = SoftwareProduct . objects . get ( name = product . name ) if verbose : log_accounting_info ( "Product '%s' already exists. Using existing product to add rate." % product . name ) except SoftwareProduct . DoesNotExist : if verbose : log_accounting_info ( "Creating Product: %s" % product ) product . save ( ) product_rate . product = product if verbose : log_accounting_info ( "Corresponding product rate of $%d created." % product_rate . monthly_fee ) return product , product_rate except LookupError : product_rate . name = product_name if verbose : log_accounting_info ( "Corresponding product rate of $%d created." % product_rate . monthly_fee ) return None , product_rate