Пример #1
0
def _create_commtrack_config_if_needed(domain):
    if SQLCommtrackConfig.for_domain(domain):
        return

    config = SQLCommtrackConfig(domain=domain)
    config.save(
        sync_to_couch=False)  # must be saved before submodels can be saved

    SQLAlertConfig(commtrack_config=config).save()
    SQLConsumptionConfig(commtrack_config=config).save()
    SQLStockLevelsConfig(commtrack_config=config).save()
    SQLStockRestoreConfig(commtrack_config=config).save()
    config.set_actions([
        SQLActionConfig(
            action='receipts',
            keyword='r',
            caption='Received',
        ),
        SQLActionConfig(
            action='consumption',
            keyword='c',
            caption='Consumed',
        ),
        SQLActionConfig(
            action='consumption',
            subaction='loss',
            keyword='l',
            caption='Losses',
        ),
        SQLActionConfig(
            action='stockonhand',
            keyword='soh',
            caption='Stock on hand',
        ),
        SQLActionConfig(
            action='stockout',
            keyword='so',
            caption='Stock-out',
        ),
    ])
    config.save()  # save actions, and sync couch
Пример #2
0
    def _create_unsynced_sql(self):
        """
            Create a SQLCommtrackConfig matching the one created by _create_unsynced_couch
        """
        sqlalertconfig = SQLAlertConfig(
            stock_out_facilities=True,
            stock_out_commodities=True,
            stock_out_rates=True,
            non_report=True,
        )
        sqlstockrestoreconfig = SQLStockRestoreConfig(
            section_to_consumption_types={'s1': 'c1'},
            force_consumption_case_types=['type1'],
            use_dynamic_product_list=True,
        )
        sqlconsumptionconfig = SQLConsumptionConfig(
            min_transactions=1,
            min_window=2,
            optimal_window=3,
            use_supply_point_type_default_consumption=True,
            exclude_invalid_periods=False,
        )
        sqlstocklevelsconfig = SQLStockLevelsConfig(
            emergency_level=0.5,
            understock_threshold=1.5,
            overstock_threshold=3,
        )
        sql = SQLCommtrackConfig(
            domain='my_project',
            use_auto_emergency_levels=False,
            sync_consumption_fixtures=False,
            use_auto_consumption=False,
            individual_consumption_defaults=True,
            sqlalertconfig=sqlalertconfig,
            sqlstockrestoreconfig=sqlstockrestoreconfig,
            sqlconsumptionconfig=sqlconsumptionconfig,
            sqlstocklevelsconfig=sqlstocklevelsconfig,
        )
        sql.save(sync_to_couch=False)  # save so that set_actions works

        sql.set_actions([
            SQLActionConfig(
                action='receipts',
                subaction='sub-receipts',
                _keyword='one',
                caption='first action',
            ),
            SQLActionConfig(
                action='receipts',
                subaction='sub-receipts',
                _keyword='two',
                caption='second action',
            ),
        ])
        sql.save(sync_to_couch=False)  # save actions

        # Save submodels
        sqlstockrestoreconfig.commtrack_config = sql
        sqlstockrestoreconfig.save()
        sqlalertconfig.commtrack_config = sql
        sqlalertconfig.save()
        sqlconsumptionconfig.commtrack_config = sql
        sqlconsumptionconfig.save()
        sqlstocklevelsconfig.commtrack_config = sql
        sqlstocklevelsconfig.save()

        return sql