Пример #1
0
def make_psi_config(domain):
    c = CommtrackConfig(
        domain=domain,
        multiaction_enabled=True,
        multiaction_keyword="s",
        actions=[
            CommtrackActionConfig(action_type="stockedoutfor", keyword="d", caption="Stock-out Days"),
            CommtrackActionConfig(action_type="receipts", keyword="r", caption="Other Receipts"),
            CommtrackActionConfig(action_type="stockonhand", keyword="b", caption="Balance"),
            CommtrackActionConfig(action_type="receipts", name="sales", keyword="p", caption="Placements"),
        ],
        supply_point_types=[
            SupplyPointType(name="CHC", categories=["Public"]),
            SupplyPointType(name="PHC", categories=["Public"]),
            SupplyPointType(name="SC", categories=["Public"]),
            SupplyPointType(name="MBBS", categories=["Private"]),
            SupplyPointType(name="Pediatrician", categories=["Private"]),
            SupplyPointType(name="AYUSH", categories=["Private"]),
            SupplyPointType(name="Medical Store / Chemist", categories=["Traditional"]),
            SupplyPointType(name="RP", categories=["Traditional"]),
            SupplyPointType(name="Asha", categories=["Frontline Workers"]),
            SupplyPointType(name="AWW", categories=["Public", "Frontline Workers"]),
            SupplyPointType(name="NGO", categories=["Non-traditional"]),
            SupplyPointType(name="CBO", categories=["Non-traditional"]),
            SupplyPointType(name="SHG", categories=["Non-traditional"]),
            SupplyPointType(name="Pan Store", categories=["Traditional"]),
            SupplyPointType(name="General Store", categories=["Traditional"]),
        ],
    )
    c.save()
    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=["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
 def test_report_with_exclude_disabled(self):
     commtrack_config = CommtrackConfig(domain=self.domain.name)
     commtrack_config.consumption_config = ConsumptionConfig()
     commtrack_config.save()
     self.create_transactions(self.domain.name)
     self.assertEqual(StockTransaction.objects.all().count(), 3)
     self.assertEqual(StockTransaction.objects.filter(type='receipts').count(), 1)
     commtrack_config.delete()
Пример #4
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
Пример #5
0
 def test_get_docs_in_domain_by_class(self):
     commtrack_config = CommtrackConfig(domain=self.domain)
     group = Group(domain=self.domain)
     xform = XFormInstance(domain=self.domain)
     commtrack_config.save()
     group.save()
     xform.save()
     self.addCleanup(commtrack_config.delete)
     self.addCleanup(group.delete)
     self.addCleanup(xform.delete)
     [commtrack_config_2] = get_docs_in_domain_by_class(self.domain, CommtrackConfig)
     self.assertEqual(commtrack_config_2.to_json(), commtrack_config.to_json())
Пример #6
0
def make_psi_config(domain):
    c = CommtrackConfig(domain=domain,
                        multiaction_enabled=True,
                        multiaction_keyword='s',
                        actions=[
                            CommtrackActionConfig(action_type='stockedoutfor',
                                                  keyword='d',
                                                  caption='Stock-out Days'),
                            CommtrackActionConfig(action_type='receipts',
                                                  keyword='r',
                                                  caption='Other Receipts'),
                            CommtrackActionConfig(action_type='stockonhand',
                                                  keyword='b',
                                                  caption='Balance'),
                            CommtrackActionConfig(action_type='receipts',
                                                  name='sales',
                                                  keyword='p',
                                                  caption='Placements'),
                        ],
                        supply_point_types=[
                            SupplyPointType(name='CHC', categories=['Public']),
                            SupplyPointType(name='PHC', categories=['Public']),
                            SupplyPointType(name='SC', categories=['Public']),
                            SupplyPointType(name='MBBS',
                                            categories=['Private']),
                            SupplyPointType(name='Pediatrician',
                                            categories=['Private']),
                            SupplyPointType(name='AYUSH',
                                            categories=['Private']),
                            SupplyPointType(name='Medical Store / Chemist',
                                            categories=['Traditional']),
                            SupplyPointType(name='RP',
                                            categories=['Traditional']),
                            SupplyPointType(name='Asha',
                                            categories=['Frontline Workers']),
                            SupplyPointType(
                                name='AWW',
                                categories=['Public', 'Frontline Workers']),
                            SupplyPointType(name='NGO',
                                            categories=['Non-traditional']),
                            SupplyPointType(name='CBO',
                                            categories=['Non-traditional']),
                            SupplyPointType(name='SHG',
                                            categories=['Non-traditional']),
                            SupplyPointType(name='Pan Store',
                                            categories=['Traditional']),
                            SupplyPointType(name='General Store',
                                            categories=['Traditional']),
                        ])
    c.save()
    return c
 def _create_unsynced_couch(self):
     """
         Create a CommtrackConfig matching the one created by _create_unsynced_sql
     """
     couch = CommtrackConfig(
         domain='my_project',
         use_auto_emergency_levels=False,
         sync_consumption_fixtures=False,
         use_auto_consumption=False,
         individual_consumption_defaults=True,
         ota_restore_config=StockRestoreConfig(
             section_to_consumption_types={'s1': 'c1'},
             force_consumption_case_types=['type1'],
             use_dynamic_product_list=True,
         ),
         alert_config=AlertConfig(
             stock_out_facilities=True,
             stock_out_commodities=True,
             stock_out_rates=True,
             non_report=True,
         ),
         actions=[
             CommtrackActionConfig(
                 action='receipts',
                 subaction='sub-receipts',
                 _keyword='one',
                 caption='first action',
             ),
             CommtrackActionConfig(
                 action='receipts',
                 subaction='sub-receipts',
                 _keyword='two',
                 caption='second action',
             ),
         ],
         consumption_config=ConsumptionConfig(
             min_transactions=1,
             min_window=2,
             optimal_window=3,
             use_supply_point_type_default_consumption=True,
             exclude_invalid_periods=False,
         ),
         stock_levels_config=StockLevelsConfig(
             emergency_level=0.5,
             understock_threshold=1.5,
             overstock_threshold=3,
         )
     )
     couch.save(sync_to_sql=False)
     return couch
Пример #8
0
def make_psi_config(domain):
    c = CommtrackConfig(
        domain=domain,
        multiaction_enabled=True,
        multiaction_keyword='s',
        actions=[
            CommtrackActionConfig(
                action_type='stockedoutfor',
                keyword='d',
                caption='Stock-out Days'
            ),
            CommtrackActionConfig(
                action_type='receipts',
                keyword='r',
                caption='Other Receipts'
            ),
            CommtrackActionConfig(
                action_type='stockonhand',
                keyword='b',
                caption='Balance'
            ),
            CommtrackActionConfig(
                action_type='receipts',
                name='sales',
                keyword='p',
                caption='Placements'
            ),
        ],
        supply_point_types=[
            SupplyPointType(name='CHC', categories=['Public']),
            SupplyPointType(name='PHC', categories=['Public']),
            SupplyPointType(name='SC', categories=['Public']),
            SupplyPointType(name='MBBS', categories=['Private']),
            SupplyPointType(name='Pediatrician', categories=['Private']),
            SupplyPointType(name='AYUSH', categories=['Private']),
            SupplyPointType(name='Medical Store / Chemist', categories=['Traditional']),
            SupplyPointType(name='RP', categories=['Traditional']),
            SupplyPointType(name='Asha', categories=['Frontline Workers']),
            SupplyPointType(name='AWW', categories=['Public', 'Frontline Workers']),
            SupplyPointType(name='NGO', categories=['Non-traditional']),
            SupplyPointType(name='CBO', categories=['Non-traditional']),
            SupplyPointType(name='SHG', categories=['Non-traditional']),
            SupplyPointType(name='Pan Store', categories=['Traditional']),
            SupplyPointType(name='General Store', categories=['Traditional']),
        ]
    )
    c.save()
    return c
Пример #9
0
def _create_commtrack_config_if_needed(domain):
    if CommtrackConfig.for_domain(domain):
        return

    config = CommtrackConfig(domain=domain)
    config.save()  # must be saved before submodels can be saved

    AlertConfig(commtrack_config=config).save()
    ConsumptionConfig(commtrack_config=config).save()
    StockLevelsConfig(commtrack_config=config).save()
    StockRestoreConfig(commtrack_config=config).save()
    config.set_actions([
        ActionConfig(
            action='receipts',
            keyword='r',
            caption='Received',
        ),
        ActionConfig(
            action='consumption',
            keyword='c',
            caption='Consumed',
        ),
        ActionConfig(
            action='consumption',
            subaction='loss',
            keyword='l',
            caption='Losses',
        ),
        ActionConfig(
            action='stockonhand',
            keyword='soh',
            caption='Stock on hand',
        ),
        ActionConfig(
            action='stockout',
            keyword='so',
            caption='Stock-out',
        ),
    ])
    config.save()  # save actions, and sync couch
Пример #10
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
Пример #11
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
Пример #12
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
Пример #13
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