Пример #1
0
def bootstrap_commtrack_settings_if_necessary(domain, requisitions_enabled=False):
    if not (domain and domain.commtrack_enabled and not CommtrackConfig.for_domain(domain.name)):
        return

    c = CommtrackConfig(
        domain=domain.name,
        multiaction_enabled=True,
        multiaction_keyword="report",
        actions=[
            CommtrackActionConfig(action="receipts", keyword="r", caption="Received"),
            CommtrackActionConfig(action="consumption", keyword="c", caption="Consumed"),
            CommtrackActionConfig(action="consumption", subaction="loss", keyword="l", caption="Losses"),
            CommtrackActionConfig(action="stockonhand", keyword="soh", caption="Stock on hand"),
            CommtrackActionConfig(action="stockout", keyword="so", caption="Stock-out"),
        ],
        location_types=[
            LocationType(name="state", allowed_parents=[""], administrative=True),
            LocationType(name="district", allowed_parents=["state"], administrative=True),
            LocationType(name="block", allowed_parents=["district"], administrative=True),
            LocationType(name="village", allowed_parents=["block"], administrative=True),
            LocationType(name="outlet", allowed_parents=["village"]),
        ],
        supply_point_types=[],
    )
    if requisitions_enabled:
        c.requisition_config = get_default_requisition_config()

    c.save()

    program = make_program(domain.name, "Default", "def")
    make_product(domain.name, "Sample Product 1", "pp", program.get_id)
    make_product(domain.name, "Sample Product 2", "pq", program.get_id)
    make_product(domain.name, "Sample Product 3", "pr", program.get_id)

    return c
Пример #2
0
def bootstrap_commtrack_settings_if_necessary(domain, requisitions_enabled=False):
    if not(domain and domain.commtrack_enabled and not CommtrackConfig.for_domain(domain.name)):
        return

    c = CommtrackConfig(
        domain=domain.name,
        multiaction_enabled=True,
        multiaction_keyword='report',
        actions=[
            CommtrackActionConfig(
                action='receipts',
                keyword='r',
                caption='Received',
            ),
            CommtrackActionConfig(
                action='consumption',
                keyword='c',
                caption='Consumed',
            ),
            CommtrackActionConfig(
                action='consumption',
                subaction='loss',
                keyword='l',
                caption='Losses',
            ),
            CommtrackActionConfig(
                action='stockonhand',
                keyword='soh',
                caption='Stock on hand',
            ),
            CommtrackActionConfig(
                action='stockout',
                keyword='so',
                caption='Stock-out',
            ),
        ],
        location_types=[
            LocationType(name='state', allowed_parents=[''], administrative=True),
            LocationType(name='district', allowed_parents=['state'], administrative=True),
            LocationType(name='block', allowed_parents=['district'], administrative=True),
            LocationType(name='village', allowed_parents=['block'], administrative=True),
            LocationType(name='outlet', allowed_parents=['block', 'village']),
        ],
        supply_point_types=[],
    )
    if requisitions_enabled:
        c.requisition_config = get_default_requisition_config()

    c.save()

    program = make_program(domain.name, 'Default', 'def')
    make_product(domain.name, 'Sample Product 1', 'pp', program.get_id)
    make_product(domain.name, 'Sample Product 2', 'pq', program.get_id)
    make_product(domain.name, 'Sample Product 3', 'pr', program.get_id)

    return c
Пример #3
0
def bootstrap_commtrack_settings_if_necessary(domain, requisitions_enabled=False):
    """
    Create a new CommtrackConfig object for a domain
    if it does not already exist.


    This adds some collection of default products, programs,
    SMS keywords, etc.
    """
    def _needs_commtrack_config(domain):
        return (domain and
                domain.commtrack_enabled and
                not CommtrackConfig.for_domain(domain.name))

    if not _needs_commtrack_config(domain):
        return

    config = CommtrackConfig(
        domain=domain.name,
        multiaction_enabled=True,
        multiaction_keyword='report',
        actions=[
            CommtrackActionConfig(
                action='receipts',
                keyword='r',
                caption='Received',
            ),
            CommtrackActionConfig(
                action='consumption',
                keyword='c',
                caption='Consumed',
            ),
            CommtrackActionConfig(
                action='consumption',
                subaction='loss',
                keyword='l',
                caption='Losses',
            ),
            CommtrackActionConfig(
                action='stockonhand',
                keyword='soh',
                caption='Stock on hand',
            ),
            CommtrackActionConfig(
                action='stockout',
                keyword='so',
                caption='Stock-out',
            ),
        ],
        location_types=[
            LocationType(
                name='state',
                allowed_parents=[''],
                administrative=True
            ),
            LocationType(
                name='district',
                allowed_parents=['state'],
                administrative=True
            ),
            LocationType(
                name='block',
                allowed_parents=['district'],
                administrative=True
            ),
            LocationType(
                name='village',
                allowed_parents=['block'],
                administrative=True
            ),
            LocationType(
                name='outlet',
                allowed_parents=['village']
            ),
        ],
    )
    if requisitions_enabled:
        config.requisition_config = get_default_requisition_config()

    config.save()

    program = get_or_create_default_program(domain.name)
    make_product(domain.name, 'Sample Product 1', 'pp', program.get_id)
    make_product(domain.name, 'Sample Product 2', 'pq', program.get_id)
    make_product(domain.name, 'Sample Product 3', 'pr', program.get_id)

    return config
Пример #4
0
def bootstrap_commtrack_settings_if_necessary(domain, requisitions_enabled=False):
    """
    Create a new CommtrackConfig object for a domain
    if it does not already exist.

    This adds some collection of default products, programs,
    SMS keywords, etc.
    """
    def _needs_commtrack_config(domain):
        return (domain and
                domain.commtrack_enabled and
                not CommtrackConfig.for_domain(domain.name))

    if not _needs_commtrack_config(domain):
        return

    config = CommtrackConfig(
        domain=domain.name,
        multiaction_enabled=True,
        multiaction_keyword='report',
        actions=[
            CommtrackActionConfig(
                action='receipts',
                keyword='r',
                caption='Received',
            ),
            CommtrackActionConfig(
                action='consumption',
                keyword='c',
                caption='Consumed',
            ),
            CommtrackActionConfig(
                action='consumption',
                subaction='loss',
                keyword='l',
                caption='Losses',
            ),
            CommtrackActionConfig(
                action='stockonhand',
                keyword='soh',
                caption='Stock on hand',
            ),
            CommtrackActionConfig(
                action='stockout',
                keyword='so',
                caption='Stock-out',
            ),
        ],
    )

    if requisitions_enabled:
        config.requisition_config = get_default_requisition_config()

    config.save()

    program = get_or_create_default_program(domain.name)

    # Enable feature flags if necessary - this is required by exchange
    # and should have no effect on changing the project settings directly
    enable_commtrack_previews(domain)

    return config
Пример #5
0
def bootstrap_commtrack_settings_if_necessary(domain, requisitions_enabled=True):
    if not(domain and domain.commtrack_enabled and not domain.commtrack_settings):
        return

    c = CommtrackConfig(
        domain=domain.name,
        multiaction_enabled=True,
        multiaction_keyword='report',
        actions=[
            CommtrackActionConfig(
                action_type='receipts',
                keyword='r',
                caption='Received',
                name='received',
            ),
            CommtrackActionConfig(
                action_type='consumption',
                keyword='c',
                caption='Consumed',
                name='consumed',
            ),
            CommtrackActionConfig(
                action_type='consumption',
                keyword='l',
                caption='Losses',
                name='lost',
            ),
            CommtrackActionConfig(
                action_type='stockonhand',
                keyword='soh',
                caption='Stock on hand',
                name='stock_on_hand',
            ),
            CommtrackActionConfig(
                action_type='stockout',
                keyword='so',
                caption='Stock-out',
                name='stock_out',
            ),
        ],
        location_types=[
            LocationType(name='state', allowed_parents=[''], administrative=True),
            LocationType(name='district', allowed_parents=['state'], administrative=True),
            LocationType(name='block', allowed_parents=['district'], administrative=True),
            LocationType(name='village', allowed_parents=['block'], administrative=True),
            LocationType(name='outlet', allowed_parents=['block', 'village']),
        ],
        supply_point_types=[],
    )
    if requisitions_enabled:
        c.requisition_config = CommtrackRequisitionConfig(
            enabled=True,
            actions=[
                CommtrackActionConfig(
                    action_type=RequisitionActions.REQUEST,
                    keyword='req',
                    caption='Request',
                    name='request',
                ),
                CommtrackActionConfig(
                    action_type=RequisitionActions.APPROVAL,
                    keyword='approve',
                    caption='Approved',
                    name='approved',
                ),
                CommtrackActionConfig(
                    action_type=RequisitionActions.PACK,
                    keyword='pack',
                    caption='Packed',
                    name='packed',
                ),
                CommtrackActionConfig(
                    action_type=RequisitionActions.RECEIPTS,
                    keyword='rec',
                    caption='Requisition Receipts',
                    name='req_received',
                ),
            ],
        )
    c.save()

    make_product(domain.name, 'Sample Product 1', 'pp')
    make_product(domain.name, 'Sample Product 2', 'pq')
    make_product(domain.name, 'Sample Product 3', 'pr')

    return c
Пример #6
0
def bootstrap_commtrack_settings_if_necessary(domain, requisitions_enabled=False):
    """
    Create a new CommtrackConfig object for a domain
    if it does not already exist.


    This adds some collection of default products, programs,
    SMS keywords, etc.
    """
    def _needs_commtrack_config(domain):
        return (domain and
                domain.commtrack_enabled and
                not CommtrackConfig.for_domain(domain.name))

    if not _needs_commtrack_config(domain):
        return

    config = CommtrackConfig(
        domain=domain.name,
        multiaction_enabled=True,
        multiaction_keyword='report',
        actions=[
            CommtrackActionConfig(
                action='receipts',
                keyword='r',
                caption='Received',
            ),
            CommtrackActionConfig(
                action='consumption',
                keyword='c',
                caption='Consumed',
            ),
            CommtrackActionConfig(
                action='consumption',
                subaction='loss',
                keyword='l',
                caption='Losses',
            ),
            CommtrackActionConfig(
                action='stockonhand',
                keyword='soh',
                caption='Stock on hand',
            ),
            CommtrackActionConfig(
                action='stockout',
                keyword='so',
                caption='Stock-out',
            ),
        ],
    )

    if requisitions_enabled:
        config.requisition_config = get_default_requisition_config()

    config.save()

    program = get_or_create_default_program(domain.name)
    make_product(domain.name, 'Sample Product 1', 'pp', program.get_id)
    make_product(domain.name, 'Sample Product 2', 'pq', program.get_id)
    make_product(domain.name, 'Sample Product 3', 'pr', program.get_id)

    # this method is called during domain's post save, so this
    # is a little tricky, but it happens after the config is
    # created so should not cause problems
    domain.save()

    # Enable feature flags if necessary - this is required by exchange
    # and should have no effect on changing the project settings directly
    enable_commtrack_previews(domain)

    return config