def enable_commtrack_daily_consumption(self): from corehq.apps.commtrack.util import make_domain_commtrack old_commtrack_enabled = self.domain.commtrack_enabled old_locations_enabled = getattr(self.domain, 'locations_enabled', None) make_domain_commtrack(self.domain) config = self.domain.commtrack_settings config.sqlconsumptionconfig.min_window = 2 config.sqlconsumptionconfig.save() try: yield finally: self.domain.commtrack_settings.delete() self.domain.commtrack_enabled = old_commtrack_enabled if old_locations_enabled is not None: self.domain.locations_enabled = old_locations_enabled else: del self.domain.locations_enabled self.domain.save()
def convert_to_commtrack(self): """ One-stop-shop to make a domain CommTrack """ from corehq.apps.commtrack.util import make_domain_commtrack make_domain_commtrack(self)
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 = CommtrackConfig.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, } }) config.delete() domain_obj.delete()