diff --git a/src/classes/RenewalSubscriptionsBatch.cls b/src/classes/RenewalSubscriptionsBatch.cls index df5f79b8..f2ec18b4 100644 --- a/src/classes/RenewalSubscriptionsBatch.cls +++ b/src/classes/RenewalSubscriptionsBatch.cls @@ -224,7 +224,7 @@ public without sharing class RenewalSubscriptionsBatch implements Database.Batch public List getFutureSubscriptions() { return [SELECT Id, Accounting_subscriber_domain__r.Name FROM Accounting_Subscription__c WHERE Accounting_subscriber_domain__r.Name != '' AND is_active__c = true AND is_trial__c = false - AND date_end__c != null AND date_end__c >: this.currentDate.addDays(60)]; + AND date_end__c != null AND date_end__c >: this.currentDate.addDays(60) AND Server_Name__c = 'CommCareHQ']; } /** @@ -235,7 +235,7 @@ public without sharing class RenewalSubscriptionsBatch implements Database.Batch Accounting_subscriber_domain__r.cpAllWebUsers__c, Software_Plan_Edition__c, Renewal_Opportunity_created__c FROM Accounting_Subscription__c WHERE Accounting_subscriber_domain__r.Name != '' AND Accounting_subscriber_domain__r.Opportunity__c = '' AND date_end__c != null AND date_end__c <=: this.currentDate.addDays(60) AND date_end__c >=: this.currentDate AND Accounting_subscriber_domain__r.Name NOT IN: domainsWithFutureSubscriptions AND is_active__c = true - AND is_trial__c = false ORDER BY date_end__c DESC]; + AND is_trial__c = false AND Server_Name__c = 'CommCareHQ' ORDER BY date_end__c DESC]; } private void processProductsErrors(List insertResults, List newOpps) { diff --git a/src/classes/RenewalSubscriptionsTest.cls b/src/classes/RenewalSubscriptionsTest.cls index 7b3fa357..1cad8f82 100644 --- a/src/classes/RenewalSubscriptionsTest.cls +++ b/src/classes/RenewalSubscriptionsTest.cls @@ -26,15 +26,15 @@ public class RenewalSubscriptionsTest { List entries = [SELECT Id, Name, ProductCode, UseStandardPrice, UnitPrice, Pricebook2Id FROM PricebookEntry]; System.debug('Entries ; ' + entries); - Accounting_BillingAccount__c billingAccount1 = new Accounting_BillingAccount__c(account_type__c = 'Pro', is_active__c = true, created_by__c = 'test@dimagi.com', created_by_domain__c = 'domain_1', dimagi_contact__c = 'contact_1@dimagi.com'); + Accounting_BillingAccount__c billingAccount1 = new Accounting_BillingAccount__c(Server_Name__c = 'CommCareHQ', account_type__c = 'Pro', is_active__c = true, created_by__c = 'test@dimagi.com', created_by_domain__c = 'domain_1', dimagi_contact__c = 'contact_1@dimagi.com'); insert billingAccount1; - Accounting_BillingAccount__c billingAccount2 = new Accounting_BillingAccount__c(account_type__c = 'Conventional 1', is_active__c = true, created_by__c = 'test@dimagi.com', created_by_domain__c = 'domain_2', dimagi_contact__c = 'contact_1@dimagi.com'); + Accounting_BillingAccount__c billingAccount2 = new Accounting_BillingAccount__c(Server_Name__c = 'CommCareHQ', account_type__c = 'Conventional 1', is_active__c = true, created_by__c = 'test@dimagi.com', created_by_domain__c = 'domain_2', dimagi_contact__c = 'contact_1@dimagi.com'); insert billingAccount2; - Accounting_BillingAccount__c billingAccount3 = new Accounting_BillingAccount__c(account_type__c = 'Conventional 2', is_active__c = true, created_by__c = 'test@dimagi.com', created_by_domain__c = 'domain_2', dimagi_contact__c = 'contact_1@dimagi.com'); + Accounting_BillingAccount__c billingAccount3 = new Accounting_BillingAccount__c(Server_Name__c = 'CommCareHQ', account_type__c = 'Conventional 2', is_active__c = true, created_by__c = 'test@dimagi.com', created_by_domain__c = 'domain_2', dimagi_contact__c = 'contact_1@dimagi.com'); insert billingAccount3; - Accounting_BillingAccount__c billingAccount4 = new Accounting_BillingAccount__c(account_type__c = 'Conventional 3', is_active__c = true, created_by__c = 'test@dimagi.com', created_by_domain__c = 'domain_2', dimagi_contact__c = 'contact_1@dimagi.com'); + Accounting_BillingAccount__c billingAccount4 = new Accounting_BillingAccount__c(Server_Name__c = 'CommCareHQ', account_type__c = 'Conventional 3', is_active__c = true, created_by__c = 'test@dimagi.com', created_by_domain__c = 'domain_2', dimagi_contact__c = 'contact_1@dimagi.com'); insert billingAccount4; - Accounting_BillingAccount__c billingAccount5 = new Accounting_BillingAccount__c(account_type__c = 'Free', is_active__c = true, created_by__c = 'test@dimagi.com', created_by_domain__c = 'domain_3', dimagi_contact__c = 'contact_1@dimagi.com'); + Accounting_BillingAccount__c billingAccount5 = new Accounting_BillingAccount__c(Server_Name__c = 'CommCareHQ', account_type__c = 'Free', is_active__c = true, created_by__c = 'test@dimagi.com', created_by_domain__c = 'domain_3', dimagi_contact__c = 'contact_1@dimagi.com'); insert billingAccount5; Business_Unit__c bizUnit = new Business_Unit__c(Name = 'Test Business Unit 1'); @@ -44,48 +44,48 @@ public class RenewalSubscriptionsTest { Account testAccount = new Account(Name = 'Test Account'); insert testAccount; - Domain__c domain1 = new Domain__c(Name = 'domain_1', cpAllWebUsers__c = 30, Account__c = testAccount.Id); + Domain__c domain1 = new Domain__c(Server_Name__c = 'CommCareHQ', Name = 'domain_1', cpAllWebUsers__c = 30, Account__c = testAccount.Id); insert domain1; - Domain__c domain2 = new Domain__c(Name = 'domain_2', cpAllWebUsers__c = 22); + Domain__c domain2 = new Domain__c(Server_Name__c = 'CommCareHQ', Name = 'domain_2', cpAllWebUsers__c = 22); insert domain2; - Domain__c domain3 = new Domain__c(Name = 'domain_3', cpAllWebUsers__c = 11); + Domain__c domain3 = new Domain__c(Server_Name__c = 'CommCareHQ', Name = 'domain_3', cpAllWebUsers__c = 11); insert domain3; - Domain__c domain4 = new Domain__c(Name = 'domain_4', cpAllWebUsers__c = 111, Opportunity__c = opp.Id); + Domain__c domain4 = new Domain__c(Server_Name__c = 'CommCareHQ', Name = 'domain_4', cpAllWebUsers__c = 111, Opportunity__c = opp.Id); insert domain4; - Accounting_Softwareplan__c softwarePlan1 = new Accounting_Softwareplan__c(edition__c = 'Pro'); + Accounting_Softwareplan__c softwarePlan1 = new Accounting_Softwareplan__c(Server_Name__c = 'CommCareHQ', edition__c = 'Pro'); insert softwarePlan1; - Accounting_Softwareplan__c softwarePlan2 = new Accounting_Softwareplan__c(edition__c = 'Community'); + Accounting_Softwareplan__c softwarePlan2 = new Accounting_Softwareplan__c(Server_Name__c = 'CommCareHQ', edition__c = 'Community'); insert softwarePlan2; - Accounting_Softwareplan__c softwarePlan3 = new Accounting_Softwareplan__c(edition__c = 'Conventional'); + Accounting_Softwareplan__c softwarePlan3 = new Accounting_Softwareplan__c(Server_Name__c = 'CommCareHQ', edition__c = 'Conventional'); insert softwarePlan3; - Accounting_SoftwarePlanVersion__c planVersion1 = new Accounting_SoftwarePlanVersion__c(Accounting_SoftwarePlan__c = softwarePlan1.Id); + Accounting_SoftwarePlanVersion__c planVersion1 = new Accounting_SoftwarePlanVersion__c(Server_Name__c = 'CommCareHQ', Accounting_SoftwarePlan__c = softwarePlan1.Id); insert planVersion1; - Accounting_SoftwarePlanVersion__c planVersion2 = new Accounting_SoftwarePlanVersion__c(Accounting_SoftwarePlan__c = softwarePlan2.Id); + Accounting_SoftwarePlanVersion__c planVersion2 = new Accounting_SoftwarePlanVersion__c(Server_Name__c = 'CommCareHQ', Accounting_SoftwarePlan__c = softwarePlan2.Id); insert planVersion2; - Accounting_SoftwarePlanVersion__c planVersion3 = new Accounting_SoftwarePlanVersion__c(Accounting_SoftwarePlan__c = softwarePlan3.Id); + Accounting_SoftwarePlanVersion__c planVersion3 = new Accounting_SoftwarePlanVersion__c(Server_Name__c = 'CommCareHQ', Accounting_SoftwarePlan__c = softwarePlan3.Id); insert planVersion3; - Accounting_Subscription__c subscription1 = new Accounting_Subscription__c(is_trial__c = false, date_start__c = Date.newInstance(2016, 1, 1), date_end__c = Date.newInstance(2017, 1, 1), service_type__c = 'Implementation', is_active__c = true, + Accounting_Subscription__c subscription1 = new Accounting_Subscription__c(Server_Name__c = 'CommCareHQ', is_trial__c = false, date_start__c = Date.newInstance(2016, 1, 1), date_end__c = Date.newInstance(2017, 1, 1), service_type__c = 'Implementation', is_active__c = true, Renewal_Opportunity_created__c = false, account__c = billingAccount1.Id, Accounting_subscriber_domain__c = domain1.Id, plan_version__c = planVersion1.Id); insert subscription1; - Accounting_Subscription__c subscription2 = new Accounting_Subscription__c(is_trial__c = false, date_start__c = Date.newInstance(2016, 1, 1), date_end__c = Date.newInstance(2016, 11, 2), service_type__c = 'Other', is_active__c = true, + Accounting_Subscription__c subscription2 = new Accounting_Subscription__c(Server_Name__c = 'CommCareHQ', is_trial__c = false, date_start__c = Date.newInstance(2016, 1, 1), date_end__c = Date.newInstance(2016, 11, 2), service_type__c = 'Other', is_active__c = true, Renewal_Opportunity_created__c = false, account__c = billingAccount2.Id, Accounting_subscriber_domain__c = domain2.Id, plan_version__c = planVersion2.Id); insert subscription2; - Accounting_Subscription__c subscription3 = new Accounting_Subscription__c(is_trial__c = false, date_start__c = Date.newInstance(2016, 6, 1), date_end__c = Date.newInstance(2016, 12, 3), service_type__c = 'Other', is_active__c = true, + Accounting_Subscription__c subscription3 = new Accounting_Subscription__c(Server_Name__c = 'CommCareHQ', is_trial__c = false, date_start__c = Date.newInstance(2016, 6, 1), date_end__c = Date.newInstance(2016, 12, 3), service_type__c = 'Other', is_active__c = true, Renewal_Opportunity_created__c = false, account__c = billingAccount3.Id, Accounting_subscriber_domain__c = domain2.Id, plan_version__c = planVersion2.Id); insert subscription3; - Accounting_Subscription__c subscription4 = new Accounting_Subscription__c(is_trial__c = false, date_start__c = Date.newInstance(2016, 12, 3), date_end__c = Date.newInstance(2017, 1, 20), service_type__c = 'Other', is_active__c = true, + Accounting_Subscription__c subscription4 = new Accounting_Subscription__c(Server_Name__c = 'CommCareHQ', is_trial__c = false, date_start__c = Date.newInstance(2016, 12, 3), date_end__c = Date.newInstance(2017, 1, 20), service_type__c = 'Other', is_active__c = true, Renewal_Opportunity_created__c = false, account__c = billingAccount4.Id, Accounting_subscriber_domain__c = domain2.Id, plan_version__c = planVersion2.Id); insert subscription4; - Accounting_Subscription__c subscription5 = new Accounting_Subscription__c(is_trial__c = false, date_start__c = Date.newInstance(2016, 1, 1), date_end__c = Date.newInstance(2017, 5, 1), service_type__c = 'Product', is_active__c = true, + Accounting_Subscription__c subscription5 = new Accounting_Subscription__c(Server_Name__c = 'CommCareHQ', is_trial__c = false, date_start__c = Date.newInstance(2016, 1, 1), date_end__c = Date.newInstance(2017, 5, 1), service_type__c = 'Product', is_active__c = true, Renewal_Opportunity_created__c = false, account__c = billingAccount5.Id, Accounting_subscriber_domain__c = domain3.Id, plan_version__c = planVersion3.Id); insert subscription5; - Accounting_Subscription__c subscription6 = new Accounting_Subscription__c(is_trial__c = false, date_start__c = Date.newInstance(2016, 1, 1), date_end__c = Date.newInstance(2017, 1, 1), service_type__c = 'Product', is_active__c = true, + Accounting_Subscription__c subscription6 = new Accounting_Subscription__c(Server_Name__c = 'CommCareHQ', is_trial__c = false, date_start__c = Date.newInstance(2016, 1, 1), date_end__c = Date.newInstance(2017, 1, 1), service_type__c = 'Product', is_active__c = true, Renewal_Opportunity_created__c = false, account__c = billingAccount5.Id, Accounting_subscriber_domain__c = domain4.Id, plan_version__c = planVersion3.Id); insert subscription6; - Accounting_Subscription__c subscription7 = new Accounting_Subscription__c(is_trial__c = false, date_start__c = Date.newInstance(2016, 1, 1), date_end__c = Date.newInstance(2017, 1, 12), service_type__c = 'Product', is_active__c = true, + Accounting_Subscription__c subscription7 = new Accounting_Subscription__c(Server_Name__c = 'CommCareHQ', is_trial__c = false, date_start__c = Date.newInstance(2016, 1, 1), date_end__c = Date.newInstance(2017, 1, 12), service_type__c = 'Product', is_active__c = true, Renewal_Opportunity_created__c = false, account__c = billingAccount5.Id, Accounting_subscriber_domain__c = domain4.Id, plan_version__c = planVersion3.Id); insert subscription7;