Ejemplo n.º 1
0
    def handle(self, *args, **options):
        view = CommtrackConfig.get_db().view(
            'commtrack/domain_config',
            reduce=False
        )

        # preload domains
        domains_map = {
            d.name: d for d in Domain.get_all()
        }

        """
        Default mode is to only copy types over to
        the domain objects. This is meant to be run after
        preindexing.

        Note this will run on both pre and post deploy instances
        to make sure there aren't any new changes the second time.
        """
        def _process_fn(config):
            if 'location_types' in config:
                domain = domains_map[config['domain']].to_json()
                domain['location_types'] = config['location_types']
                return True, domain

            return False, None

        migrate_data_command(
            view=view,
            fetch_class=CommtrackConfig,
            process_fn=_process_fn,
            save_class=Domain
        )

        if 'post_deploy' in args:
            """
            If user explicitly triggers post_deploy flag,
            then we will actually delete from the commtrack
            config objects.
            """
            def _post_process_fn(config):
                if 'location_types' in config:
                    del config['location_types']
                    return True, config
                else:
                    return False, None

            migrate_data_command(
                view=view,
                fetch_class=CommtrackConfig,
                process_fn=_post_process_fn,
            )
Ejemplo n.º 2
0
 def setUpClass(cls):
     super().setUpClass()
     cls.db = CommtrackConfig.get_db()
Ejemplo n.º 3
0
 def test_make_domain_commtrack(self):
     domain_obj = create_domain("test-make-domain-commtrack")
     make_domain_commtrack(domain_obj)
     self.assertTrue(domain_obj.commtrack_enabled)
     self.assertTrue(domain_obj.locations_enabled)
     config = SQLCommtrackConfig.for_domain(domain_obj.name)
     self.assertEqual(
         config.to_json(), {
             'domain':
             'test-make-domain-commtrack',
             'actions': [{
                 'action': 'receipts',
                 'subaction': None,
                 '_keyword': 'r',
                 'caption': 'Received',
             }, {
                 'action': 'consumption',
                 'subaction': None,
                 '_keyword': 'c',
                 'caption': 'Consumed',
             }, {
                 'action': 'consumption',
                 'subaction': 'loss',
                 '_keyword': 'l',
                 'caption': 'Losses',
             }, {
                 'action': 'stockonhand',
                 'subaction': None,
                 '_keyword': 'soh',
                 'caption': 'Stock on hand',
             }, {
                 'action': 'stockout',
                 'subaction': None,
                 '_keyword': 'so',
                 'caption': 'Stock-out',
             }],
             'use_auto_emergency_levels':
             False,
             'sync_consumption_fixtures':
             False,
             'use_auto_consumption':
             False,
             'individual_consumption_defaults':
             False,
             'alert_config': {
                 'stock_out_facilities': False,
                 'stock_out_commodities': False,
                 'stock_out_rates': False,
                 'non_report': False,
             },
             'consumption_config': {
                 'min_transactions': 2,
                 'min_window': 10,
                 'optimal_window': None,
                 'use_supply_point_type_default_consumption': False,
                 'exclude_invalid_periods': False,
             },
             'ota_restore_config': {
                 'section_to_consumption_types': {},
                 'force_consumption_case_types': [],
                 'use_dynamic_product_list': False,
             },
             'stock_levels_config': {
                 'emergency_level': 0.5,
                 'understock_threshold': 1.5,
                 'overstock_threshold': 3,
             }
         })
     doc = CommtrackConfig.get_db().get(config.couch_id)
     self.assertIsNone(Command.get_diff_as_string(doc, config))
     config.delete()
     domain_obj.delete()