From cd5beec862844eab9ff52b2e55dbfd9679ca5cd0 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Tue, 17 May 2022 10:16:45 +0300 Subject: [PATCH] Use new is_hosted field --- lib/data/models/account_model.dart | 5 ++ lib/data/models/account_model.g.dart | 49 ++++++++++++++----- lib/data/models/company_model.dart | 5 ++ lib/data/models/company_model.g.dart | 43 +++++++++++----- lib/redux/app/app_state.dart | 10 ++-- lib/ui/invoice/edit/invoice_edit_desktop.dart | 2 +- lib/ui/invoice/edit/invoice_edit_pdf.dart | 2 +- 7 files changed, 83 insertions(+), 33 deletions(-) diff --git a/lib/data/models/account_model.dart b/lib/data/models/account_model.dart index c3f0ece16..0bd4e05a4 100644 --- a/lib/data/models/account_model.dart +++ b/lib/data/models/account_model.dart @@ -22,6 +22,7 @@ abstract class AccountEntity reportErrors: reportErrors, debugEnabled: false, isDocker: false, + isHosted: false, isSchedulerRunning: false, disableAutoUpdate: false, isMigrated: false, @@ -73,6 +74,9 @@ abstract class AccountEntity @BuiltValueField(wireName: 'is_migrated') bool get isMigrated; + @BuiltValueField(wireName: 'is_hosted') + bool get isHosted; + @BuiltValueField(wireName: 'is_scheduler_running') bool get isSchedulerRunning; @@ -107,6 +111,7 @@ abstract class AccountEntity ..isSchedulerRunning = false ..disableAutoUpdate = false ..isMigrated = false + ..isHosted = false ..trialPlan = '' ..trialStarted = '' ..defaultCompanyId = '' diff --git a/lib/data/models/account_model.g.dart b/lib/data/models/account_model.g.dart index f07b90dc4..5e0055675 100644 --- a/lib/data/models/account_model.g.dart +++ b/lib/data/models/account_model.g.dart @@ -53,6 +53,9 @@ class _$AccountEntitySerializer implements StructuredSerializer { 'is_migrated', serializers.serialize(object.isMigrated, specifiedType: const FullType(bool)), + 'is_hosted', + serializers.serialize(object.isHosted, + specifiedType: const FullType(bool)), 'is_scheduler_running', serializers.serialize(object.isSchedulerRunning, specifiedType: const FullType(bool)), @@ -133,6 +136,10 @@ class _$AccountEntitySerializer implements StructuredSerializer { result.isMigrated = serializers.deserialize(value, specifiedType: const FullType(bool)) as bool; break; + case 'is_hosted': + result.isHosted = serializers.deserialize(value, + specifiedType: const FullType(bool)) as bool; + break; case 'is_scheduler_running': result.isSchedulerRunning = serializers.deserialize(value, specifiedType: const FullType(bool)) as bool; @@ -186,6 +193,8 @@ class _$AccountEntity extends AccountEntity { @override final bool isMigrated; @override + final bool isHosted; + @override final bool isSchedulerRunning; @override final bool disableAutoUpdate; @@ -212,6 +221,7 @@ class _$AccountEntity extends AccountEntity { this.debugEnabled, this.isDocker, this.isMigrated, + this.isHosted, this.isSchedulerRunning, this.disableAutoUpdate, this.defaultCompanyId, @@ -240,6 +250,8 @@ class _$AccountEntity extends AccountEntity { isDocker, 'AccountEntity', 'isDocker'); BuiltValueNullFieldError.checkNotNull( isMigrated, 'AccountEntity', 'isMigrated'); + BuiltValueNullFieldError.checkNotNull( + isHosted, 'AccountEntity', 'isHosted'); BuiltValueNullFieldError.checkNotNull( isSchedulerRunning, 'AccountEntity', 'isSchedulerRunning'); BuiltValueNullFieldError.checkNotNull( @@ -275,6 +287,7 @@ class _$AccountEntity extends AccountEntity { debugEnabled == other.debugEnabled && isDocker == other.isDocker && isMigrated == other.isMigrated && + isHosted == other.isHosted && isSchedulerRunning == other.isSchedulerRunning && disableAutoUpdate == other.disableAutoUpdate && defaultCompanyId == other.defaultCompanyId && @@ -302,23 +315,26 @@ class _$AccountEntity extends AccountEntity { $jc( $jc( $jc( - 0, - id + $jc( + 0, + id + .hashCode), + trialPlan .hashCode), - trialPlan + trialStarted .hashCode), - trialStarted + defaultUrl .hashCode), - defaultUrl + reportErrors .hashCode), - reportErrors.hashCode), - plan.hashCode), - planExpires.hashCode), - latestVersion.hashCode), - currentVersion.hashCode), - debugEnabled.hashCode), - isDocker.hashCode), - isMigrated.hashCode), + plan.hashCode), + planExpires.hashCode), + latestVersion.hashCode), + currentVersion.hashCode), + debugEnabled.hashCode), + isDocker.hashCode), + isMigrated.hashCode), + isHosted.hashCode), isSchedulerRunning.hashCode), disableAutoUpdate.hashCode), defaultCompanyId.hashCode), @@ -341,6 +357,7 @@ class _$AccountEntity extends AccountEntity { ..add('debugEnabled', debugEnabled) ..add('isDocker', isDocker) ..add('isMigrated', isMigrated) + ..add('isHosted', isHosted) ..add('isSchedulerRunning', isSchedulerRunning) ..add('disableAutoUpdate', disableAutoUpdate) ..add('defaultCompanyId', defaultCompanyId) @@ -404,6 +421,10 @@ class AccountEntityBuilder bool get isMigrated => _$this._isMigrated; set isMigrated(bool isMigrated) => _$this._isMigrated = isMigrated; + bool _isHosted; + bool get isHosted => _$this._isHosted; + set isHosted(bool isHosted) => _$this._isHosted = isHosted; + bool _isSchedulerRunning; bool get isSchedulerRunning => _$this._isSchedulerRunning; set isSchedulerRunning(bool isSchedulerRunning) => @@ -448,6 +469,7 @@ class AccountEntityBuilder _debugEnabled = $v.debugEnabled; _isDocker = $v.isDocker; _isMigrated = $v.isMigrated; + _isHosted = $v.isHosted; _isSchedulerRunning = $v.isSchedulerRunning; _disableAutoUpdate = $v.disableAutoUpdate; _defaultCompanyId = $v.defaultCompanyId; @@ -494,6 +516,7 @@ class AccountEntityBuilder debugEnabled: BuiltValueNullFieldError.checkNotNull(debugEnabled, 'AccountEntity', 'debugEnabled'), isDocker: BuiltValueNullFieldError.checkNotNull(isDocker, 'AccountEntity', 'isDocker'), isMigrated: BuiltValueNullFieldError.checkNotNull(isMigrated, 'AccountEntity', 'isMigrated'), + isHosted: BuiltValueNullFieldError.checkNotNull(isHosted, 'AccountEntity', 'isHosted'), isSchedulerRunning: BuiltValueNullFieldError.checkNotNull(isSchedulerRunning, 'AccountEntity', 'isSchedulerRunning'), disableAutoUpdate: BuiltValueNullFieldError.checkNotNull(disableAutoUpdate, 'AccountEntity', 'disableAutoUpdate'), defaultCompanyId: BuiltValueNullFieldError.checkNotNull(defaultCompanyId, 'AccountEntity', 'defaultCompanyId'), diff --git a/lib/data/models/company_model.dart b/lib/data/models/company_model.dart index 9015bdee6..1ed9736b3 100644 --- a/lib/data/models/company_model.dart +++ b/lib/data/models/company_model.dart @@ -103,6 +103,7 @@ abstract class CompanyEntity extends Object markdownEmailEnabled: true, useCommaAsDecimalPlace: false, reportIncludeDrafts: false, + stopOnUnpaidRecurring: false, groups: BuiltList(), taxRates: BuiltList(), taskStatuses: BuiltList(), @@ -363,6 +364,9 @@ abstract class CompanyEntity extends Object @BuiltValueField(wireName: 'calculate_expense_tax_by_amount') bool get calculateExpenseTaxByAmount; + @BuiltValueField(wireName: 'stop_on_unpaid_recurring ') + bool get stopOnUnpaidRecurring; + String get displayName => settings.name ?? ''; @override @@ -598,6 +602,7 @@ abstract class CompanyEntity extends Object ..useCommaAsDecimalPlace = false ..reportIncludeDrafts = false ..convertRateToClient = true + ..stopOnUnpaidRecurring = false ..systemLogs.replace(BuiltList()) ..subscriptions.replace(BuiltList()) ..recurringExpenses.replace(BuiltList()) diff --git a/lib/data/models/company_model.g.dart b/lib/data/models/company_model.g.dart index 93d36fa5b..406154469 100644 --- a/lib/data/models/company_model.g.dart +++ b/lib/data/models/company_model.g.dart @@ -301,6 +301,9 @@ class _$CompanyEntitySerializer implements StructuredSerializer { 'calculate_expense_tax_by_amount', serializers.serialize(object.calculateExpenseTaxByAmount, specifiedType: const FullType(bool)), + 'stop_on_unpaid_recurring ', + serializers.serialize(object.stopOnUnpaidRecurring, + specifiedType: const FullType(bool)), 'created_at', serializers.serialize(object.createdAt, specifiedType: const FullType(int)), @@ -738,6 +741,10 @@ class _$CompanyEntitySerializer implements StructuredSerializer { result.calculateExpenseTaxByAmount = serializers.deserialize(value, specifiedType: const FullType(bool)) as bool; break; + case 'stop_on_unpaid_recurring ': + result.stopOnUnpaidRecurring = serializers.deserialize(value, + specifiedType: const FullType(bool)) as bool; + break; case 'isChanged': result.isChanged = serializers.deserialize(value, specifiedType: const FullType(bool)) as bool; @@ -1513,6 +1520,8 @@ class _$CompanyEntity extends CompanyEntity { @override final bool calculateExpenseTaxByAmount; @override + final bool stopOnUnpaidRecurring; + @override final bool isChanged; @override final int createdAt; @@ -1614,6 +1623,7 @@ class _$CompanyEntity extends CompanyEntity { this.settings, this.enabledModules, this.calculateExpenseTaxByAmount, + this.stopOnUnpaidRecurring, this.isChanged, this.createdAt, this.updatedAt, @@ -1771,6 +1781,8 @@ class _$CompanyEntity extends CompanyEntity { enabledModules, 'CompanyEntity', 'enabledModules'); BuiltValueNullFieldError.checkNotNull(calculateExpenseTaxByAmount, 'CompanyEntity', 'calculateExpenseTaxByAmount'); + BuiltValueNullFieldError.checkNotNull( + stopOnUnpaidRecurring, 'CompanyEntity', 'stopOnUnpaidRecurring'); BuiltValueNullFieldError.checkNotNull( createdAt, 'CompanyEntity', 'createdAt'); BuiltValueNullFieldError.checkNotNull( @@ -1870,6 +1882,7 @@ class _$CompanyEntity extends CompanyEntity { settings == other.settings && enabledModules == other.enabledModules && calculateExpenseTaxByAmount == other.calculateExpenseTaxByAmount && + stopOnUnpaidRecurring == other.stopOnUnpaidRecurring && isChanged == other.isChanged && createdAt == other.createdAt && updatedAt == other.updatedAt && @@ -1902,17 +1915,17 @@ class _$CompanyEntity extends CompanyEntity { $jc( $jc( $jc( - $jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc(0, enableCustomSurchargeTaxes1.hashCode), enableCustomSurchargeTaxes2.hashCode), enableCustomSurchargeTaxes3.hashCode), enableCustomSurchargeTaxes4.hashCode), sizeId.hashCode), industryId.hashCode), subdomain.hashCode), portalMode.hashCode), portalDomain.hashCode), updateProducts.hashCode), convertProductExchangeRate.hashCode), convertRateToClient.hashCode), fillProducts.hashCode), enableProductCost.hashCode), enableProductQuantity.hashCode), enableProductDiscount.hashCode), defaultTaskIsDateBased.hashCode), defaultQuantity.hashCode), showProductDetails.hashCode), clientCanRegister.hashCode), isLarge.hashCode), isDisabled.hashCode), enableShopApi.hashCode), companyKey.hashCode), firstDayOfWeek.hashCode), firstMonthOfYear.hashCode), numberOfInvoiceTaxRates.hashCode), numberOfItemTaxRates.hashCode), expenseInclusiveTaxes.hashCode), sessionTimeout.hashCode), passwordTimeout.hashCode), oauthPasswordRequired.hashCode), markdownEnabled.hashCode), markdownEmailEnabled.hashCode), useCommaAsDecimalPlace.hashCode), reportIncludeDrafts.hashCode), groups.hashCode), activities.hashCode), taxRates.hashCode), taskStatuses.hashCode), taskStatusMap.hashCode), companyGateways.hashCode), expenseCategories.hashCode), users.hashCode), clients.hashCode), products.hashCode), invoices.hashCode), recurringInvoices.hashCode), recurringExpenses.hashCode), payments.hashCode), quotes.hashCode), credits.hashCode), tasks.hashCode), projects.hashCode), expenses.hashCode), vendors.hashCode), designs.hashCode), documents.hashCode), tokens.hashCode), webhooks.hashCode), subscriptions.hashCode), paymentTerms.hashCode), systemLogs.hashCode), clientRegistrationFields.hashCode), customFields.hashCode), slackWebhookUrl.hashCode), googleAnalyticsKey.hashCode), markExpensesInvoiceable.hashCode), markExpensesPaid.hashCode), - invoiceExpenseDocuments.hashCode), - invoiceTaskDocuments.hashCode), - invoiceTaskTimelog.hashCode), - invoiceTaskDatelog.hashCode), - autoStartTasks.hashCode), - showTasksTable.hashCode), - showTaskEndDate.hashCode), - settings.hashCode), - enabledModules.hashCode), - calculateExpenseTaxByAmount.hashCode), + $jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc(0, enableCustomSurchargeTaxes1.hashCode), enableCustomSurchargeTaxes2.hashCode), enableCustomSurchargeTaxes3.hashCode), enableCustomSurchargeTaxes4.hashCode), sizeId.hashCode), industryId.hashCode), subdomain.hashCode), portalMode.hashCode), portalDomain.hashCode), updateProducts.hashCode), convertProductExchangeRate.hashCode), convertRateToClient.hashCode), fillProducts.hashCode), enableProductCost.hashCode), enableProductQuantity.hashCode), enableProductDiscount.hashCode), defaultTaskIsDateBased.hashCode), defaultQuantity.hashCode), showProductDetails.hashCode), clientCanRegister.hashCode), isLarge.hashCode), isDisabled.hashCode), enableShopApi.hashCode), companyKey.hashCode), firstDayOfWeek.hashCode), firstMonthOfYear.hashCode), numberOfInvoiceTaxRates.hashCode), numberOfItemTaxRates.hashCode), expenseInclusiveTaxes.hashCode), sessionTimeout.hashCode), passwordTimeout.hashCode), oauthPasswordRequired.hashCode), markdownEnabled.hashCode), markdownEmailEnabled.hashCode), useCommaAsDecimalPlace.hashCode), reportIncludeDrafts.hashCode), groups.hashCode), activities.hashCode), taxRates.hashCode), taskStatuses.hashCode), taskStatusMap.hashCode), companyGateways.hashCode), expenseCategories.hashCode), users.hashCode), clients.hashCode), products.hashCode), invoices.hashCode), recurringInvoices.hashCode), recurringExpenses.hashCode), payments.hashCode), quotes.hashCode), credits.hashCode), tasks.hashCode), projects.hashCode), expenses.hashCode), vendors.hashCode), designs.hashCode), documents.hashCode), tokens.hashCode), webhooks.hashCode), subscriptions.hashCode), paymentTerms.hashCode), systemLogs.hashCode), clientRegistrationFields.hashCode), customFields.hashCode), slackWebhookUrl.hashCode), googleAnalyticsKey.hashCode), markExpensesInvoiceable.hashCode), markExpensesPaid.hashCode), invoiceExpenseDocuments.hashCode), + invoiceTaskDocuments.hashCode), + invoiceTaskTimelog.hashCode), + invoiceTaskDatelog.hashCode), + autoStartTasks.hashCode), + showTasksTable.hashCode), + showTaskEndDate.hashCode), + settings.hashCode), + enabledModules.hashCode), + calculateExpenseTaxByAmount.hashCode), + stopOnUnpaidRecurring.hashCode), isChanged.hashCode), createdAt.hashCode), updatedAt.hashCode), @@ -2006,6 +2019,7 @@ class _$CompanyEntity extends CompanyEntity { ..add('settings', settings) ..add('enabledModules', enabledModules) ..add('calculateExpenseTaxByAmount', calculateExpenseTaxByAmount) + ..add('stopOnUnpaidRecurring', stopOnUnpaidRecurring) ..add('isChanged', isChanged) ..add('createdAt', createdAt) ..add('updatedAt', updatedAt) @@ -2431,6 +2445,11 @@ class CompanyEntityBuilder set calculateExpenseTaxByAmount(bool calculateExpenseTaxByAmount) => _$this._calculateExpenseTaxByAmount = calculateExpenseTaxByAmount; + bool _stopOnUnpaidRecurring; + bool get stopOnUnpaidRecurring => _$this._stopOnUnpaidRecurring; + set stopOnUnpaidRecurring(bool stopOnUnpaidRecurring) => + _$this._stopOnUnpaidRecurring = stopOnUnpaidRecurring; + bool _isChanged; bool get isChanged => _$this._isChanged; set isChanged(bool isChanged) => _$this._isChanged = isChanged; @@ -2555,6 +2574,7 @@ class CompanyEntityBuilder _settings = $v.settings.toBuilder(); _enabledModules = $v.enabledModules; _calculateExpenseTaxByAmount = $v.calculateExpenseTaxByAmount; + _stopOnUnpaidRecurring = $v.stopOnUnpaidRecurring; _isChanged = $v.isChanged; _createdAt = $v.createdAt; _updatedAt = $v.updatedAt; @@ -2679,6 +2699,7 @@ class CompanyEntityBuilder settings: settings.build(), enabledModules: BuiltValueNullFieldError.checkNotNull(enabledModules, 'CompanyEntity', 'enabledModules'), calculateExpenseTaxByAmount: BuiltValueNullFieldError.checkNotNull(calculateExpenseTaxByAmount, 'CompanyEntity', 'calculateExpenseTaxByAmount'), + stopOnUnpaidRecurring: BuiltValueNullFieldError.checkNotNull(stopOnUnpaidRecurring, 'CompanyEntity', 'stopOnUnpaidRecurring'), isChanged: isChanged, createdAt: BuiltValueNullFieldError.checkNotNull(createdAt, 'CompanyEntity', 'createdAt'), updatedAt: BuiltValueNullFieldError.checkNotNull(updatedAt, 'CompanyEntity', 'updatedAt'), diff --git a/lib/redux/app/app_state.dart b/lib/redux/app/app_state.dart index a54cd5daa..57d9706e0 100644 --- a/lib/redux/app/app_state.dart +++ b/lib/redux/app/app_state.dart @@ -752,25 +752,21 @@ abstract class AppState implements Built { bool get reportErrors => account?.reportErrors ?? false; - bool get isHosted => authState.isHosted ?? false; + bool get isHosted => account == null ? authState.isHosted : account.isHosted; - bool get isSelfHosted => authState.isSelfHost ?? false; + bool get isSelfHosted => !isHosted; bool get isDemo => cleanApiUrl(authState.url) == kAppDemoUrl; bool get isStaging => cleanApiUrl(authState.url) == kAppStagingUrl; - bool get isProduction => cleanApiUrl(authState.url) == kAppProductionUrl; - bool get isWhiteLabeled => account.plan == kPlanWhiteLabel; bool get isProPlan => isEnterprisePlan || account.plan == kPlanPro; bool get isTrial => isHosted && account.isTrial; - bool get isEnterprisePlan => !isProduction || account.plan == kPlanEnterprise; - - //bool get isEnterprisePlan => isSelfHosted || account.plan == kPlanEnterprise; + bool get isEnterprisePlan => isSelfHosted || account.plan == kPlanEnterprise; bool get isPaidAccount => isSelfHosted ? isWhiteLabeled diff --git a/lib/ui/invoice/edit/invoice_edit_desktop.dart b/lib/ui/invoice/edit/invoice_edit_desktop.dart index 947855235..ec6e84c9f 100644 --- a/lib/ui/invoice/edit/invoice_edit_desktop.dart +++ b/lib/ui/invoice/edit/invoice_edit_desktop.dart @@ -999,7 +999,7 @@ class __PdfPreviewState extends State<_PdfPreview> { if (widget.invoice.isOld) { url += '&entity_id=${widget.invoice.id}'; } - if (state.isProduction) { + if (state.isHosted) { url = url.replaceFirst('//', '//preview.'); } diff --git a/lib/ui/invoice/edit/invoice_edit_pdf.dart b/lib/ui/invoice/edit/invoice_edit_pdf.dart index 9a7db4f26..af49f721c 100644 --- a/lib/ui/invoice/edit/invoice_edit_pdf.dart +++ b/lib/ui/invoice/edit/invoice_edit_pdf.dart @@ -55,7 +55,7 @@ class InvoiceEditPDFState extends State { if (viewModel.invoice.isOld) { url += '&entity_id=${viewModel.invoice.id}'; } - if (viewModel.state.isProduction) { + if (viewModel.state.isHosted) { url = url.replaceFirst('//', '//preview.'); }