mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Merge pull request #3321 from luisramos0/2-0-delete-acct-invoices
[Spree Upgrade] Delete Accounts and Billing dead feature code until we decide we want to start using it again
This commit is contained in:
@@ -22,9 +22,7 @@
|
||||
Metrics/LineLength:
|
||||
Max: 100
|
||||
Exclude:
|
||||
- app/controllers/admin/accounts_and_billing_settings_controller.rb
|
||||
- app/controllers/admin/bulk_line_items_controller.rb
|
||||
- app/controllers/admin/business_model_configuration_controller.rb
|
||||
- app/controllers/admin/cache_settings_controller.rb
|
||||
- app/controllers/admin/contents_controller.rb
|
||||
- app/controllers/admin/customers_controller.rb
|
||||
@@ -63,7 +61,6 @@ Metrics/LineLength:
|
||||
- app/controllers/stripe/callbacks_controller.rb
|
||||
- app/controllers/user_confirmations_controller.rb
|
||||
- app/helpers/admin/account_helper.rb
|
||||
- app/helpers/admin/business_model_configuration_helper.rb
|
||||
- app/helpers/admin/injection_helper.rb
|
||||
- app/helpers/angular_form_builder.rb
|
||||
- app/helpers/angular_form_helper.rb
|
||||
@@ -79,16 +76,12 @@ Metrics/LineLength:
|
||||
- app/helpers/spree/admin/navigation_helper_decorator.rb
|
||||
- app/helpers/spree/admin/orders_helper_decorator.rb
|
||||
- app/helpers/spree/orders_helper.rb
|
||||
- app/jobs/finalize_account_invoices.rb
|
||||
- app/jobs/products_cache_integrity_checker_job.rb
|
||||
- app/jobs/subscription_confirm_job.rb
|
||||
- app/jobs/subscription_placement_job.rb
|
||||
- app/jobs/update_account_invoices.rb
|
||||
- app/jobs/update_billable_periods.rb
|
||||
- app/mailers/producer_mailer.rb
|
||||
- app/mailers/spree/order_mailer_decorator.rb
|
||||
- app/mailers/subscription_mailer.rb
|
||||
- app/models/billable_period.rb
|
||||
- app/models/column_preference.rb
|
||||
- app/models/content_configuration.rb
|
||||
- app/models/customer.rb
|
||||
@@ -160,11 +153,8 @@ Metrics/LineLength:
|
||||
- engines/web/app/helpers/web/cookies_policy_helper.rb
|
||||
- Gemfile
|
||||
- lib/discourse/single_sign_on.rb
|
||||
- lib/open_food_network/accounts_and_billing_settings_validator.rb
|
||||
- lib/open_food_network/available_payment_method_filter.rb
|
||||
- lib/open_food_network/bill_calculator.rb
|
||||
- lib/open_food_network/bulk_coop_report.rb
|
||||
- lib/open_food_network/business_model_configuration_validator.rb
|
||||
- lib/open_food_network/customers_report.rb
|
||||
- lib/open_food_network/distribution_change_validator.rb
|
||||
- lib/open_food_network/enterprise_fee_applicator.rb
|
||||
@@ -201,7 +191,6 @@ Metrics/LineLength:
|
||||
- lib/tasks/dev.rake
|
||||
- lib/tasks/enterprises.rake
|
||||
- spec/archive/features/consumer/checkout_spec.rb
|
||||
- spec/controllers/admin/accounts_and_billing_settings_controller_spec.rb
|
||||
- spec/controllers/admin/bulk_line_items_controller_spec.rb
|
||||
- spec/controllers/admin/column_preferences_controller_spec.rb
|
||||
- spec/controllers/admin/customers_controller_spec.rb
|
||||
@@ -245,7 +234,6 @@ Metrics/LineLength:
|
||||
- spec/controllers/stripe/webhooks_controller_spec.rb
|
||||
- spec/controllers/user_confirmations_controller_spec.rb
|
||||
- spec/controllers/user_registrations_controller_spec.rb
|
||||
- spec/features/admin/accounts_and_billing_settings_spec.rb
|
||||
- spec/features/admin/adjustments_spec.rb
|
||||
- spec/features/admin/bulk_order_management_spec.rb
|
||||
- spec/features/admin/bulk_product_update_spec.rb
|
||||
@@ -289,7 +277,6 @@ Metrics/LineLength:
|
||||
- spec/features/consumer/shopping/shopping_spec.rb
|
||||
- spec/features/consumer/shopping/variant_overrides_spec.rb
|
||||
- spec/features/consumer/shops_spec.rb
|
||||
- spec/helpers/admin/business_model_configuration_helper_spec.rb
|
||||
- spec/helpers/admin/subscriptions_helper_spec.rb
|
||||
- spec/helpers/checkout_helper_spec.rb
|
||||
- spec/helpers/enterprises_helper_spec.rb
|
||||
@@ -298,12 +285,9 @@ Metrics/LineLength:
|
||||
- spec/helpers/order_cycles_helper_spec.rb
|
||||
- spec/helpers/spree/admin/base_helper_spec.rb
|
||||
- spec/jobs/confirm_order_job_spec.rb
|
||||
- spec/jobs/finalize_account_invoices_spec.rb
|
||||
- spec/jobs/refresh_products_cache_job_spec.rb
|
||||
- spec/jobs/subscription_confirm_job_spec.rb
|
||||
- spec/jobs/subscription_placement_job_spec.rb
|
||||
- spec/jobs/update_account_invoices_spec.rb
|
||||
- spec/jobs/update_billable_periods_spec.rb
|
||||
- spec/lib/open_food_network/address_finder_spec.rb
|
||||
- spec/lib/open_food_network/bulk_coop_report_spec.rb
|
||||
- spec/lib/open_food_network/cached_products_renderer_spec.rb
|
||||
@@ -337,7 +321,6 @@ Metrics/LineLength:
|
||||
- spec/mailers/order_mailer_spec.rb
|
||||
- spec/mailers/producer_mailer_spec.rb
|
||||
- spec/mailers/subscription_mailer_spec.rb
|
||||
- spec/models/billable_period_spec.rb
|
||||
- spec/models/column_preference_spec.rb
|
||||
- spec/models/customer_spec.rb
|
||||
- spec/models/enterprise_caching_spec.rb
|
||||
@@ -452,18 +435,13 @@ Metrics/AbcSize:
|
||||
- app/controllers/user_confirmations_controller.rb
|
||||
- app/controllers/user_passwords_controller.rb
|
||||
- app/controllers/user_registrations_controller.rb
|
||||
- app/helpers/admin/business_model_configuration_helper.rb
|
||||
- app/helpers/checkout_helper.rb
|
||||
- app/helpers/i18n_helper.rb
|
||||
- app/helpers/order_cycles_helper.rb
|
||||
- app/helpers/spree/admin/orders_helper_decorator.rb
|
||||
- app/helpers/spree/orders_helper.rb
|
||||
- app/jobs/finalize_account_invoices.rb
|
||||
- app/jobs/subscription_placement_job.rb
|
||||
- app/jobs/update_account_invoices.rb
|
||||
- app/jobs/update_billable_periods.rb
|
||||
- app/mailers/producer_mailer.rb
|
||||
- app/models/billable_period.rb
|
||||
- app/models/calculator/flat_percent_per_item.rb
|
||||
- app/models/column_preference.rb
|
||||
- app/models/enterprise_group.rb
|
||||
@@ -492,7 +470,6 @@ Metrics/AbcSize:
|
||||
- app/services/order_syncer.rb
|
||||
- app/services/subscription_validator.rb
|
||||
- lib/discourse/single_sign_on.rb
|
||||
- lib/open_food_network/bill_calculator.rb
|
||||
- lib/open_food_network/bulk_coop_report.rb
|
||||
- lib/open_food_network/customers_report.rb
|
||||
- lib/open_food_network/enterprise_issue_validator.rb
|
||||
@@ -534,13 +511,10 @@ Metrics/CyclomaticComplexity:
|
||||
- app/controllers/checkout_controller.rb
|
||||
- app/controllers/spree/admin/orders_controller_decorator.rb
|
||||
- app/controllers/spree/orders_controller_decorator.rb
|
||||
- app/helpers/admin/business_model_configuration_helper.rb
|
||||
- app/helpers/checkout_helper.rb
|
||||
- app/helpers/i18n_helper.rb
|
||||
- app/helpers/order_cycles_helper.rb
|
||||
- app/helpers/spree/admin/orders_helper_decorator.rb
|
||||
- app/jobs/update_account_invoices.rb
|
||||
- app/jobs/update_billable_periods.rb
|
||||
- app/models/enterprise.rb
|
||||
- app/models/enterprise_relationship.rb
|
||||
- app/models/product_import/entry_processor.rb
|
||||
@@ -553,7 +527,6 @@ Metrics/CyclomaticComplexity:
|
||||
- app/models/variant_override_set.rb
|
||||
- app/services/cart_service.rb
|
||||
- lib/discourse/single_sign_on.rb
|
||||
- lib/open_food_network/bill_calculator.rb
|
||||
- lib/open_food_network/bulk_coop_report.rb
|
||||
- lib/open_food_network/enterprise_issue_validator.rb
|
||||
- lib/open_food_network/orders_and_fulfillments_report.rb
|
||||
@@ -569,12 +542,10 @@ Metrics/PerceivedComplexity:
|
||||
- app/controllers/checkout_controller.rb
|
||||
- app/controllers/spree/admin/orders_controller_decorator.rb
|
||||
- app/controllers/spree/orders_controller_decorator.rb
|
||||
- app/helpers/admin/business_model_configuration_helper.rb
|
||||
- app/helpers/checkout_helper.rb
|
||||
- app/helpers/i18n_helper.rb
|
||||
- app/helpers/order_cycles_helper.rb
|
||||
- app/helpers/spree/admin/orders_helper_decorator.rb
|
||||
- app/jobs/update_account_invoices.rb
|
||||
- app/models/enterprise_relationship.rb
|
||||
- app/models/product_import/entry_processor.rb
|
||||
- app/models/product_import/entry_validator.rb
|
||||
@@ -624,12 +595,8 @@ Metrics/MethodLength:
|
||||
- app/helpers/checkout_helper.rb
|
||||
- app/helpers/order_cycles_helper.rb
|
||||
- app/helpers/spree/admin/orders_helper_decorator.rb
|
||||
- app/jobs/finalize_account_invoices.rb
|
||||
- app/jobs/subscription_placement_job.rb
|
||||
- app/jobs/update_account_invoices.rb
|
||||
- app/jobs/update_billable_periods.rb
|
||||
- app/mailers/producer_mailer.rb
|
||||
- app/models/billable_period.rb
|
||||
- app/models/column_preference.rb
|
||||
- app/models/enterprise.rb
|
||||
- app/models/enterprise_relationship.rb
|
||||
|
||||
@@ -143,7 +143,6 @@ Layout/EmptyLines:
|
||||
- 'app/helpers/angular_form_helper.rb'
|
||||
- 'app/helpers/injection_helper.rb'
|
||||
- 'app/helpers/spree/admin/base_helper_decorator.rb'
|
||||
- 'app/jobs/finalize_account_invoices.rb'
|
||||
- 'app/jobs/products_cache_integrity_checker_job.rb'
|
||||
- 'app/jobs/refresh_products_cache_job.rb'
|
||||
- 'app/models/coordinator_fee.rb'
|
||||
@@ -218,7 +217,6 @@ Layout/EmptyLines:
|
||||
- 'spec/features/consumer/shopping/variant_overrides_spec.rb'
|
||||
- 'spec/features/consumer/shops_spec.rb'
|
||||
- 'spec/helpers/checkout_helper_spec.rb'
|
||||
- 'spec/jobs/finalize_account_invoices_spec.rb'
|
||||
- 'spec/jobs/heartbeat_job_spec.rb'
|
||||
- 'spec/lib/open_food_network/enterprise_fee_calculator_spec.rb'
|
||||
- 'spec/lib/open_food_network/option_value_namer_spec.rb'
|
||||
@@ -278,17 +276,14 @@ Layout/EmptyLinesAroundBlockBody:
|
||||
- 'spec/features/consumer/shopping/embedded_groups_spec.rb'
|
||||
- 'spec/features/consumer/shopping/embedded_shopfronts_spec.rb'
|
||||
- 'spec/features/consumer/shopping/shopping_spec.rb'
|
||||
- 'spec/helpers/admin/business_model_configuration_helper_spec.rb'
|
||||
- 'spec/helpers/shared_helper_spec.rb'
|
||||
- 'spec/helpers/shop_helper_spec.rb'
|
||||
- 'spec/helpers/spree/orders_helper_spec.rb'
|
||||
- 'spec/jobs/update_billable_periods_spec.rb'
|
||||
- 'spec/lib/open_food_network/group_buy_report_spec.rb'
|
||||
- 'spec/lib/open_food_network/lettuce_share_report_spec.rb'
|
||||
- 'spec/lib/open_food_network/order_grouper_spec.rb'
|
||||
- 'spec/lib/open_food_network/referer_parser_spec.rb'
|
||||
- 'spec/lib/open_food_network/user_balance_calculator_spec.rb'
|
||||
- 'spec/models/billable_period_spec.rb'
|
||||
- 'spec/models/product_distribution_spec.rb'
|
||||
- 'spec/models/spree/ability_spec.rb'
|
||||
- 'spec/models/spree/product_spec.rb'
|
||||
@@ -307,7 +302,6 @@ Layout/EmptyLinesAroundBlockBody:
|
||||
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only
|
||||
Layout/EmptyLinesAroundClassBody:
|
||||
Exclude:
|
||||
- 'app/controllers/admin/account_controller.rb'
|
||||
- 'app/controllers/admin/cache_settings_controller.rb'
|
||||
- 'app/controllers/admin/enterprise_fees_controller.rb'
|
||||
- 'app/controllers/admin/inventory_items_controller.rb'
|
||||
@@ -358,7 +352,6 @@ Layout/ExtraSpacing:
|
||||
- 'lib/open_food_network/variant_and_line_item_naming.rb'
|
||||
- 'lib/spree/product_filters.rb'
|
||||
- 'lib/tasks/karma.rake'
|
||||
- 'spec/controllers/admin/accounts_and_billing_settings_controller_spec.rb'
|
||||
- 'spec/features/admin/bulk_order_management_spec.rb'
|
||||
- 'spec/features/admin/bulk_product_update_spec.rb'
|
||||
- 'spec/features/admin/orders_spec.rb'
|
||||
@@ -409,7 +402,6 @@ Layout/IndentationConsistency:
|
||||
- 'lib/open_food_network/permissions.rb'
|
||||
- 'spec/controllers/admin/tag_rules_controller_spec.rb'
|
||||
- 'spec/features/consumer/shopping/checkout_spec.rb'
|
||||
- 'spec/helpers/admin/business_model_configuration_helper_spec.rb'
|
||||
- 'spec/models/spree/line_item_spec.rb'
|
||||
- 'spec/models/spree/product_spec.rb'
|
||||
|
||||
@@ -425,7 +417,6 @@ Layout/IndentationWidth:
|
||||
- 'app/serializers/api/admin/for_order_cycle/supplied_product_serializer.rb'
|
||||
- 'app/serializers/api/admin/order_cycle_serializer.rb'
|
||||
- 'spec/features/consumer/shopping/variant_overrides_spec.rb'
|
||||
- 'spec/helpers/admin/business_model_configuration_helper_spec.rb'
|
||||
- 'spec/helpers/groups_helper_spec.rb'
|
||||
- 'spec/lib/open_food_network/enterprise_fee_calculator_spec.rb'
|
||||
- 'spec/lib/open_food_network/order_grouper_spec.rb'
|
||||
@@ -439,7 +430,6 @@ Layout/IndentationWidth:
|
||||
Layout/LeadingCommentSpace:
|
||||
Exclude:
|
||||
- 'Gemfile'
|
||||
- 'app/models/billable_period.rb'
|
||||
- 'app/models/content_configuration.rb'
|
||||
- 'app/models/spree/inventory_unit_decorator.rb'
|
||||
- 'app/models/spree/taxon_decorator.rb'
|
||||
@@ -449,7 +439,6 @@ Layout/LeadingCommentSpace:
|
||||
- 'spec/controllers/spree/api/line_items_controller_spec.rb'
|
||||
- 'spec/features/admin/products_spec.rb'
|
||||
- 'spec/features/admin/reports_spec.rb'
|
||||
- 'spec/jobs/finalize_account_invoices_spec.rb'
|
||||
- 'spec/lib/open_food_network/order_grouper_spec.rb'
|
||||
- 'spec/lib/open_food_network/user_balance_calculator_spec.rb'
|
||||
- 'spec/models/enterprise_spec.rb'
|
||||
@@ -471,7 +460,6 @@ Layout/MultilineBlockLayout:
|
||||
- 'spec/features/admin/variant_overrides_spec.rb'
|
||||
- 'spec/features/consumer/shopping/cart_spec.rb'
|
||||
- 'spec/helpers/enterprises_helper_spec.rb'
|
||||
- 'spec/jobs/update_billable_periods_spec.rb'
|
||||
- 'spec/lib/open_food_network/enterprise_fee_calculator_spec.rb'
|
||||
- 'spec/lib/open_food_network/permissions_spec.rb'
|
||||
- 'spec/lib/open_food_network/user_balance_calculator_spec.rb'
|
||||
@@ -489,7 +477,6 @@ Layout/MultilineBlockLayout:
|
||||
Layout/MultilineHashBraceLayout:
|
||||
Exclude:
|
||||
- 'app/controllers/spree/admin/products_controller_decorator.rb'
|
||||
- 'app/models/billable_period.rb'
|
||||
- 'lib/spree/product_filters.rb'
|
||||
- 'spec/support/request/authentication_workflow.rb'
|
||||
|
||||
@@ -528,7 +515,6 @@ Layout/MultilineOperationIndentation:
|
||||
- 'app/models/producer_property.rb'
|
||||
- 'app/models/spree/ability_decorator.rb'
|
||||
- 'app/models/variant_override_set.rb'
|
||||
- 'lib/open_food_network/accounts_and_billing_settings_validator.rb'
|
||||
- 'lib/open_food_network/order_cycle_permissions.rb'
|
||||
- 'lib/open_food_network/sales_tax_report.rb'
|
||||
- 'lib/open_food_network/users_and_enterprises_report.rb'
|
||||
@@ -551,8 +537,6 @@ Layout/SpaceAfterComma:
|
||||
- 'app/controllers/spree/orders_controller_decorator.rb'
|
||||
- 'app/models/column_preference.rb'
|
||||
- 'lib/discourse/single_sign_on.rb'
|
||||
- 'lib/open_food_network/accounts_and_billing_settings_validator.rb'
|
||||
- 'lib/open_food_network/business_model_configuration_validator.rb'
|
||||
- 'lib/open_food_network/order_cycle_form_applicator.rb'
|
||||
- 'lib/open_food_network/users_and_enterprises_report.rb'
|
||||
- 'spec/controllers/admin/enterprises_controller_spec.rb'
|
||||
@@ -561,7 +545,6 @@ Layout/SpaceAfterComma:
|
||||
- 'spec/features/admin/bulk_product_update_spec.rb'
|
||||
- 'spec/features/admin/customers_spec.rb'
|
||||
- 'spec/features/admin/variant_overrides_spec.rb'
|
||||
- 'spec/jobs/update_account_invoices_spec.rb'
|
||||
- 'spec/lib/open_food_network/group_buy_report_spec.rb'
|
||||
- 'spec/lib/open_food_network/subscription_summary_spec.rb'
|
||||
- 'spec/models/content_configuration_spec.rb'
|
||||
@@ -608,9 +591,6 @@ Layout/SpaceAroundEqualsInParameterDefault:
|
||||
- 'app/models/spree/taxon_decorator.rb'
|
||||
- 'app/models/variant_override_set.rb'
|
||||
- 'lib/discourse/single_sign_on.rb'
|
||||
- 'lib/open_food_network/accounts_and_billing_settings_validator.rb'
|
||||
- 'lib/open_food_network/bill_calculator.rb'
|
||||
- 'lib/open_food_network/business_model_configuration_validator.rb'
|
||||
- 'lib/open_food_network/enterprise_fee_calculator.rb'
|
||||
- 'lib/open_food_network/enterprise_issue_validator.rb'
|
||||
- 'lib/open_food_network/order_cycle_form_applicator.rb'
|
||||
@@ -631,8 +611,6 @@ Layout/SpaceAroundEqualsInParameterDefault:
|
||||
Layout/SpaceAroundOperators:
|
||||
Exclude:
|
||||
- 'app/controllers/checkout_controller.rb'
|
||||
- 'app/helpers/admin/business_model_configuration_helper.rb'
|
||||
- 'app/jobs/update_billable_periods.rb'
|
||||
- 'app/overrides/remove_search_bar.rb'
|
||||
- 'app/overrides/remove_side_bar.rb'
|
||||
- 'app/overrides/replace_shipping_address_form_with_distributor_details.rb'
|
||||
@@ -644,7 +622,6 @@ Layout/SpaceAroundOperators:
|
||||
- 'spec/features/consumer/shopping/checkout_spec.rb'
|
||||
- 'spec/helpers/checkout_helper_spec.rb'
|
||||
- 'spec/helpers/order_cycles_helper_spec.rb'
|
||||
- 'spec/jobs/update_billable_periods_spec.rb'
|
||||
- 'spec/lib/open_food_network/order_grouper_spec.rb'
|
||||
- 'spec/lib/stripe/account_connector_spec.rb'
|
||||
- 'spec/spec_helper.rb'
|
||||
@@ -694,7 +671,6 @@ Layout/SpaceInsideArrayLiteralBrackets:
|
||||
- 'lib/open_food_network/users_and_enterprises_report.rb'
|
||||
- 'spec/controllers/admin/variant_overrides_controller_spec.rb'
|
||||
- 'spec/features/admin/reports_spec.rb'
|
||||
- 'spec/jobs/update_billable_periods_spec.rb'
|
||||
- 'spec/lib/open_food_network/order_grouper_spec.rb'
|
||||
- 'spec/lib/open_food_network/users_and_enterprises_report_spec.rb'
|
||||
- 'spec/models/spree/order_spec.rb'
|
||||
@@ -715,8 +691,6 @@ Layout/SpaceInsideBlockBraces:
|
||||
- 'lib/spree/product_filters.rb'
|
||||
- 'lib/tasks/karma.rake'
|
||||
- 'spec/archive/features/consumer/checkout_spec.rb'
|
||||
- 'spec/controllers/admin/accounts_and_billing_settings_controller_spec.rb'
|
||||
- 'spec/controllers/admin/business_model_configuration_controller_spec.rb'
|
||||
- 'spec/controllers/admin/inventory_items_controller_spec.rb'
|
||||
- 'spec/controllers/admin/tag_rules_controller_spec.rb'
|
||||
- 'spec/controllers/admin/variant_overrides_controller_spec.rb'
|
||||
@@ -732,9 +706,6 @@ Layout/SpaceInsideBlockBraces:
|
||||
- 'spec/helpers/enterprises_helper_spec.rb'
|
||||
- 'spec/helpers/injection_helper_spec.rb'
|
||||
- 'spec/helpers/spree/orders_helper_spec.rb'
|
||||
- 'spec/jobs/finalize_account_invoices_spec.rb'
|
||||
- 'spec/jobs/update_account_invoices_spec.rb'
|
||||
- 'spec/jobs/update_billable_periods_spec.rb'
|
||||
- 'spec/lib/open_food_network/order_cycle_form_applicator_spec.rb'
|
||||
- 'spec/lib/open_food_network/order_grouper_spec.rb'
|
||||
- 'spec/lib/open_food_network/orders_and_fulfillments_report_spec.rb'
|
||||
@@ -767,7 +738,6 @@ Layout/SpaceInsideHashLiteralBraces:
|
||||
- 'app/controllers/spree/admin/line_items_controller_decorator.rb'
|
||||
- 'app/controllers/spree/admin/products_controller_decorator.rb'
|
||||
- 'app/controllers/spree/admin/search_controller_decorator.rb'
|
||||
- 'app/helpers/admin/business_model_configuration_helper.rb'
|
||||
- 'app/helpers/admin/injection_helper.rb'
|
||||
- 'app/helpers/angular_form_builder.rb'
|
||||
- 'app/helpers/injection_helper.rb'
|
||||
@@ -775,9 +745,7 @@ Layout/SpaceInsideHashLiteralBraces:
|
||||
- 'app/helpers/serializer_helper.rb'
|
||||
- 'app/helpers/spree/admin/base_helper_decorator.rb'
|
||||
- 'app/helpers/spree/admin/navigation_helper_decorator.rb'
|
||||
- 'app/jobs/update_billable_periods.rb'
|
||||
- 'app/mailers/spree/base_mailer_decorator.rb'
|
||||
- 'app/models/billable_period.rb'
|
||||
- 'app/models/enterprise.rb'
|
||||
- 'app/models/enterprise_group.rb'
|
||||
- 'app/models/enterprise_relationship.rb'
|
||||
@@ -796,8 +764,6 @@ Layout/SpaceInsideHashLiteralBraces:
|
||||
- 'lib/open_food_network/sales_tax_report.rb'
|
||||
- 'lib/open_food_network/variant_and_line_item_naming.rb'
|
||||
- 'lib/open_food_network/xero_invoices_report.rb'
|
||||
- 'spec/controllers/admin/accounts_and_billing_settings_controller_spec.rb'
|
||||
- 'spec/controllers/admin/business_model_configuration_controller_spec.rb'
|
||||
- 'spec/controllers/admin/enterprises_controller_spec.rb'
|
||||
- 'spec/controllers/admin/manager_invitations_controller_spec.rb'
|
||||
- 'spec/controllers/admin/order_cycles_controller_spec.rb'
|
||||
@@ -816,7 +782,6 @@ Layout/SpaceInsideHashLiteralBraces:
|
||||
- 'spec/controllers/spree/user_sessions_controller_spec.rb'
|
||||
- 'spec/controllers/user_passwords_controller_spec.rb'
|
||||
- 'spec/controllers/user_registrations_controller_spec.rb'
|
||||
- 'spec/features/admin/accounts_and_billing_settings_spec.rb'
|
||||
- 'spec/features/admin/image_settings_spec.rb'
|
||||
- 'spec/features/admin/products_spec.rb'
|
||||
- 'spec/features/admin/reports_spec.rb'
|
||||
@@ -972,7 +937,6 @@ Lint/ShadowingOuterLocalVariable:
|
||||
# Cop supports --auto-correct.
|
||||
Lint/StringConversionInInterpolation:
|
||||
Exclude:
|
||||
- 'app/controllers/admin/accounts_and_billing_settings_controller.rb'
|
||||
- 'app/controllers/enterprises_controller.rb'
|
||||
- 'app/helpers/admin/injection_helper.rb'
|
||||
- 'app/helpers/injection_helper.rb'
|
||||
@@ -1025,8 +989,6 @@ Lint/UnusedMethodArgument:
|
||||
- 'app/helpers/angular_form_helper.rb'
|
||||
- 'app/helpers/order_cycles_helper.rb'
|
||||
- 'app/helpers/spree/base_helper_decorator.rb'
|
||||
- 'app/jobs/finalize_account_invoices.rb'
|
||||
- 'app/jobs/update_account_invoices.rb'
|
||||
- 'app/models/spree/ability_decorator.rb'
|
||||
- 'app/models/spree/product_decorator.rb'
|
||||
- 'lib/open_food_network/enterprise_fee_applicator.rb'
|
||||
@@ -1337,8 +1299,6 @@ Rails/HasAndBelongsToMany:
|
||||
# Include: app/models/**/*.rb
|
||||
Rails/HasManyOrHasOneDependent:
|
||||
Exclude:
|
||||
- 'app/models/account_invoice.rb'
|
||||
- 'app/models/billable_period.rb'
|
||||
- 'app/models/customer.rb'
|
||||
- 'app/models/enterprise.rb'
|
||||
- 'app/models/order_cycle.rb'
|
||||
@@ -1394,8 +1354,6 @@ Rails/OutputSafety:
|
||||
Rails/PluralizationGrammar:
|
||||
Exclude:
|
||||
- 'spec/features/admin/order_cycles_spec.rb'
|
||||
- 'spec/jobs/update_account_invoices_spec.rb'
|
||||
- 'spec/jobs/update_billable_periods_spec.rb'
|
||||
- 'spec/models/order_cycle_spec.rb'
|
||||
- 'spec/models/spree/product_spec.rb'
|
||||
|
||||
@@ -1515,15 +1473,9 @@ Style/BracesAroundHashParameters:
|
||||
- 'app/controllers/checkout_controller.rb'
|
||||
- 'app/controllers/spree/admin/products_controller_decorator.rb'
|
||||
- 'app/controllers/spree/admin/search_controller_decorator.rb'
|
||||
- 'app/helpers/admin/account_helper.rb'
|
||||
- 'app/helpers/admin/business_model_configuration_helper.rb'
|
||||
- 'app/helpers/angular_form_builder.rb'
|
||||
- 'app/helpers/checkout_helper.rb'
|
||||
- 'app/helpers/spree/admin/orders_helper_decorator.rb'
|
||||
- 'app/jobs/finalize_account_invoices.rb'
|
||||
- 'app/jobs/update_account_invoices.rb'
|
||||
- 'app/jobs/update_billable_periods.rb'
|
||||
- 'app/models/billable_period.rb'
|
||||
- 'app/models/exchange.rb'
|
||||
- 'app/models/spree/adjustment_decorator.rb'
|
||||
- 'app/models/spree/line_item_decorator.rb'
|
||||
@@ -1533,8 +1485,6 @@ Style/BracesAroundHashParameters:
|
||||
- 'lib/open_food_network/reports/rule.rb'
|
||||
- 'lib/open_food_network/variant_and_line_item_naming.rb'
|
||||
- 'lib/open_food_network/xero_invoices_report.rb'
|
||||
- 'spec/controllers/admin/accounts_and_billing_settings_controller_spec.rb'
|
||||
- 'spec/controllers/admin/business_model_configuration_controller_spec.rb'
|
||||
- 'spec/controllers/admin/enterprises_controller_spec.rb'
|
||||
- 'spec/controllers/admin/manager_invitations_controller_spec.rb'
|
||||
- 'spec/controllers/admin/order_cycles_controller_spec.rb'
|
||||
@@ -1552,19 +1502,14 @@ Style/BracesAroundHashParameters:
|
||||
- 'spec/controllers/spree/orders_controller_spec.rb'
|
||||
- 'spec/controllers/user_confirmations_controller_spec.rb'
|
||||
- 'spec/controllers/user_registrations_controller_spec.rb'
|
||||
- 'spec/features/admin/accounts_and_billing_settings_spec.rb'
|
||||
- 'spec/features/admin/business_model_configuration_spec.rb'
|
||||
- 'spec/features/admin/order_cycles_spec.rb'
|
||||
- 'spec/features/admin/products_spec.rb'
|
||||
- 'spec/features/admin/reports_spec.rb'
|
||||
- 'spec/features/admin/tax_settings_spec.rb'
|
||||
- 'spec/helpers/order_cycles_helper_spec.rb'
|
||||
- 'spec/jobs/finalize_account_invoices_spec.rb'
|
||||
- 'spec/jobs/update_account_invoices_spec.rb'
|
||||
- 'spec/lib/open_food_network/feature_toggle_spec.rb'
|
||||
- 'spec/lib/open_food_network/order_cycle_form_applicator_spec.rb'
|
||||
- 'spec/lib/open_food_network/subscription_summarizer_spec.rb'
|
||||
- 'spec/models/billable_period_spec.rb'
|
||||
- 'spec/models/product_distribution_spec.rb'
|
||||
- 'spec/models/spree/ability_spec.rb'
|
||||
- 'spec/models/spree/order_spec.rb'
|
||||
@@ -1588,9 +1533,6 @@ Style/CaseEquality:
|
||||
# SupportedStyles: nested, compact
|
||||
Style/ClassAndModuleChildren:
|
||||
Exclude:
|
||||
- 'app/controllers/admin/account_controller.rb'
|
||||
- 'app/controllers/admin/accounts_and_billing_settings_controller.rb'
|
||||
- 'app/controllers/admin/business_model_configuration_controller.rb'
|
||||
- 'app/controllers/admin/cache_settings_controller.rb'
|
||||
- 'app/controllers/spree/store_controller_decorator.rb'
|
||||
- 'app/helpers/angular_form_helper.rb'
|
||||
@@ -1758,7 +1700,6 @@ Style/FormatStringToken:
|
||||
# Configuration parameters: MinBodyLength.
|
||||
Style/GuardClause:
|
||||
Exclude:
|
||||
- 'app/controllers/admin/accounts_and_billing_settings_controller.rb'
|
||||
- 'app/controllers/admin/enterprises_controller.rb'
|
||||
- 'app/controllers/admin/order_cycles_controller.rb'
|
||||
- 'app/controllers/admin/product_import_controller.rb'
|
||||
@@ -1775,8 +1716,6 @@ Style/GuardClause:
|
||||
- 'app/controllers/spree/orders_controller_decorator.rb'
|
||||
- 'app/controllers/spree/paypal_controller_decorator.rb'
|
||||
- 'app/jobs/products_cache_integrity_checker_job.rb'
|
||||
- 'app/jobs/update_account_invoices.rb'
|
||||
- 'app/jobs/update_billable_periods.rb'
|
||||
- 'app/models/enterprise.rb'
|
||||
- 'app/models/enterprise_group.rb'
|
||||
- 'app/models/producer_property.rb'
|
||||
@@ -1786,7 +1725,6 @@ Style/GuardClause:
|
||||
- 'app/models/spree/product_decorator.rb'
|
||||
- 'app/models/spree/user_decorator.rb'
|
||||
- 'lib/discourse/single_sign_on.rb'
|
||||
- 'lib/open_food_network/accounts_and_billing_settings_validator.rb'
|
||||
- 'lib/open_food_network/order_cycle_form_applicator.rb'
|
||||
- 'lib/open_food_network/products_cache.rb'
|
||||
- 'lib/open_food_network/products_renderer.rb'
|
||||
@@ -1805,7 +1743,6 @@ Style/GuardClause:
|
||||
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
|
||||
Style/HashSyntax:
|
||||
Exclude:
|
||||
- 'app/controllers/admin/accounts_and_billing_settings_controller.rb'
|
||||
- 'app/controllers/admin/contents_controller.rb'
|
||||
- 'app/controllers/admin/enterprise_fees_controller.rb'
|
||||
- 'app/controllers/admin/enterprises_controller.rb'
|
||||
@@ -1823,7 +1760,6 @@ Style/HashSyntax:
|
||||
- 'app/controllers/spree/paypal_controller_decorator.rb'
|
||||
- 'app/controllers/spree/store_controller_decorator.rb'
|
||||
- 'app/controllers/user_passwords_controller.rb'
|
||||
- 'app/helpers/admin/account_helper.rb'
|
||||
- 'app/helpers/angular_form_builder.rb'
|
||||
- 'app/helpers/application_helper.rb'
|
||||
- 'app/helpers/checkout_helper.rb'
|
||||
@@ -1832,7 +1768,6 @@ Style/HashSyntax:
|
||||
- 'app/helpers/spree/admin/orders_helper_decorator.rb'
|
||||
- 'app/mailers/enterprise_mailer.rb'
|
||||
- 'app/mailers/spree/user_mailer_decorator.rb'
|
||||
- 'app/models/billable_period.rb'
|
||||
- 'app/models/calculator/flat_percent_per_item.rb'
|
||||
- 'app/models/enterprise.rb'
|
||||
- 'app/models/enterprise_fee.rb'
|
||||
@@ -2090,9 +2025,7 @@ Style/NumericLiterals:
|
||||
Style/NumericPredicate:
|
||||
Exclude:
|
||||
- 'spec/**/*'
|
||||
- 'app/helpers/admin/business_model_configuration_helper.rb'
|
||||
- 'app/helpers/checkout_helper.rb'
|
||||
- 'app/jobs/update_account_invoices.rb'
|
||||
- 'app/models/spree/calculator/flexi_rate_decorator.rb'
|
||||
- 'app/models/spree/line_item_decorator.rb'
|
||||
- 'app/models/spree/order_decorator.rb'
|
||||
@@ -2181,7 +2114,6 @@ Style/RedundantReturn:
|
||||
# Cop supports --auto-correct.
|
||||
Style/RedundantSelf:
|
||||
Exclude:
|
||||
- 'app/models/billable_period.rb'
|
||||
- 'app/models/calculator/flat_percent_per_item.rb'
|
||||
- 'app/models/enterprise.rb'
|
||||
- 'app/models/exchange.rb'
|
||||
@@ -2295,7 +2227,6 @@ Style/StabbyLambdaParentheses:
|
||||
Style/StringLiteralsInInterpolation:
|
||||
Exclude:
|
||||
- 'app/controllers/application_controller.rb'
|
||||
- 'app/jobs/update_billable_periods.rb'
|
||||
- 'lib/discourse/single_sign_on.rb'
|
||||
- 'lib/open_food_network/users_and_enterprises_report.rb'
|
||||
- 'spec/features/admin/bulk_order_management_spec.rb'
|
||||
@@ -2373,12 +2304,9 @@ Style/UnneededCondition:
|
||||
# Cop supports --auto-correct.
|
||||
Style/UnneededInterpolation:
|
||||
Exclude:
|
||||
- 'app/controllers/admin/accounts_and_billing_settings_controller.rb'
|
||||
- 'app/controllers/admin/resource_controller.rb'
|
||||
- 'app/helpers/admin/business_model_configuration_helper.rb'
|
||||
- 'app/helpers/angular_form_builder.rb'
|
||||
- 'app/helpers/injection_helper.rb'
|
||||
- 'app/jobs/update_billable_periods.rb'
|
||||
- 'lib/discourse/single_sign_on.rb'
|
||||
- 'spec/features/admin/bulk_order_management_spec.rb'
|
||||
- 'spec/features/admin/bulk_product_update_spec.rb'
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
angular.module("admin.accounts_and_billing_settings", ["admin.utils"])
|
||||
@@ -1,14 +0,0 @@
|
||||
angular.module("admin.accounts_and_billing_settings").directive "methodSettingsFor", ->
|
||||
template: "<div ng-include='include_html'></div>"
|
||||
restrict: 'A'
|
||||
scope: {
|
||||
enterprise_id: '=methodSettingsFor'
|
||||
}
|
||||
link: (scope, element, attrs) ->
|
||||
scope.include_html = ""
|
||||
|
||||
scope.$watch "enterprise_id", (newVal, oldVal)->
|
||||
if !newVal? || newVal == ""
|
||||
scope.include_html = ""
|
||||
else
|
||||
scope.include_html = "/admin/accounts_and_billing_settings/show_methods?enterprise_id=#{newVal};"
|
||||
@@ -23,8 +23,6 @@
|
||||
//= require angular-rails-templates
|
||||
//= require_tree ../templates/admin
|
||||
//= require ./admin_ofn
|
||||
//= require ./accounts_and_billing_settings/accounts_and_billing_settings
|
||||
//= require ./business_model_configuration/business_model_configuration
|
||||
//= require ./customers/customers
|
||||
//= require ./dropdown/dropdown
|
||||
//= require ./enterprises/enterprises
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
angular.module("admin.businessModelConfiguration", ["admin.utils"])
|
||||
@@ -1,25 +0,0 @@
|
||||
angular.module("admin.businessModelConfiguration").controller "BusinessModelConfigCtrl", ($scope, $filter) ->
|
||||
$scope.turnover = 1000
|
||||
|
||||
$scope.bill = ->
|
||||
return $filter('currency')(0) unless $scope.fixed || $scope.rate
|
||||
Number($scope.fixed) + Number($scope.turnover) * Number($scope.rate)
|
||||
|
||||
$scope.cappedBill = ->
|
||||
return $scope.bill() if !$scope.cap? || Number($scope.cap) == 0
|
||||
Math.min($scope.bill(), Number($scope.cap))
|
||||
|
||||
$scope.finalBill = ->
|
||||
return 0 if Number($scope.turnover) < Number($scope.minBillableTurnover)
|
||||
$scope.cappedBill()
|
||||
|
||||
$scope.capReached = ->
|
||||
return t('no') if !$scope.cap? || Number($scope.cap) == 0
|
||||
if $scope.bill() >= Number($scope.cap) then t('yes') else t('no')
|
||||
|
||||
$scope.includedTax = ->
|
||||
return 0 if !$scope.taxRate? || Number($scope.taxRate) == 0
|
||||
($scope.cappedBill() * Number($scope.taxRate))
|
||||
|
||||
$scope.total = ->
|
||||
$scope.finalBill() + $scope.includedTax()
|
||||
@@ -1,19 +0,0 @@
|
||||
@import "variables";
|
||||
|
||||
.row.invoice_title {
|
||||
margin-bottom: 0px;
|
||||
}
|
||||
|
||||
table.invoice_summary {
|
||||
margin-bottom: 70px;
|
||||
|
||||
tr.total {
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
|
||||
.invoice_title {
|
||||
.balance {
|
||||
color: $spree-green;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
@import "../variables";
|
||||
|
||||
#trial_progress_bar {
|
||||
position: fixed;
|
||||
left: 0px;
|
||||
bottom: 0px;
|
||||
width: 100vw;
|
||||
padding: 8px 10px;
|
||||
font-weight: bold;
|
||||
background-color: $spree-blue;
|
||||
color: white;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
class Admin::AccountController < Spree::Admin::BaseController
|
||||
|
||||
def show
|
||||
@invoices = spree_current_user.account_invoices
|
||||
end
|
||||
end
|
||||
@@ -1,74 +0,0 @@
|
||||
require 'open_food_network/accounts_and_billing_settings_validator'
|
||||
|
||||
class Admin::AccountsAndBillingSettingsController < Spree::Admin::BaseController
|
||||
before_filter :load_distributors, only: [:edit, :update, :start_job]
|
||||
before_filter :load_jobs, only: [:edit, :update, :start_job]
|
||||
before_filter :load_settings, only: [:edit, :update, :start_job]
|
||||
before_filter :require_valid_settings, only: [:update, :start_job]
|
||||
before_filter :require_known_job, only: [:start_job]
|
||||
|
||||
def update
|
||||
Spree::Config.set(params[:settings])
|
||||
flash[:success] = t(:successfully_updated, :resource => t(:billing_and_account_settings))
|
||||
redirect_to_edit
|
||||
end
|
||||
|
||||
def start_job
|
||||
if @update_account_invoices_job || @finalize_account_invoices_job
|
||||
flash[:error] = I18n.t(:accounts_and_billing_task_already_running_error)
|
||||
else
|
||||
new_job = "#{params[:job][:name]}".camelize.constantize.new
|
||||
Delayed::Job.enqueue new_job
|
||||
flash[:success] = I18n.t(:accounts_and_billing_start_task_notice)
|
||||
end
|
||||
|
||||
redirect_to_edit
|
||||
end
|
||||
|
||||
def show_methods
|
||||
@enterprise = Enterprise.find_by_id(params[:enterprise_id])
|
||||
@shipping_methods = @enterprise.shipping_methods
|
||||
@payment_methods = @enterprise.payment_methods
|
||||
render partial: 'method_settings'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def redirect_to_edit
|
||||
redirect_to main_app.edit_admin_accounts_and_billing_settings_path
|
||||
end
|
||||
|
||||
def require_valid_settings
|
||||
render :edit unless @settings.valid?
|
||||
end
|
||||
|
||||
def known_jobs
|
||||
['update_account_invoices', 'finalize_account_invoices']
|
||||
end
|
||||
|
||||
def require_known_job
|
||||
unless known_jobs.include?(params[:job][:name])
|
||||
flash[:error] = "Unknown Task: #{params[:job][:name].to_s}"
|
||||
redirect_to_edit
|
||||
end
|
||||
end
|
||||
|
||||
def load_settings
|
||||
@settings = OpenFoodNetwork::AccountsAndBillingSettingsValidator.new(params[:settings] || {
|
||||
accounts_distributor_id: Spree::Config[:accounts_distributor_id],
|
||||
default_accounts_payment_method_id: Spree::Config[:default_accounts_payment_method_id],
|
||||
default_accounts_shipping_method_id: Spree::Config[:default_accounts_shipping_method_id],
|
||||
auto_update_invoices: Spree::Config[:auto_update_invoices],
|
||||
auto_finalize_invoices: Spree::Config[:auto_finalize_invoices]
|
||||
})
|
||||
end
|
||||
|
||||
def load_distributors
|
||||
@distributors = Enterprise.is_distributor.select([:id, :name])
|
||||
end
|
||||
|
||||
def load_jobs
|
||||
@update_account_invoices_job = Delayed::Job.where("handler LIKE (?)", "%UpdateAccountInvoices%").last
|
||||
@finalize_account_invoices_job = Delayed::Job.where("handler LIKE (?)", "%FinalizeAccountInvoices%").last
|
||||
end
|
||||
end
|
||||
@@ -1,35 +0,0 @@
|
||||
require 'open_food_network/business_model_configuration_validator'
|
||||
|
||||
class Admin::BusinessModelConfigurationController < Spree::Admin::BaseController
|
||||
before_filter :load_settings, only: [:edit, :update]
|
||||
before_filter :require_valid_settings, only: [:update]
|
||||
|
||||
def update
|
||||
Spree::Config.set(params[:settings])
|
||||
flash[:success] = t(:successfully_updated,
|
||||
resource: t('admin.business_model_configuration.edit.business_model_configuration'))
|
||||
redirect_to_edit
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def redirect_to_edit
|
||||
redirect_to main_app.edit_admin_business_model_configuration_path
|
||||
end
|
||||
|
||||
def load_settings
|
||||
@settings = OpenFoodNetwork::BusinessModelConfigurationValidator.new(params[:settings] || {
|
||||
shop_trial_length_days: Spree::Config[:shop_trial_length_days],
|
||||
account_invoices_monthly_fixed: Spree::Config[:account_invoices_monthly_fixed],
|
||||
account_invoices_monthly_rate: Spree::Config[:account_invoices_monthly_rate],
|
||||
account_invoices_monthly_cap: Spree::Config[:account_invoices_monthly_cap],
|
||||
account_invoices_tax_rate: Spree::Config[:account_invoices_tax_rate],
|
||||
minimum_billable_turnover: Spree::Config[:minimum_billable_turnover]
|
||||
|
||||
})
|
||||
end
|
||||
|
||||
def require_valid_settings
|
||||
render :edit unless @settings.valid?
|
||||
end
|
||||
end
|
||||
@@ -64,10 +64,6 @@ module Admin
|
||||
|
||||
attributes = { sells: params[:sells], visible: true }
|
||||
|
||||
if ['own', 'any'].include? params[:sells]
|
||||
attributes[:shop_trial_start_date] = @enterprise.shop_trial_start_date || Time.zone.now
|
||||
end
|
||||
|
||||
if @enterprise.update_attributes(attributes)
|
||||
flash[:success] = I18n.t(:enterprise_register_success_notice, enterprise: @enterprise.name)
|
||||
redirect_to admin_path
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module Api
|
||||
class CustomersController < BaseController
|
||||
def index
|
||||
@customers = current_api_user.customers.of_regular_shops
|
||||
@customers = current_api_user.customers
|
||||
render json: @customers, each_serializer: CustomerSerializer
|
||||
end
|
||||
|
||||
|
||||
@@ -10,10 +10,6 @@ Spree::UsersController.class_eval do
|
||||
def show
|
||||
@orders = @user.orders.where(state: 'complete').order('completed_at desc')
|
||||
@unconfirmed_email = spree_current_user.unconfirmed_email
|
||||
|
||||
return unless Spree::Config.accounts_distributor_id
|
||||
|
||||
@orders = @orders.where('distributor_id != ?', Spree::Config.accounts_distributor_id)
|
||||
end
|
||||
|
||||
# Endpoint for queries to check if a user is already registered
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
module Admin
|
||||
module AccountHelper
|
||||
def invoice_description_for(invoice)
|
||||
month = t(:abbr_month_names, :scope => :date)[invoice.month]
|
||||
year = invoice.year
|
||||
star = invoice.order.nil? || invoice.order.completed? ? "" : "*"
|
||||
"#{month} #{year}#{star}"
|
||||
end
|
||||
|
||||
def invoice_total_for(invoice)
|
||||
invoice.order.andand.display_total || Spree::Money.new(0, { :currency => Spree::Config[:currency] })
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,71 +0,0 @@
|
||||
module Admin
|
||||
module BusinessModelConfigurationHelper
|
||||
def monthly_bill_description
|
||||
plus = monthly_bill_includes_fixed? && monthly_bill_includes_rate? ? " + " : ""
|
||||
ts = trial_description.empty? ? "": " "
|
||||
ms = minimum_description.empty? ? "": " "
|
||||
|
||||
if fixed_description.empty? && rate_description.empty?
|
||||
t(:free).upcase
|
||||
elsif monthly_bill_includes_rate_limits? && monthly_bill_includes_rate? # only care about cap/min-bill-to if there is a rate too
|
||||
"#{trial_description}#{ts}#{fixed_description}#{plus}#{rate_description}#{ms}#{minimum_description}#{cap_description} #{t(:per_month).upcase}#{tax_description.upcase}"
|
||||
else
|
||||
"#{trial_description}#{ts}#{fixed_description}#{plus}#{rate_description} #{t(:per_month).upcase}#{tax_description.upcase}"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def free_use?
|
||||
Spree::Config[:account_invoices_monthly_fixed] == 0 && Spree::Config[:account_invoices_monthly_rate] == 0
|
||||
end
|
||||
|
||||
def fixed_description
|
||||
fixed_amount = Spree::Money.new(Spree::Config[:account_invoices_monthly_fixed], {currency: Spree::Config[:currency]} ).rounded
|
||||
monthly_bill_includes_fixed? ? "#{fixed_amount}" : ""
|
||||
end
|
||||
|
||||
def rate_description
|
||||
percentage = (Spree::Config[:account_invoices_monthly_rate]*100).round(2)
|
||||
monthly_bill_includes_rate? ? t(:percentage_of_sales, percentage: "#{percentage}%").upcase : ""
|
||||
end
|
||||
|
||||
def cap_description
|
||||
cap_amount = Spree::Money.new(Spree::Config[:account_invoices_monthly_cap], { currency: Spree::Config[:currency] }).rounded
|
||||
monthly_bill_includes_cap? ? ", #{t(:capped_at_cap, cap: cap_amount).upcase}" : ""
|
||||
end
|
||||
|
||||
def tax_description
|
||||
Spree::Config[:account_invoices_tax_rate] > 0 ? ", #{t(:plus_tax).upcase}" : ""
|
||||
end
|
||||
|
||||
def trial_description
|
||||
Spree::Config[:shop_trial_length_days] > 0 ? "#{t(:free_trial).upcase} #{t(:then).upcase}" : ""
|
||||
end
|
||||
|
||||
def minimum_description
|
||||
mbt_amount = Spree::Money.new(Spree::Config[:minimum_billable_turnover], { currency: Spree::Config[:currency] }).rounded
|
||||
monthly_bill_includes_min_turnover? ? "#{t(:min_bill_turnover_desc, mbt_amount: mbt_amount).upcase}" : ""
|
||||
end
|
||||
|
||||
def monthly_bill_includes_fixed?
|
||||
Spree::Config[:account_invoices_monthly_fixed] > 0
|
||||
end
|
||||
|
||||
def monthly_bill_includes_rate?
|
||||
Spree::Config[:account_invoices_monthly_rate] > 0
|
||||
end
|
||||
|
||||
def monthly_bill_includes_cap?
|
||||
Spree::Config[:account_invoices_monthly_cap] > 0
|
||||
end
|
||||
|
||||
def monthly_bill_includes_min_turnover?
|
||||
Spree::Config[:minimum_billable_turnover] > 1
|
||||
end
|
||||
|
||||
def monthly_bill_includes_rate_limits?
|
||||
monthly_bill_includes_min_turnover? || monthly_bill_includes_cap?
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,7 +1,5 @@
|
||||
module Admin
|
||||
module InjectionHelper
|
||||
include BusinessModelConfigurationHelper
|
||||
|
||||
def admin_inject_enterprise
|
||||
admin_inject_json_ams "admin.enterprises", "enterprise", @enterprise, Api::Admin::EnterpriseSerializer
|
||||
end
|
||||
@@ -110,10 +108,6 @@ module Admin
|
||||
admin_inject_json_ams_array "admin.orders", "orderCycles", @order_cycles, Api::Admin::BasicOrderCycleSerializer, current_user: spree_current_user
|
||||
end
|
||||
|
||||
def admin_inject_monthly_bill_description
|
||||
render partial: "admin/json/injection_ams", locals: {ngModule: "admin.enterprises", name: "monthlyBillDescription", json: monthly_bill_description.to_json}
|
||||
end
|
||||
|
||||
def admin_inject_spree_api_key
|
||||
render partial: "admin/json/injection_ams", locals: {ngModule: 'admin.indexUtils', name: 'SpreeApiKey', json: "'#{@spree_api_key.to_s}'"}
|
||||
end
|
||||
|
||||
@@ -78,22 +78,6 @@ module EnterprisesHelper
|
||||
link_to_with_icon 'icon-trash', name, url, options
|
||||
end
|
||||
|
||||
def shop_trial_in_progress?(enterprise)
|
||||
!!enterprise.shop_trial_start_date &&
|
||||
(enterprise.shop_trial_start_date + Spree::Config[:shop_trial_length_days].days > Time.zone.now) &&
|
||||
%w(own any).include?(enterprise.sells)
|
||||
end
|
||||
|
||||
def shop_trial_expired?(enterprise)
|
||||
!!enterprise.shop_trial_start_date &&
|
||||
(enterprise.shop_trial_start_date + Spree::Config[:shop_trial_length_days].days <= Time.zone.now) &&
|
||||
%w(own any).include?(enterprise.sells)
|
||||
end
|
||||
|
||||
def remaining_trial_days(enterprise)
|
||||
distance_of_time_in_words(Time.zone.now, enterprise.shop_trial_start_date + Spree::Config[:shop_trial_length_days].days)
|
||||
end
|
||||
|
||||
def order_changes_allowed?
|
||||
current_order.andand.distributor.andand.allow_order_changes?
|
||||
end
|
||||
|
||||
@@ -65,7 +65,7 @@ module InjectionHelper
|
||||
end
|
||||
|
||||
def inject_shops
|
||||
customers = spree_current_user.customers.of_regular_shops
|
||||
customers = spree_current_user.customers
|
||||
shops = Enterprise.where(id: @orders.pluck(:distributor_id).uniq | customers.pluck(:enterprise_id))
|
||||
inject_json_ams "shops", shops.all, Api::ShopForOrdersSerializer
|
||||
end
|
||||
|
||||
@@ -1,110 +0,0 @@
|
||||
# This class is part of the system that charges hubs for using OFN. It does so
|
||||
# by creating orders. These are not orders for food that customers place, but
|
||||
# instead are orders for OFN usage, so to speak. Thus, they're technically not
|
||||
# "shipped" anywhere, so they're just given a default shipping method.
|
||||
#
|
||||
# The "orders" used by this class are not real orders, they are basically
|
||||
# "invoices" that enterprise owners need to pay for use of an open food network
|
||||
# instance. The amount that the enterprise owner is charged is configurable by
|
||||
# the instance, and can be based on a combination of a percentage of their
|
||||
# turnover, fixed fees, caps and floors and trial periods. This "orders" hold
|
||||
# the billing information for a particular enterprise owner for a given month.
|
||||
#
|
||||
# We assign them also a default shipping method because there is a validation
|
||||
# on Spree::Shipment that requires it.
|
||||
class FinalizeAccountInvoices
|
||||
attr_reader :year, :month, :start_date, :end_date
|
||||
|
||||
def initialize(year = nil, month = nil)
|
||||
ref_point = Time.zone.now - 1.month
|
||||
@year = year || ref_point.year
|
||||
@month = month || ref_point.month
|
||||
@start_date = Time.zone.local(@year, @month)
|
||||
@end_date = Time.zone.local(@year, @month) + 1.month
|
||||
end
|
||||
|
||||
def before(job)
|
||||
UpdateBillablePeriods.new(year, month).perform
|
||||
UpdateAccountInvoices.new(year, month).perform
|
||||
end
|
||||
|
||||
def perform
|
||||
return unless settings_are_valid?
|
||||
|
||||
|
||||
invoice_orders = AccountInvoice.where(year: year, month: month).map(&:order)
|
||||
invoice_orders.select{ |order| order.present? && order.completed_at.nil? }.each{ |order| finalize(order) }
|
||||
end
|
||||
|
||||
def finalize(invoice_order)
|
||||
# TODO: When we implement per-customer and/or per-user preferences around shipping and payment methods
|
||||
# we can update these to read from those preferences
|
||||
invoice_order.payments.create(payment_method_id: Spree::Config.default_accounts_payment_method_id, amount: invoice_order.total)
|
||||
invoice_order.update_attribute(:shipping_method_id, Spree::Config.default_accounts_shipping_method_id)
|
||||
while invoice_order.state != "complete"
|
||||
if invoice_order.errors.any?
|
||||
Bugsnag.notify(RuntimeError.new("FinalizeInvoiceError"), {
|
||||
job: "FinalizeAccountInvoices",
|
||||
error: "Cannot finalize invoice due to errors",
|
||||
data: {
|
||||
errors: invoice_order.errors.full_messages
|
||||
}
|
||||
})
|
||||
break
|
||||
else
|
||||
invoice_order.next
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def settings_are_valid?
|
||||
unless end_date <= Time.zone.now
|
||||
Bugsnag.notify(RuntimeError.new("InvalidJobSettings"), {
|
||||
job: "FinalizeAccountInvoices",
|
||||
error: "end_date is in the future",
|
||||
data: {
|
||||
end_date: end_date.in_time_zone.strftime("%F %T"),
|
||||
now: Time.zone.now.strftime("%F %T")
|
||||
}
|
||||
})
|
||||
return false
|
||||
end
|
||||
|
||||
unless @accounts_distributor = Enterprise.find_by_id(Spree::Config.accounts_distributor_id)
|
||||
Bugsnag.notify(RuntimeError.new("InvalidJobSettings"), {
|
||||
job: "FinalizeAccountInvoices",
|
||||
error: "accounts_distributor_id is invalid",
|
||||
data: {
|
||||
accounts_distributor_id: Spree::Config.accounts_distributor_id
|
||||
}
|
||||
})
|
||||
return false
|
||||
end
|
||||
|
||||
unless @accounts_distributor.payment_methods.find_by_id(Spree::Config.default_accounts_payment_method_id)
|
||||
Bugsnag.notify(RuntimeError.new("InvalidJobSettings"), {
|
||||
job: "FinalizeAccountInvoices",
|
||||
error: "default_accounts_payment_method_id is invalid",
|
||||
data: {
|
||||
default_accounts_payment_method_id: Spree::Config.default_accounts_payment_method_id
|
||||
}
|
||||
})
|
||||
return false
|
||||
end
|
||||
|
||||
unless @accounts_distributor.shipping_methods.find_by_id(Spree::Config.default_accounts_shipping_method_id)
|
||||
Bugsnag.notify(RuntimeError.new("InvalidJobSettings"), {
|
||||
job: "FinalizeAccountInvoices",
|
||||
error: "default_accounts_shipping_method_id is invalid",
|
||||
data: {
|
||||
default_accounts_shipping_method_id: Spree::Config.default_accounts_shipping_method_id
|
||||
}
|
||||
})
|
||||
return false
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
end
|
||||
@@ -1,108 +0,0 @@
|
||||
class UpdateAccountInvoices
|
||||
attr_reader :year, :month, :start_date, :end_date
|
||||
|
||||
def initialize(year = nil, month = nil)
|
||||
ref_point = Time.zone.now - 1.day
|
||||
@year = year || ref_point.year
|
||||
@month = month || ref_point.month
|
||||
@start_date = Time.zone.local(@year, @month)
|
||||
@end_date = Time.zone.local(@year, @month) + 1.month
|
||||
@end_date = Time.zone.now.beginning_of_day if start_date == Time.zone.now.beginning_of_month
|
||||
end
|
||||
|
||||
def before(job)
|
||||
UpdateBillablePeriods.new(year, month).perform
|
||||
end
|
||||
|
||||
def perform
|
||||
return unless settings_are_valid?
|
||||
|
||||
account_invoices = AccountInvoice.where(year: year, month: month)
|
||||
account_invoices.each { |account_invoice| update(account_invoice) }
|
||||
end
|
||||
|
||||
def update(account_invoice)
|
||||
current_adjustments = []
|
||||
unless account_invoice.order
|
||||
account_invoice.order = account_invoice.user.orders.new(distributor_id: Spree::Config[:accounts_distributor_id])
|
||||
end
|
||||
|
||||
if account_invoice.order.complete?
|
||||
Bugsnag.notify(RuntimeError.new("InvoiceAlreadyFinalized"), {
|
||||
invoice_order: account_invoice.order.as_json
|
||||
})
|
||||
else
|
||||
billable_periods = account_invoice.billable_periods.order(:enterprise_id, :begins_at).reject{ |bp| bp.bill == 0 }
|
||||
|
||||
if billable_periods.any?
|
||||
oldest_enterprise = billable_periods.first.enterprise
|
||||
address = oldest_enterprise.address.dup
|
||||
first, _space, last = (oldest_enterprise.contact_name || "").partition(' ')
|
||||
address.update_attributes(phone: oldest_enterprise.phone) if oldest_enterprise.phone.present?
|
||||
address.update_attributes(firstname: first, lastname: last) if first.present? && last.present?
|
||||
account_invoice.order.update_attributes(bill_address: address, ship_address: address)
|
||||
end
|
||||
|
||||
billable_periods.each do |billable_period|
|
||||
current_adjustments << billable_period.ensure_correct_adjustment_for(account_invoice.order)
|
||||
end
|
||||
|
||||
account_invoice.save if current_adjustments.any?
|
||||
|
||||
clean_up(account_invoice.order, current_adjustments)
|
||||
end
|
||||
end
|
||||
|
||||
def clean_up(invoice_order, current_adjustments)
|
||||
# Snag and then delete any obsolete adjustments
|
||||
obsolete_adjustments = invoice_order.adjustments.where('source_type = (?) AND id NOT IN (?)', "BillablePeriod", current_adjustments)
|
||||
|
||||
if obsolete_adjustments.any?
|
||||
Bugsnag.notify(RuntimeError.new("Obsolete Adjustments"), {
|
||||
current: current_adjustments.map(&:as_json),
|
||||
obsolete: obsolete_adjustments.map(&:as_json)
|
||||
})
|
||||
|
||||
obsolete_adjustments.destroy_all
|
||||
end
|
||||
|
||||
if current_adjustments.empty?
|
||||
if invoice_order.persisted?
|
||||
Bugsnag.notify(RuntimeError.new("Empty Persisted Invoice"), {
|
||||
invoice_order: invoice_order.as_json
|
||||
})
|
||||
else
|
||||
invoice_order.destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def settings_are_valid?
|
||||
unless end_date <= Time.zone.now
|
||||
Bugsnag.notify(RuntimeError.new("InvalidJobSettings"), {
|
||||
job: "UpdateAccountInvoices",
|
||||
error: "end_date is in the future",
|
||||
data: {
|
||||
end_date: end_date.in_time_zone.strftime("%F %T"),
|
||||
now: Time.zone.now.strftime("%F %T")
|
||||
}
|
||||
})
|
||||
return false
|
||||
end
|
||||
|
||||
unless Enterprise.find_by_id(Spree::Config.accounts_distributor_id)
|
||||
Bugsnag.notify(RuntimeError.new("InvalidJobSettings"), {
|
||||
job: "UpdateAccountInvoices",
|
||||
error: "accounts_distributor_id is invalid",
|
||||
data: {
|
||||
accounts_distributor_id: Spree::Config.accounts_distributor_id
|
||||
}
|
||||
})
|
||||
return false
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
end
|
||||
@@ -1,130 +0,0 @@
|
||||
class UpdateBillablePeriods
|
||||
attr_reader :year, :month, :start_date, :end_date
|
||||
|
||||
def initialize(year = nil, month = nil)
|
||||
ref_point = Time.zone.now - 1.day
|
||||
@year = year || ref_point.year
|
||||
@month = month || ref_point.month
|
||||
@start_date = Time.zone.local(@year, @month)
|
||||
@end_date = Time.zone.local(@year, @month) + 1.month
|
||||
@end_date = Time.zone.now.beginning_of_day if start_date == Time.zone.now.beginning_of_month
|
||||
end
|
||||
|
||||
def perform
|
||||
return unless settings_are_valid?
|
||||
|
||||
job_start_time = Time.zone.now
|
||||
|
||||
enterprises = Enterprise.where('created_at < (?)', end_date).select([:id, :name, :owner_id, :sells, :shop_trial_start_date, :created_at])
|
||||
|
||||
# Cycle through enterprises
|
||||
enterprises.each do |enterprise|
|
||||
start_for_enterprise = [start_date, enterprise.created_at].max
|
||||
end_for_enterprise = [end_date].min # [end_date, enterprise.deleted_at].min
|
||||
|
||||
# Cycle through previous versions of this enterprise
|
||||
versions = enterprise.versions.where('created_at >= (?) AND created_at < (?)', start_for_enterprise, end_for_enterprise).order(:created_at)
|
||||
|
||||
trial_start = enterprise.shop_trial_start_date
|
||||
trial_expiry = enterprise.shop_trial_expiry
|
||||
|
||||
versions.each do |version|
|
||||
begins_at = version.previous.andand.created_at || start_for_enterprise
|
||||
ends_at = version.created_at
|
||||
|
||||
split_for_trial(version.reify, begins_at, ends_at, trial_start, trial_expiry)
|
||||
end
|
||||
|
||||
# Update / create billable_period for current start
|
||||
begins_at = versions.last.andand.created_at || start_for_enterprise
|
||||
ends_at = end_date
|
||||
|
||||
split_for_trial(enterprise, begins_at, ends_at, trial_start, trial_expiry)
|
||||
|
||||
clean_up_untouched_billable_periods_for(enterprise, job_start_time)
|
||||
end
|
||||
end
|
||||
|
||||
def split_for_trial(enterprise, begins_at, ends_at, trial_start, trial_expiry)
|
||||
trial_start = trial_expiry = begins_at-1.day if trial_start.nil? || trial_expiry.nil?
|
||||
|
||||
# If the trial begins after ends_at, create a bill for the entire period
|
||||
# Otherwise, create a normal billable_period from the begins_at until the start of the trial
|
||||
if trial_start > begins_at
|
||||
update_billable_period(enterprise, begins_at, [ends_at, trial_start].min, false)
|
||||
end
|
||||
|
||||
# If all or some of the trial occurs between begins_at and ends_at
|
||||
# Create a trial billable_period from the from begins_at or trial_start, whichever occurs last, until ends_at, or trial_expiry whichever occurs first
|
||||
if trial_expiry >= begins_at && trial_start <= ends_at
|
||||
update_billable_period(enterprise, [trial_start, begins_at].max, [ends_at, trial_expiry].min, true)
|
||||
end
|
||||
|
||||
# If the trial finishes before begins_at, or trial has not been set, create a bill for the entire period
|
||||
# Otherwise, create a normal billable_period from the end of the trial until ends_at
|
||||
if trial_expiry < ends_at
|
||||
update_billable_period(enterprise, [trial_expiry, begins_at].max, ends_at, false)
|
||||
end
|
||||
end
|
||||
|
||||
def update_billable_period(enterprise, begins_at, ends_at, trial)
|
||||
owner_id = enterprise.owner_id
|
||||
sells = enterprise.sells
|
||||
orders = Spree::Order.where('distributor_id = (?) AND completed_at >= (?) AND completed_at < (?)', enterprise.id, begins_at, ends_at)
|
||||
account_invoice = AccountInvoice.find_or_create_by_user_id_and_year_and_month(owner_id, begins_at.year, begins_at.month)
|
||||
|
||||
billable_period = BillablePeriod.where(account_invoice_id: account_invoice.id, begins_at: begins_at, enterprise_id: enterprise.id).first
|
||||
|
||||
unless account_invoice.order.andand.complete?
|
||||
billable_period ||= BillablePeriod.new(account_invoice_id: account_invoice.id, begins_at: begins_at, enterprise_id: enterprise.id)
|
||||
billable_period.update_attributes({
|
||||
ends_at: ends_at,
|
||||
sells: sells,
|
||||
trial: trial,
|
||||
owner_id: owner_id,
|
||||
turnover: orders.sum(&:total)
|
||||
})
|
||||
end
|
||||
|
||||
billable_period.touch
|
||||
end
|
||||
|
||||
def clean_up_untouched_billable_periods_for(enterprise, job_start_time)
|
||||
# Snag and then delete any BillablePeriods which overlap
|
||||
obsolete_billable_periods = enterprise.billable_periods.where('ends_at > (?) AND begins_at < (?) AND billable_periods.updated_at < (?)', start_date, end_date, job_start_time)
|
||||
|
||||
if obsolete_billable_periods.any?
|
||||
current_billable_periods = enterprise.billable_periods.where('ends_at >= (?) AND begins_at <= (?) AND billable_periods.updated_at > (?)', start_date, end_date, job_start_time)
|
||||
|
||||
Delayed::Worker.logger.info "#{enterprise.name} #{start_date.strftime("%F %T")} #{job_start_time.strftime("%F %T")}"
|
||||
Delayed::Worker.logger.info "#{obsolete_billable_periods.first.updated_at.strftime("%F %T")}"
|
||||
|
||||
Bugsnag.notify(RuntimeError.new("Obsolete BillablePeriods"), {
|
||||
current: current_billable_periods.map(&:as_json),
|
||||
obsolete: obsolete_billable_periods.map(&:as_json)
|
||||
})
|
||||
end
|
||||
|
||||
obsolete_billable_periods.includes({ account_invoice: :order}).
|
||||
where('spree_orders.state <> \'complete\' OR account_invoices.order_id IS NULL').
|
||||
each(&:delete)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def settings_are_valid?
|
||||
unless end_date <= Time.zone.now
|
||||
Bugsnag.notify(RuntimeError.new("InvalidJobSettings"), {
|
||||
job: "UpdateBillablePeriods",
|
||||
error: "end_date is in the future",
|
||||
data: {
|
||||
end_date: end_date.in_time_zone.strftime("%F %T"),
|
||||
now: Time.zone.now.strftime("%F %T")
|
||||
}
|
||||
})
|
||||
return false
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
end
|
||||
@@ -1,6 +0,0 @@
|
||||
class AccountInvoice < ActiveRecord::Base
|
||||
belongs_to :user, class_name: "Spree::User"
|
||||
belongs_to :order, class_name: "Spree::Order"
|
||||
attr_accessible :user_id, :order_id, :issued_at, :month, :year
|
||||
has_many :billable_periods
|
||||
end
|
||||
@@ -1,77 +0,0 @@
|
||||
require 'open_food_network/bill_calculator'
|
||||
|
||||
class BillablePeriod < ActiveRecord::Base
|
||||
belongs_to :enterprise
|
||||
belongs_to :owner, class_name: 'Spree::User'
|
||||
belongs_to :account_invoice
|
||||
has_one :adjustment, :as => :source, class_name: "Spree::Adjustment" #, :dependent => :destroy
|
||||
|
||||
default_scope where(deleted_at: nil)
|
||||
|
||||
def display_turnover
|
||||
Spree::Money.new(turnover, {currency: Spree::Config[:currency]})
|
||||
end
|
||||
|
||||
def display_bill
|
||||
Spree::Money.new(bill, {currency: Spree::Config[:currency]})
|
||||
end
|
||||
|
||||
def bill
|
||||
return 0 if trial?
|
||||
return 0 unless ['own', 'any'].include?(sells)
|
||||
OpenFoodNetwork::BillCalculator.new(turnover: turnover).bill
|
||||
end
|
||||
|
||||
def label
|
||||
enterprise_version = enterprise.version_at(begins_at)
|
||||
category = enterprise_version.category.to_s.titleize
|
||||
category += (trial ? " #{I18n.t(:trial)}" : "")
|
||||
|
||||
"#{enterprise_version.name} (#{category})"
|
||||
end
|
||||
|
||||
def adjustment_label
|
||||
begins = begins_at.in_time_zone.strftime("%d/%m/%y")
|
||||
ends = ends_at.in_time_zone.strftime("%d/%m/%y")
|
||||
|
||||
"#{label} [#{begins} - #{ends}]"
|
||||
end
|
||||
|
||||
def delete
|
||||
self.update_column(:deleted_at, Time.zone.now)
|
||||
end
|
||||
|
||||
def ensure_correct_adjustment_for(invoice)
|
||||
if adjustment
|
||||
# adjustment.originator = enterprise.package
|
||||
adjustment.adjustable = invoice
|
||||
adjustment.update_attributes( label: adjustment_label, amount: bill )
|
||||
else
|
||||
self.adjustment = invoice.adjustments.new( adjustment_attrs, :without_protection => true )
|
||||
end
|
||||
|
||||
if Spree::Config.account_invoices_tax_rate > 0
|
||||
adjustment.set_included_tax! Spree::Config.account_invoices_tax_rate
|
||||
else
|
||||
adjustment.set_included_tax! 0
|
||||
end
|
||||
|
||||
adjustment
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def adjustment_attrs
|
||||
# We should ultimately have an EnterprisePackage model, which holds all info about shop type, producer, trials, etc.
|
||||
# It should also implement a calculator that we can use here by specifying the package as the originator of the
|
||||
# adjustment, meaning that adjustments are created and updated using Spree's existing architecture.
|
||||
|
||||
{ label: adjustment_label,
|
||||
amount: bill,
|
||||
source: self,
|
||||
originator: nil, # enterprise.package
|
||||
mandatory: true,
|
||||
state: 'closed'
|
||||
}
|
||||
end
|
||||
end
|
||||
@@ -23,11 +23,6 @@ class Customer < ActiveRecord::Base
|
||||
|
||||
scope :of, ->(enterprise) { where(enterprise_id: enterprise) }
|
||||
|
||||
scope :of_regular_shops, lambda {
|
||||
next scoped unless Spree::Config.accounts_distributor_id
|
||||
where('enterprise_id <> ?', Spree::Config.accounts_distributor_id)
|
||||
}
|
||||
|
||||
before_create :associate_user
|
||||
|
||||
private
|
||||
|
||||
@@ -37,7 +37,6 @@ class Enterprise < ActiveRecord::Base
|
||||
has_many :distributor_shipping_methods, foreign_key: :distributor_id
|
||||
has_many :shipping_methods, through: :distributor_shipping_methods
|
||||
has_many :customers
|
||||
has_many :billable_periods
|
||||
has_many :inventory_items
|
||||
has_many :tag_rules
|
||||
has_one :stripe_account, dependent: :destroy
|
||||
@@ -322,10 +321,6 @@ class Enterprise < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def shop_trial_expiry
|
||||
shop_trial_start_date.andand + Spree::Config[:shop_trial_length_days].days
|
||||
end
|
||||
|
||||
def can_invoice?
|
||||
abn.present?
|
||||
end
|
||||
|
||||
@@ -11,7 +11,6 @@ module Spree
|
||||
belongs_to :tax_rate, foreign_key: 'originator_id', conditions: "spree_adjustments.originator_type = 'Spree::TaxRate'"
|
||||
|
||||
scope :enterprise_fee, where(originator_type: 'EnterpriseFee')
|
||||
scope :billable_period, where(source_type: 'BillablePeriod')
|
||||
scope :admin, where(source_type: nil, originator_type: nil)
|
||||
scope :included_tax, where(originator_type: 'Spree::TaxRate', adjustable_type: 'Spree::LineItem')
|
||||
|
||||
|
||||
@@ -20,21 +20,6 @@ Spree::AppConfiguration.class_eval do
|
||||
preference :products_require_tax_category, :boolean, default: false
|
||||
preference :shipping_tax_rate, :decimal, default: 0
|
||||
|
||||
# Accounts & Billing Preferences
|
||||
preference :accounts_distributor_id, :integer, default: nil
|
||||
preference :default_accounts_payment_method_id, :integer, default: nil
|
||||
preference :default_accounts_shipping_method_id, :integer, default: nil
|
||||
preference :auto_update_invoices, :boolean, default: false
|
||||
preference :auto_finalize_invoices, :boolean, default: false
|
||||
|
||||
# Business Model Configuration
|
||||
preference :account_invoices_monthly_fixed, :decimal, default: 0
|
||||
preference :account_invoices_monthly_rate, :decimal, default: 0
|
||||
preference :account_invoices_monthly_cap, :decimal, default: 0
|
||||
preference :account_invoices_tax_rate, :decimal, default: 0
|
||||
preference :shop_trial_length_days, :integer, default: 30
|
||||
preference :minimum_billable_turnover, :integer, default: 0
|
||||
|
||||
# Monitoring
|
||||
preference :last_job_queue_heartbeat_at, :string, default: nil
|
||||
|
||||
|
||||
@@ -309,14 +309,9 @@ Spree::Order.class_eval do
|
||||
not line_items.with_tax.empty?
|
||||
end
|
||||
|
||||
def account_invoice?
|
||||
distributor_id == Spree::Config.accounts_distributor_id
|
||||
end
|
||||
|
||||
# Overrride of Spree method, that allows us to send separate confirmation emails to user and shop owners
|
||||
# And separately, to skip sending confirmation email completely for user invoice orders
|
||||
def deliver_order_confirmation_email
|
||||
unless account_invoice? || subscription.present?
|
||||
unless subscription.present?
|
||||
Delayed::Job.enqueue ConfirmOrderJob.new(id)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,8 +7,6 @@ Spree.user_class.class_eval do
|
||||
has_many :enterprises, through: :enterprise_roles
|
||||
has_many :owned_enterprises, class_name: 'Enterprise', foreign_key: :owner_id, inverse_of: :owner
|
||||
has_many :owned_groups, class_name: 'EnterpriseGroup', foreign_key: :owner_id, inverse_of: :owner
|
||||
has_many :account_invoices
|
||||
has_many :billable_periods, foreign_key: :owner_id, inverse_of: :owner
|
||||
has_many :customers
|
||||
has_many :credit_cards
|
||||
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
// insert_bottom "[data-hook='admin_configurations_sidebar_menu']"
|
||||
|
||||
%li
|
||||
= link_to t('admin.accounts_and_billing_settings.edit.accounts_and_billing'), main_app.edit_admin_accounts_and_billing_settings_path
|
||||
@@ -1,4 +0,0 @@
|
||||
// insert_bottom "[data-hook='admin_configurations_sidebar_menu']"
|
||||
|
||||
%li
|
||||
= link_to t('admin.business_model_configuration.edit.business_model_configuration'), main_app.edit_admin_business_model_configuration_path
|
||||
@@ -1,47 +0,0 @@
|
||||
- content_for :page_title do
|
||||
= t(:account)
|
||||
|
||||
- if @invoices.empty?
|
||||
%h4= t(:no_invoices_to_display)
|
||||
|
||||
- @invoices.order('year DESC, month DESC').each do |invoice|
|
||||
.row.invoice_title
|
||||
.two.columns.alpha
|
||||
%h4= invoice_description_for(invoice)
|
||||
.two.columns.text-right
|
||||
%h5
|
||||
- if invoice.order.andand.complete?
|
||||
%a{ href: print_admin_order_url(invoice.order), :target => "_blank"}
|
||||
%i.icon-print
|
||||
= t(:print)
|
||||
- else
|
||||
|
||||
.ten.columns
|
||||
|
||||
.two.columns.omega.text-right
|
||||
%h4.balance= invoice_total_for(invoice)
|
||||
%table.invoice_summary
|
||||
%col{ width: '25%' }
|
||||
%col{ width: '62.5%' }
|
||||
%col{ width: '12.5%' }
|
||||
%thead
|
||||
%th= t('admin.date')
|
||||
%th= t(:description)
|
||||
%th= t(:charge)
|
||||
- if order = invoice.order
|
||||
- invoice.billable_periods.select{ |bp| bp.adjustment.andand.amount.andand > 0}.each do |billable_period|
|
||||
%tr
|
||||
%td.text-center= "#{billable_period.begins_at.strftime("%d/%m/%Y")}"
|
||||
%td= billable_period.label
|
||||
-# Using amount from the actual adjustment on the order here so that we avoid recalculating the bill
|
||||
-# at a future date with different settings to those used at the time the invoice was finalized
|
||||
%td.text-right= billable_period.adjustment.display_amount
|
||||
- order.adjustments.where('source_type <> (?)', "BillablePeriod").reject{ |a| a.amount == 0 }.each do |adjustment|
|
||||
%tr
|
||||
%td.text-center
|
||||
%td= adjustment.label
|
||||
%td.text-right= adjustment.display_amount
|
||||
%tr.total
|
||||
%td.text-center
|
||||
%td= t(:total).upcase
|
||||
%td.text-right= invoice_total_for(invoice)
|
||||
@@ -1,10 +0,0 @@
|
||||
.row
|
||||
.six.columns.alpha
|
||||
.field
|
||||
= label :settings, :default_accounts_payment_method_id, t('.default_accounts_payment_method')
|
||||
= collection_select(:settings, :default_accounts_payment_method_id, @payment_methods, :id, :name, { include_blank: true, selected: Spree::Config.default_accounts_payment_method_id}, { class: "select2 fullwidth" })
|
||||
|
||||
.six.columns.omega
|
||||
.field
|
||||
= label :settings, :default_accounts_shipping_method_id, t('.default_accounts_shipping_method')
|
||||
= collection_select(:settings, :default_accounts_shipping_method_id, @shipping_methods, :id, :name, { include_blank: true, selected: Spree::Config.default_accounts_shipping_method_id}, { class: "select2 fullwidth" })
|
||||
@@ -1,94 +0,0 @@
|
||||
= render :partial => 'spree/admin/shared/configuration_menu'
|
||||
|
||||
- content_for :page_title do
|
||||
= t('.accounts_and_billing')
|
||||
|
||||
= render 'spree/shared/error_messages', target: @settings
|
||||
|
||||
-# - month_options = (0...12).map { |i| Time.zone.now.beginning_of_month - i.months }.map{ |t| [t.strftime("%b %Y"), t.strftime("%b %Y %z")]}
|
||||
|
||||
%fieldset.no-border-bottom
|
||||
%legend
|
||||
= t('.admin_settings')
|
||||
= form_for @settings, as: :settings, url: main_app.admin_accounts_and_billing_settings_path, :method => :put do |f|
|
||||
.row{ ng: { app: 'admin.accounts_and_billing_settings' } }
|
||||
.twelve.columns.alpha.omega
|
||||
.field
|
||||
= f.label :accounts_distributor_id, t('.accounts_administration_distributor')
|
||||
= f.collection_select(:accounts_distributor_id, @distributors, :id, :name, { include_blank: true }, { class: "select2 fullwidth", 'watch-value-as' => "enterprise_id"})
|
||||
|
||||
= f.hidden_field :default_accounts_payment_method_id, value: ''
|
||||
= f.hidden_field :default_accounts_shipping_method_id, value: ''
|
||||
%div{ 'method-settings-for' => 'enterprise_id' }
|
||||
|
||||
.row
|
||||
.six.columns.alpha
|
||||
%fieldset.no-border-bottom
|
||||
%legend
|
||||
= t('.update_invoice')
|
||||
= f.check_box :auto_update_invoices
|
||||
= f.label :auto_update_invoices, t('.auto_update_invoices')
|
||||
|
||||
.six.columns.omega
|
||||
%fieldset.no-border-bottom
|
||||
%legend
|
||||
= t('.finalise_invoice')
|
||||
= f.check_box :auto_finalize_invoices
|
||||
= f.label :auto_finalize_invoices, t('.auto_finalise_invoices')
|
||||
|
||||
.row
|
||||
.twelve.columns.alpha.omega.form-buttons{"data-hook" => "buttons"}
|
||||
= button t(:update), 'icon-refresh', value: "update"
|
||||
|
||||
%fieldset.no-border-bottom
|
||||
%legend
|
||||
=t('.manually_run_task')
|
||||
.row
|
||||
.six.columns.alpha.step.text-center
|
||||
.form-buttons{"data-hook" => "buttons"}
|
||||
= link_to_with_icon "icon-undo", t('.update_user_invoices'),
|
||||
main_app.start_job_admin_accounts_and_billing_settings_path(job: { name: "update_account_invoices" }),
|
||||
class: "button fullwidth"
|
||||
|
||||
%br
|
||||
|
||||
- if @update_account_invoices_job
|
||||
%p.text-center
|
||||
- if @update_account_invoices_job.run_at < Time.zone.now
|
||||
= t(:in_progress)
|
||||
%br
|
||||
= t(:started_at)
|
||||
- else
|
||||
%strong
|
||||
= t(:queued)
|
||||
%br
|
||||
= t(:scheduled_for)
|
||||
= @update_account_invoices_job.run_at
|
||||
- else
|
||||
%p.explanation
|
||||
= t('.update_user_invoice_explained')
|
||||
|
||||
.six.columns.omega.step.text-center
|
||||
.form-buttons{"data-hook" => "buttons"}
|
||||
=link_to_with_icon "icon-ok-sign", t('.finalise_user_invoices'),
|
||||
main_app.start_job_admin_accounts_and_billing_settings_path(job: { name: "finalize_account_invoices" }),
|
||||
class: "button fullwidth"
|
||||
|
||||
%br
|
||||
|
||||
- if @finalize_account_invoices_job
|
||||
%p.text-center
|
||||
- if @finalize_account_invoices_job.run_at < Time.zone.now
|
||||
%strong
|
||||
= t(:in_progress)
|
||||
%br
|
||||
= t(:started_at)
|
||||
- else
|
||||
%strong
|
||||
= t(:queued)
|
||||
%br
|
||||
= t(:scheduled_for)
|
||||
= @finalize_account_invoices_job.run_at
|
||||
- else
|
||||
%p.explanation
|
||||
= t('.finalise_user_invoice_explained')
|
||||
@@ -1,104 +0,0 @@
|
||||
= render :partial => 'spree/admin/shared/configuration_menu'
|
||||
|
||||
- content_for :app_wrapper_attrs do
|
||||
= "ng-app='admin.businessModelConfiguration'"
|
||||
|
||||
- content_for :page_title do
|
||||
%h1.page-title= t('.business_model_configuration')
|
||||
%a{ 'ofn-with-tip' => t('.business_model_configuration_tip') }
|
||||
= t('admin.whats_this')
|
||||
|
||||
= render 'spree/shared/error_messages', target: @settings
|
||||
|
||||
.row{ ng: { controller: "BusinessModelConfigCtrl" } }
|
||||
.five.columns.omega
|
||||
%fieldset.no-border-bottom
|
||||
%legend=t('.bill_calculation_settings')
|
||||
%p
|
||||
= t('.bill_calculation_settings_tip')
|
||||
%br
|
||||
= form_for @settings, as: :settings, url: main_app.admin_business_model_configuration_path, :method => :put do |f|
|
||||
.row
|
||||
.three.columns.alpha
|
||||
= f.label :shop_trial_length_days, t('.shop_trial_length')
|
||||
%span.icon-question-sign{'ofn-with-tip' => t('.shop_trial_length_tip')}
|
||||
.two.columns.omega
|
||||
= f.number_field :shop_trial_length_days, min: 0.0, step: 1.0, class: "fullwidth"
|
||||
.row
|
||||
.three.columns.alpha
|
||||
= f.label :account_invoices_monthly_fixed, t('.fixed_monthly_charge')
|
||||
%span.icon-question-sign{'ofn-with-tip' => t('.fixed_monthly_charge_tip')}
|
||||
.two.columns.omega
|
||||
.input-symbol.before
|
||||
%span= Spree::Money.currency_symbol
|
||||
= f.number_field :account_invoices_monthly_fixed, min: 0.0, class: "fullwidth", 'watch-value-as' => 'fixed'
|
||||
.row
|
||||
.three.columns.alpha
|
||||
= f.label :account_invoices_monthly_rate, t('.percentage_of_turnover')
|
||||
%span.icon-question-sign{'ofn-with-tip' => t('.percentage_of_turnover_tip')}
|
||||
.two.columns.omega
|
||||
= f.number_field :account_invoices_monthly_rate, min: 0.0, max: 1.0, step: 0.01, class: "fullwidth", 'watch-value-as' => 'rate'
|
||||
.row
|
||||
.three.columns.alpha
|
||||
= f.label :account_invoices_monthly_cap, t('.monthly_cap_excl_tax')
|
||||
%span.icon-question-sign{'ofn-with-tip' => t('.monthly_cap_excl_tax_tip')}
|
||||
.two.columns.omega
|
||||
.input-symbol.before
|
||||
%span= Spree::Money.currency_symbol
|
||||
= f.number_field :account_invoices_monthly_cap, min: 0.0, class: "fullwidth", 'watch-value-as' => 'cap'
|
||||
.row
|
||||
.three.columns.alpha
|
||||
= f.label :account_invoices_tax_rate, t('.tax_rate')
|
||||
%span.icon-question-sign{'ofn-with-tip' => t('.tax_rate_tip')}
|
||||
.two.columns.omega
|
||||
= f.number_field :account_invoices_tax_rate, min: 0.0, max: 1.0, step: 0.01, class: "fullwidth", 'watch-value-as' => 'taxRate'
|
||||
.row
|
||||
.three.columns.alpha
|
||||
= f.label :minimum_billable_turnover, t('.minimum_monthly_billable_turnover')
|
||||
%span.icon-question-sign{'ofn-with-tip' => t('.minimum_monthly_billable_turnover_tip')}
|
||||
.two.columns.omega
|
||||
.input-symbol.before
|
||||
%span= Spree::Money.currency_symbol
|
||||
= f.number_field :minimum_billable_turnover, min: 0, class: "fullwidth", 'watch-value-as' => 'minBillableTurnover'
|
||||
|
||||
.row
|
||||
.five.columns.alpha.omega.form-buttons{"data-hook" => "buttons"}
|
||||
= button t(:update), 'icon-refresh', value: "update"
|
||||
|
||||
.two.columns
|
||||
|
||||
|
||||
.five.columns.alpha
|
||||
%fieldset.no-border-bottom
|
||||
%legend= t('.example_bill_calculator')
|
||||
%p
|
||||
= t('.example_bill_calculator_legend')
|
||||
%br
|
||||
.row
|
||||
.three.columns.alpha
|
||||
= label_tag :turnover, t('.example_monthly_turnover')
|
||||
%span.icon-question-sign{'ofn-with-tip' => t('.example_monthly_turnover_tip')}
|
||||
.two.columns.omega
|
||||
.input-symbol.before
|
||||
%span= Spree::Money.currency_symbol
|
||||
%input.fullwidth{ id: 'turnover', type: "number", ng: { model: 'turnover' } }
|
||||
.row
|
||||
.three.columns.alpha
|
||||
= label_tag :cap_reached, t('.cap_reached?')
|
||||
%span.icon-question-sign{'ofn-with-tip' => t('.cap_reached?_tip')}
|
||||
.two.columns.omega
|
||||
%input.fullwidth{ id: 'cap_reached', type: "text", readonly: true, ng: { value: 'capReached()' } }
|
||||
.row
|
||||
.three.columns.alpha
|
||||
= label_tag :included_tax, t('.included_tax')
|
||||
%span.icon-question-sign{'ofn-with-tip' => t('.included_tax_tip')}
|
||||
.two.columns.omega
|
||||
%span= Spree::Money.currency_symbol
|
||||
%input.fullwidth{ id: 'included_tax', type: "text", readonly: true, ng: { value: 'includedTax()' } }
|
||||
.row
|
||||
.three.columns.alpha
|
||||
= label_tag :total_incl_tax, t('.total_monthly_bill_incl_tax')
|
||||
%span.icon-question-sign{'ofn-with-tip' => t('.total_monthly_bill_incl_tax_tip')}
|
||||
.two.columns.omega
|
||||
%span= Spree::Money.currency_symbol
|
||||
%input.fullwidth{ id: 'total_incl_tax', type: "text", readonly: true, ng: { value: 'total()' } }
|
||||
@@ -1,5 +1,4 @@
|
||||
= admin_inject_enterprise
|
||||
= admin_inject_monthly_bill_description
|
||||
|
||||
= form_for @enterprise, url: main_app.register_admin_enterprise_path(@enterprise),
|
||||
html: { name: "change_type", id: "change_type", novalidate: true, "ng-app" => "admin.enterprises", "ng-controller"=> 'changeTypeFormCtrl' } do |change_type_form|
|
||||
@@ -43,12 +42,6 @@
|
||||
%p.description
|
||||
= t('.producer_hub_description_text')
|
||||
|
||||
-# %p.description
|
||||
-# Test out having your own shopfront with full access to all Shopfront features for 30 days.
|
||||
-# %br
|
||||
-# %br
|
||||
-# At the end of your trial, there is a one-off $200 fee to fully activate your account. Then you will be billed for 2% of your actual transactions, capped at $50 a month (so if you don’t sell anything you don’t pay anything, but you never pay more than $50 a month).
|
||||
|
||||
- else
|
||||
.two.columns.alpha
|
||||
|
||||
@@ -77,14 +70,7 @@
|
||||
.sixteen.columns.alpha
|
||||
%span.error{ ng: { show: "(change_type.sells.$error.required || change_type.sells.$error.pattern) && submitted" } }
|
||||
= t('.choose_option')
|
||||
- if @enterprise.sells == 'unspecified' && @enterprise.shop_trial_start_date.nil?
|
||||
-if free_use?
|
||||
%input.button.big{ type: 'submit', value: t(:select_continue), ng: { click: "submit(change_type)" } }
|
||||
- else
|
||||
- trial_length = Spree::Config[:shop_trial_length_days]
|
||||
%input.button.big{ type: 'submit', value: "Start #{trial_length}-Day Shop Trial", ng: { click: "submit(change_type)", show: "sells=='own' || sells=='any'" } }
|
||||
%input.button.big{ type: 'submit', value: t(:select_continue), ng: { click: "submit(change_type)", hide: "sells=='own' || sells=='any'" } }
|
||||
- elsif @enterprise.sells == 'unspecified'
|
||||
- if @enterprise.sells == 'unspecified'
|
||||
%input.button.big{ type: 'submit', value: t(:select_continue), ng: { click: "submit(change_type)" } }
|
||||
- else
|
||||
%input.button.big{ type: 'submit', value: t('.change_now'), ng: { click: "submit(change_type)" } }
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
- modal_message = t('js.admin.enterprise_limit_reached', contact_email: ContentConfig.footer_email)
|
||||
= button_link_to t('.new_enterprise'), button_href, icon: 'icon-plus', id: 'admin_new_enterprise_link', 'enterprise-limit' => !spree_current_user.can_own_more_enterprises?, 'modal-message' => modal_message
|
||||
|
||||
= admin_inject_monthly_bill_description
|
||||
= admin_inject_column_preferences module: 'admin.enterprises', action: "enterprises_index"
|
||||
|
||||
= render 'admin/shared/enterprises_sub_menu'
|
||||
|
||||
@@ -19,9 +19,6 @@
|
||||
.small-12.medium-10.medium-offset-1.columns.text-center
|
||||
%h2
|
||||
= t :shops_signup_pricing
|
||||
-# %p.text-big
|
||||
-# If there is a time-sensitive offer you can write it here, e.g.
|
||||
-# Sign up before 30th June for an extra month free!
|
||||
%br
|
||||
= ContentConfig.hub_signup_pricing_table_html.html_safe
|
||||
|
||||
|
||||
@@ -89,5 +89,3 @@
|
||||
%a.button.bottom{href: main_app.admin_order_cycles_path}
|
||||
= t "manage_order_cycles"
|
||||
%span.icon-arrow-right
|
||||
|
||||
= render 'spree/admin/shared/trial_progress_bar', enterprise: @enterprise
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
- if enterprise
|
||||
-if shop_trial_in_progress?(enterprise)
|
||||
#trial_progress_bar
|
||||
= "#{t(:shop_trial_expires_in)} #{remaining_trial_days(enterprise)}."
|
||||
-elsif shop_trial_expired?(enterprise)
|
||||
#trial_progress_bar
|
||||
= t(:shop_trial_expired_notice)
|
||||
@@ -1,11 +0,0 @@
|
||||
Spree::Core::Engine.config.to_prepare do
|
||||
if Spree.user_class
|
||||
Spree.user_class.class_eval do
|
||||
|
||||
# Override of spree method to ignore orders associated with account_invoices
|
||||
def last_incomplete_spree_order
|
||||
spree_orders.incomplete.where("id NOT IN (?)", account_invoices.map(&:order_id)).order('created_at DESC').first
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -202,17 +202,9 @@ en:
|
||||
confirm_resend_order_confirmation: "Are you sure you want to resend the order confirmation email?"
|
||||
must_have_valid_business_number: "%{enterprise_name} must have a valid ABN before invoices can be sent."
|
||||
invoice: "Invoice"
|
||||
percentage_of_sales: "%{percentage} of sales"
|
||||
capped_at_cap: "capped at %{cap}"
|
||||
per_month: "per month"
|
||||
free: "free"
|
||||
free_trial: "free trial"
|
||||
plus_tax: "plus GST"
|
||||
min_bill_turnover_desc: "once turnover exceeds %{mbt_amount}"
|
||||
more: "More"
|
||||
say_no: "No"
|
||||
say_yes: "Yes"
|
||||
then: then
|
||||
ongoing: Ongoing
|
||||
bill_address: Billing Address
|
||||
ship_address: Shipping Address
|
||||
@@ -348,28 +340,6 @@ en:
|
||||
unsaved_confirm_leave: "There are unsaved changed on this page. Continue without saving?"
|
||||
unsaved_changes: "You have unsaved changes"
|
||||
|
||||
accounts_and_billing_settings:
|
||||
method_settings:
|
||||
default_accounts_payment_method: "Default Accounts Payment Method"
|
||||
default_accounts_shipping_method: "Default Accounts Shipping Method"
|
||||
edit:
|
||||
accounts_and_billing: "Accounts & Billing"
|
||||
accounts_administration_distributor: "Accounts Administration Distributor"
|
||||
admin_settings: "Settings"
|
||||
update_invoice: "Update Invoices"
|
||||
auto_update_invoices: "Auto-update invoices nightly at 1:00am"
|
||||
finalise_invoice: "Finalise Invoices"
|
||||
auto_finalise_invoices: "Auto-finalise invoices monthly on the 2nd at 1:30am"
|
||||
manually_run_task: "Manually Run Task "
|
||||
update_user_invoice_explained: "Use this button to immediately update invoices for the month to date for each enterprise user in the system. This task can be set up to run automatically every night."
|
||||
finalise_user_invoices: "Finalise User Invoices"
|
||||
finalise_user_invoice_explained: "Use this button to finalize all invoices in the system for the previous calendar month. This task can be set up to run automatically once a month."
|
||||
update_user_invoices: "Update User Invoices"
|
||||
errors:
|
||||
accounts_distributor: must be set if you wish to create invoices for enterprise users.
|
||||
default_payment_method: must be set if you wish to create invoices for enterprise users.
|
||||
default_shipping_method: must be set if you wish to create invoices for enterprise users.
|
||||
|
||||
shopfront_settings:
|
||||
embedded_shopfront_settings: "Embedded Shopfront Settings"
|
||||
enable_embedded_shopfronts: "Enable Embedded Shopfronts"
|
||||
@@ -379,35 +349,6 @@ en:
|
||||
number_localization_settings: "Number Localization Settings"
|
||||
enable_localized_number: "Use the international thousand/decimal separator logic"
|
||||
|
||||
business_model_configuration:
|
||||
edit:
|
||||
business_model_configuration: "Business Model"
|
||||
business_model_configuration_tip: "Configure the rate at which shops will be charged each month for use of the Open Food Network."
|
||||
bill_calculation_settings: "Bill Calculation Settings"
|
||||
bill_calculation_settings_tip: "Adjust the amount that enterprises will be billed each month for use of the OFN."
|
||||
shop_trial_length: "Shop Trial Length (Days)"
|
||||
shop_trial_length_tip: "The length of time (in days) that enterprises who are set up as shops can run as a trial period."
|
||||
fixed_monthly_charge: "Fixed Monthly Charge"
|
||||
fixed_monthly_charge_tip: "A fixed monthly charge for all enterprises who are set up as a shop and have exceeded the minimum billable turnover (if set)."
|
||||
percentage_of_turnover: "Percentage of turnover"
|
||||
percentage_of_turnover_tip: "When greater than zero, this rate (0.0 - 1.0) will be applied to the total turnover of each shop and added to any fixed charges (to the left) to calculate the monthly bill."
|
||||
monthly_cap_excl_tax: "monthly cap (excl. GST)"
|
||||
monthly_cap_excl_tax_tip: "When greater than zero, this value will be used as a cap on the amount that shops will be charged each month."
|
||||
tax_rate: "Tax Rate"
|
||||
tax_rate_tip: "Tax rate that applies to the the monthly bill that enterprises are charged for using the system."
|
||||
minimum_monthly_billable_turnover: "Minimum Monthly Billable Turnover"
|
||||
minimum_monthly_billable_turnover_tip: "Minimum monthly turnover before a shopfront will be charged for using OFN. Enterprises turning over less than this amount in a month will not be charged, either as a percentage or fixed rate."
|
||||
example_bill_calculator: "Example Bill Calculator"
|
||||
example_bill_calculator_legend: "Alter the example turnover to visualise the effect of the settings to the left."
|
||||
example_monthly_turnover: "Example Monthly Turnover"
|
||||
example_monthly_turnover_tip: "An example monthly turnover for an enterprise which will be used to generate calculate an example monthly bill below."
|
||||
cap_reached?: "Cap Reached ?"
|
||||
cap_reached?_tip: "Whether the cap (specified to the left) has been reached, given the settings and the turnover provided."
|
||||
included_tax: "Included tax"
|
||||
included_tax_tip: "The total tax included in the example monthly bill, given the settings and the turnover provided."
|
||||
total_monthly_bill_incl_tax: "Total Monthly Bill (Incl. Tax)"
|
||||
total_monthly_bill_incl_tax_tip: "The example total monthly bill with tax included, given the settings and the turnover provided."
|
||||
|
||||
cache_settings:
|
||||
show:
|
||||
title: Caching
|
||||
@@ -1818,10 +1759,6 @@ See the %{link} to find out more about %{sitename}'s features and to start using
|
||||
products_distributor_info: When you select a distributor for your order, their address and pickup times will be displayed here.
|
||||
products_distribution_adjustment_label: "Product distribution by %{distributor} for %{product}"
|
||||
|
||||
shop_trial_expires_in: "Your shopfront trial expires in"
|
||||
shop_trial_expired_notice: "Good news! We have decided to extend shopfront trials until further notice."
|
||||
|
||||
|
||||
# keys used in javascript
|
||||
password: Password
|
||||
remember_me: Remember Me
|
||||
@@ -2053,8 +1990,6 @@ See the %{link} to find out more about %{sitename}'s features and to start using
|
||||
registration_detail_country_error: "Please select a country"
|
||||
# END
|
||||
shipping_method_destroy_error: "That shipping method cannot be deleted as it is referenced by an order: %{number}."
|
||||
accounts_and_billing_task_already_running_error: "A task is already running, please wait until it has finished"
|
||||
accounts_and_billing_start_task_notice: "Task Queued"
|
||||
fees: "Fees"
|
||||
item_cost: "Item cost"
|
||||
bulk: "Bulk"
|
||||
@@ -2207,7 +2142,6 @@ See the %{link} to find out more about %{sitename}'s features and to start using
|
||||
live: "live"
|
||||
manage: "Manage"
|
||||
resend: "Resend"
|
||||
trial: Trial
|
||||
add_and_manage_products: "Add & manage products"
|
||||
add_and_manage_order_cycles: "Add & manage order cycles"
|
||||
manage_order_cycles: "Manage order cycles"
|
||||
@@ -2240,7 +2174,6 @@ See the %{link} to find out more about %{sitename}'s features and to start using
|
||||
hub_sidebar_at_least: "At least one hub must be selected"
|
||||
hub_sidebar_blue: "blue"
|
||||
hub_sidebar_red: "red"
|
||||
shop_trial_in_progress: "Your shopfront trial expires in %{days}."
|
||||
report_customers_distributor: "Distributor"
|
||||
report_customers_supplier: "Supplier"
|
||||
report_customers_cycle: "Order Cycle"
|
||||
|
||||
@@ -70,19 +70,8 @@ Openfoodnetwork::Application.routes.draw do
|
||||
|
||||
resource :content
|
||||
|
||||
resource :accounts_and_billing_settings, only: [:edit, :update] do
|
||||
collection do
|
||||
get :show_methods
|
||||
get :start_job
|
||||
end
|
||||
end
|
||||
|
||||
resource :business_model_configuration, only: [:edit, :update], controller: 'business_model_configuration'
|
||||
|
||||
resource :cache_settings
|
||||
|
||||
resource :account, only: [:show], controller: 'account'
|
||||
|
||||
resources :column_preferences, only: [], format: :json do
|
||||
put :bulk_update, on: :collection
|
||||
end
|
||||
|
||||
@@ -33,12 +33,3 @@ every 5.minutes do
|
||||
enqueue_job 'SubscriptionPlacementJob', priority: 0
|
||||
enqueue_job 'SubscriptionConfirmJob', priority: 0
|
||||
end
|
||||
|
||||
every 1.day, at: '1:00am' do
|
||||
rake 'ofn:billing:update_account_invoices'
|
||||
end
|
||||
|
||||
# On the 2nd of every month at 1:30am
|
||||
every '30 1 2 * *' do
|
||||
rake 'ofn:billing:finalize_account_invoices'
|
||||
end
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
class DeleteAccountInvoicesPreferences < ActiveRecord::Migration
|
||||
def up
|
||||
Spree::Preference
|
||||
.where( key: ['spree/app_configuration/accounts_distributor_id',
|
||||
'spree/app_configuration/default_accounts_payment_method_id',
|
||||
'spree/app_configuration/default_accounts_shipping_method_id',
|
||||
'spree/app_configuration/auto_update_invoices',
|
||||
'spree/app_configuration/auto_finalize_invoices',
|
||||
'spree/app_configuration/account_invoices_monthly_fixed',
|
||||
'spree/app_configuration/account_invoices_monthly_rate',
|
||||
'spree/app_configuration/account_invoices_monthly_cap',
|
||||
'spree/app_configuration/account_invoices_tax_rate',
|
||||
'spree/app_configuration/shop_trial_length_days',
|
||||
'spree/app_configuration/minimum_billable_turnover'])
|
||||
.destroy_all
|
||||
end
|
||||
|
||||
def down
|
||||
# If these preferences are re-added to app/models/spree/app_configuration_decorator.rb
|
||||
# these DB entries will be regenerated
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,11 @@
|
||||
class DeleteAccountInvoicesAdjustments < ActiveRecord::Migration
|
||||
def up
|
||||
Spree::Adjustment
|
||||
.where(source_type: 'BillablePeriod')
|
||||
.destroy_all
|
||||
end
|
||||
|
||||
def down
|
||||
# This data does not need to be recovered
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,9 @@
|
||||
class DropEnterpriseShopTrialStartDate < ActiveRecord::Migration
|
||||
def up
|
||||
remove_column :enterprises, :shop_trial_start_date
|
||||
end
|
||||
|
||||
def down
|
||||
add_column :enterprises, :shop_trial_start_date, :datetime, default: nil
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20181128054803) do
|
||||
ActiveRecord::Schema.define(:version => 20190221214542) do
|
||||
|
||||
create_table "account_invoices", :force => true do |t|
|
||||
t.integer "user_id", :null => false
|
||||
@@ -233,7 +233,6 @@ ActiveRecord::Schema.define(:version => 20181128054803) do
|
||||
t.string "linkedin"
|
||||
t.integer "owner_id", :null => false
|
||||
t.string "sells", :default => "none", :null => false
|
||||
t.datetime "shop_trial_start_date"
|
||||
t.boolean "producer_profile_only", :default => false
|
||||
t.string "permalink", :null => false
|
||||
t.boolean "charges_sales_tax", :default => false, :null => false
|
||||
|
||||
@@ -68,14 +68,12 @@
|
||||
"spec/controllers/admin/enterprises_controller_spec.rb": 4.12069845199585,
|
||||
"spec/lib/open_food_network/scope_variant_to_hub_spec.rb": 3.415233612060547,
|
||||
"spec/controllers/shop_controller_spec.rb": 2.8152332305908203,
|
||||
"spec/features/admin/accounts_and_billing_settings_spec.rb": 4.564471960067749,
|
||||
"spec/lib/open_food_network/user_balance_calculator_spec.rb": 5.701348066329956,
|
||||
"spec/features/consumer/groups_spec.rb": 4.695758104324341,
|
||||
"spec/lib/open_food_network/order_cycle_form_applicator_spec.rb": 5.4417150020599365,
|
||||
"spec/controllers/spree/api/products_controller_spec.rb": 9.90657091140747,
|
||||
"spec/serializers/admin/exchange_serializer_spec.rb": 2.6061851978302,
|
||||
"spec/controllers/api/promo_images_controller_spec.rb": 3.7358314990997314,
|
||||
"spec/jobs/update_billable_periods_spec.rb": 7.687055826187134,
|
||||
"spec/controllers/enterprises_controller_spec.rb": 4.6496901512146,
|
||||
"spec/features/consumer/registration_spec.rb": 4.664679765701294,
|
||||
"spec/serializers/order_serializer_spec.rb": 6.241122722625732,
|
||||
@@ -97,14 +95,12 @@
|
||||
"spec/models/enterprise_fee_spec.rb": 2.6969127655029297,
|
||||
"spec/features/consumer/shopping/embedded_groups_spec.rb": 3.5200917720794678,
|
||||
"spec/lib/open_food_network/scope_variants_to_search_spec.rb": 2.9324328899383545,
|
||||
"spec/controllers/admin/accounts_and_billing_settings_controller_spec.rb": 3.5419158935546875,
|
||||
"spec/models/spree/payment_spec.rb": 3.644035816192627,
|
||||
"spec/controllers/admin/schedules_controller_spec.rb": 4.086155414581299,
|
||||
"spec/controllers/spree/admin/reports_controller_spec.rb": 4.6371729373931885,
|
||||
"spec/helpers/enterprises_helper_spec.rb": 4.092283725738525,
|
||||
"spec/features/admin/schedules_spec.rb": 4.011422872543335,
|
||||
"spec/controllers/admin/order_cycles_controller_spec.rb": 3.8047308921813965,
|
||||
"spec/models/billable_period_spec.rb": 4.33881139755249,
|
||||
"spec/features/admin/authentication_spec.rb": 2.6899383068084717,
|
||||
"spec/controllers/spree/admin/orders/customer_details_controller_spec.rb": 3.8118021488189697,
|
||||
"spec/models/enterprise_caching_spec.rb": 3.222259998321533,
|
||||
@@ -118,8 +114,6 @@
|
||||
"spec/lib/open_food_network/subscription_payment_updater_spec.rb": 3.8399856090545654,
|
||||
"spec/features/consumer/footer_links_spec.rb": 1.9081592559814453,
|
||||
"spec/jobs/subscription_placement_job_spec.rb": 3.095796823501587,
|
||||
"spec/helpers/admin/business_model_configuration_helper_spec.rb": 1.4220046997070312,
|
||||
"spec/features/admin/business_model_configuration_spec.rb": 2.1453568935394287,
|
||||
"spec/controllers/admin/subscription_line_items_controller_spec.rb": 2.2608282566070557,
|
||||
"spec/controllers/cart_controller_spec.rb": 2.738463878631592,
|
||||
"spec/models/producer_property_spec.rb": 2.198972702026367,
|
||||
@@ -206,7 +200,6 @@
|
||||
"spec/models/concerns/order_shipping_method_spec.rb": 0.29420924186706543,
|
||||
"spec/models/stripe_account_spec.rb": 0.23795485496520996,
|
||||
"spec/controllers/admin/stripe_connect_settings_controller_spec.rb": 0.2342853546142578,
|
||||
"spec/controllers/admin/business_model_configuration_controller_spec.rb": 0.18909120559692383,
|
||||
"spec/serializers/api/admin/product_serializer_spec.rb": 0.2630436420440674,
|
||||
"spec/serializers/variant_serializer_spec.rb": 0.29114508628845215,
|
||||
"spec/controllers/stripe/callbacks_controller_spec.rb": 0.2801051139831543,
|
||||
@@ -230,7 +223,6 @@
|
||||
"spec/controllers/stripe/webhooks_controller_spec.rb": 0.15674114227294922,
|
||||
"spec/models/model_set_spec.rb": 0.17897748947143555,
|
||||
"spec/models/spree/credit_card_spec.rb": 0.11442422866821289,
|
||||
"spec/features/admin/account_spec.rb": 0.15611958503723145,
|
||||
"spec/features/consumer/confirm_invitation_spec.rb": 0.1410982608795166,
|
||||
"spec/lib/open_food_network/sales_tax_report_spec.rb": 0.10101437568664551,
|
||||
"spec/models/coordinator_fee_spec.rb": 0.11246252059936523,
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
# This class is a lightweight model used to validate preferences for accounts and billing settings
|
||||
# when they are submitted to the AccountsAndBillingSettingsController
|
||||
|
||||
module OpenFoodNetwork
|
||||
class AccountsAndBillingSettingsValidator
|
||||
include ActiveModel::Validations
|
||||
|
||||
attr_accessor :accounts_distributor_id, :default_accounts_payment_method_id, :default_accounts_shipping_method_id
|
||||
attr_accessor :auto_update_invoices, :auto_finalize_invoices
|
||||
|
||||
validate :ensure_accounts_distributor_set
|
||||
validate :ensure_default_payment_method_set
|
||||
validate :ensure_default_shipping_method_set
|
||||
# validate :ensure_billing_info_collected, unless: lambda { create_invoices_for_enterprise_users == '0' }
|
||||
|
||||
def initialize(attr, button=nil)
|
||||
attr.each { |k,v| instance_variable_set("@#{k}", v) }
|
||||
@button = button
|
||||
end
|
||||
|
||||
def ensure_accounts_distributor_set
|
||||
unless Enterprise.find_by_id(accounts_distributor_id)
|
||||
errors.add(:accounts_distributor, I18n.t('admin.accounts_and_billing_settings.errors.accounts_distributor'))
|
||||
end
|
||||
end
|
||||
|
||||
def ensure_default_payment_method_set
|
||||
unless Enterprise.find_by_id(accounts_distributor_id) &&
|
||||
Enterprise.find_by_id(accounts_distributor_id).payment_methods.find_by_id(default_accounts_payment_method_id)
|
||||
errors.add(:default_payment_method, I18n.t('admin.accounts_and_billing_settings.errors.default_payment_method'))
|
||||
end
|
||||
end
|
||||
|
||||
def ensure_default_shipping_method_set
|
||||
unless Enterprise.find_by_id(accounts_distributor_id) &&
|
||||
Enterprise.find_by_id(accounts_distributor_id).shipping_methods.find_by_id(default_accounts_shipping_method_id)
|
||||
errors.add(:default_shipping_method, I18n.t('admin.accounts_and_billing_settings.errors.default_shipping_method'))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,21 +0,0 @@
|
||||
module OpenFoodNetwork
|
||||
class BillCalculator
|
||||
attr_accessor :turnover, :fixed, :rate, :cap, :tax_rate, :minimum_billable_turnover
|
||||
|
||||
def initialize(opts={})
|
||||
@turnover = opts[:turnover] || 0
|
||||
@fixed = opts[:fixed] || Spree::Config[:account_invoices_monthly_fixed]
|
||||
@rate = opts[:rate] || Spree::Config[:account_invoices_monthly_rate]
|
||||
@cap = opts[:cap] || Spree::Config[:account_invoices_monthly_cap]
|
||||
@tax_rate = opts[:tax_rate] || Spree::Config[:account_invoices_tax_rate]
|
||||
@minimum_billable_turnover = opts[:minimum_billable_turnover] || Spree::Config[:minimum_billable_turnover]
|
||||
end
|
||||
|
||||
def bill
|
||||
return 0 if turnover < minimum_billable_turnover
|
||||
bill = fixed + (turnover * rate)
|
||||
bill = [bill, cap].min if cap > 0
|
||||
bill * (1 + tax_rate)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,22 +0,0 @@
|
||||
# This class is a lightweight model used to validate preferences for business model configuration
|
||||
# when they are submitted to the BusinessModelConfigurationController
|
||||
|
||||
module OpenFoodNetwork
|
||||
class BusinessModelConfigurationValidator
|
||||
include ActiveModel::Validations
|
||||
|
||||
attr_accessor :shop_trial_length_days, :account_invoices_monthly_fixed, :account_invoices_monthly_rate, :account_invoices_monthly_cap, :account_invoices_tax_rate, :minimum_billable_turnover
|
||||
|
||||
validates :shop_trial_length_days, presence: true, numericality: { greater_than_or_equal_to: 0 }
|
||||
validates :account_invoices_monthly_fixed, presence: true, numericality: { greater_than_or_equal_to: 0 }
|
||||
validates :account_invoices_monthly_rate, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 1 }
|
||||
validates :account_invoices_monthly_cap, presence: true, numericality: { greater_than_or_equal_to: 0 }
|
||||
validates :account_invoices_tax_rate, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 1 }
|
||||
validates :minimum_billable_turnover, presence: true, numericality: { greater_than_or_equal_to: 0 }
|
||||
|
||||
def initialize(attr, button=nil)
|
||||
attr.each { |k,v| instance_variable_set("@#{k}", v) }
|
||||
@button = button
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -89,7 +89,7 @@ module OpenFoodNetwork
|
||||
rows = []
|
||||
|
||||
rows += produce_summary_rows(order, invoice_number, opts) unless detail?
|
||||
rows += fee_summary_rows(order, invoice_number, opts) unless detail? && order.account_invoice?
|
||||
rows += fee_summary_rows(order, invoice_number, opts)
|
||||
rows += shipping_summary_rows(order, invoice_number, opts)
|
||||
rows += payment_summary_rows(order, invoice_number, opts)
|
||||
rows += admin_adjustment_summary_rows(order, invoice_number, opts) unless detail?
|
||||
@@ -158,18 +158,11 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
def adjustments(order)
|
||||
account_invoice_adjustments(order) + order.adjustments.admin
|
||||
end
|
||||
|
||||
def account_invoice_adjustments(order)
|
||||
order.adjustments.
|
||||
billable_period.
|
||||
select { |a| a.source.present? }
|
||||
order.adjustments.admin
|
||||
end
|
||||
|
||||
def adjustment_order(adjustment)
|
||||
adjustment.source.andand.account_invoice.andand.order ||
|
||||
(adjustment.adjustable.is_a?(Spree::Order) ? adjustment.adjustable : nil)
|
||||
adjustment.adjustable.is_a?(Spree::Order) ? adjustment.adjustable : nil
|
||||
end
|
||||
|
||||
def invoice_number_for(order, i)
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
namespace :ofn do
|
||||
namespace :billing do
|
||||
desc 'Update enterprise user invoices'
|
||||
task update_account_invoices: :environment do
|
||||
Delayed::Job.enqueue(UpdateAccountInvoices.new) if Spree::Config[:auto_update_invoices]
|
||||
end
|
||||
|
||||
desc 'Finalize enterprise user invoices'
|
||||
task finalize_account_invoices: :environment do
|
||||
Delayed::Job.enqueue(FinalizeAccountInvoices.new) if Spree::Config[:auto_finalize_invoices]
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,241 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Admin::AccountsAndBillingSettingsController, type: :controller do
|
||||
let!(:pm1) { create(:payment_method) }
|
||||
let!(:sm1) { create(:shipping_method) }
|
||||
let!(:pm2) { create(:payment_method) }
|
||||
let!(:sm2) { create(:shipping_method) }
|
||||
let!(:accounts_distributor) { create(:distributor_enterprise, payment_methods: [pm1], shipping_methods: [sm1]) }
|
||||
let!(:new_distributor) { create(:distributor_enterprise, payment_methods: [pm2], shipping_methods: [sm2]) }
|
||||
let(:user) { create(:user) }
|
||||
let(:admin) { create(:admin_user) }
|
||||
|
||||
before do
|
||||
Spree::Config.set({
|
||||
accounts_distributor_id: accounts_distributor.id,
|
||||
default_accounts_payment_method_id: pm1.id,
|
||||
default_accounts_shipping_method_id: sm1.id,
|
||||
auto_update_invoices: true,
|
||||
auto_finalize_invoices: false
|
||||
})
|
||||
end
|
||||
|
||||
describe "edit" do
|
||||
context "as an enterprise user" do
|
||||
before { allow(controller).to receive(:spree_current_user) { user } }
|
||||
|
||||
it "does not allow access" do
|
||||
spree_get :edit
|
||||
expect(response).to redirect_to spree.unauthorized_path
|
||||
end
|
||||
end
|
||||
|
||||
context "as super admin" do
|
||||
before { allow(controller).to receive(:spree_current_user) { admin } }
|
||||
|
||||
it "loads relevant global settings into a locally dummy class" do
|
||||
spree_get :edit
|
||||
settings = assigns(:settings)
|
||||
|
||||
expect(settings.accounts_distributor_id).to eq accounts_distributor.id
|
||||
expect(settings.default_accounts_payment_method_id).to eq pm1.id
|
||||
expect(settings.default_accounts_shipping_method_id).to eq sm1.id
|
||||
expect(settings.auto_update_invoices).to eq true
|
||||
expect(settings.auto_finalize_invoices).to eq false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "update" do
|
||||
context "as an enterprise user" do
|
||||
before { allow(controller).to receive(:spree_current_user) { user } }
|
||||
|
||||
it "does not allow access" do
|
||||
spree_get :update
|
||||
expect(response).to redirect_to spree.unauthorized_path
|
||||
end
|
||||
end
|
||||
|
||||
context "as super admin" do
|
||||
before {allow(controller).to receive(:spree_current_user) { admin } }
|
||||
let(:params) { { settings: { } } }
|
||||
|
||||
context "when required settings have no values" do
|
||||
before do
|
||||
params[:settings][:accounts_distributor_id] = ''
|
||||
params[:settings][:default_accounts_payment_method_id] = '0'
|
||||
params[:settings][:default_accounts_shipping_method_id] = '0'
|
||||
params[:settings][:auto_update_invoices] = '0'
|
||||
params[:settings][:auto_finalize_invoices] = '0'
|
||||
spree_get :update, params
|
||||
end
|
||||
|
||||
it "does not allow them to be empty/false" do
|
||||
expect(response).to render_template :edit
|
||||
expect(assigns(:settings).errors.count).to be 3
|
||||
expect(Spree::Config.accounts_distributor_id).to eq accounts_distributor.id
|
||||
expect(Spree::Config.default_accounts_payment_method_id).to eq pm1.id
|
||||
expect(Spree::Config.default_accounts_shipping_method_id).to eq sm1.id
|
||||
expect(Spree::Config.auto_update_invoices).to be true
|
||||
expect(Spree::Config.auto_finalize_invoices).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context "when required settings have values" do
|
||||
before do
|
||||
params[:settings][:accounts_distributor_id] = new_distributor.id
|
||||
params[:settings][:default_accounts_payment_method_id] = pm2.id
|
||||
params[:settings][:default_accounts_shipping_method_id] = sm2.id
|
||||
params[:settings][:auto_update_invoices] = '0'
|
||||
params[:settings][:auto_finalize_invoices] = '0'
|
||||
end
|
||||
|
||||
it "sets global config to the specified values" do
|
||||
spree_get :update, params
|
||||
expect(Spree::Config.accounts_distributor_id).to eq new_distributor.id
|
||||
expect(Spree::Config.default_accounts_payment_method_id).to eq pm2.id
|
||||
expect(Spree::Config.default_accounts_shipping_method_id).to eq sm2.id
|
||||
expect(Spree::Config.auto_update_invoices).to be false
|
||||
expect(Spree::Config.auto_finalize_invoices).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "start_job" do
|
||||
context "as an enterprise user" do
|
||||
before do
|
||||
allow(controller).to receive(:spree_current_user) { user }
|
||||
spree_post :start_job, enterprise_id: accounts_distributor.id
|
||||
end
|
||||
|
||||
it "does not allow access" do
|
||||
expect(response).to redirect_to spree.unauthorized_path
|
||||
end
|
||||
end
|
||||
|
||||
context "as super admin" do
|
||||
before do
|
||||
allow(controller).to receive(:spree_current_user) { admin }
|
||||
end
|
||||
|
||||
context "when settings are not valid" do
|
||||
before do
|
||||
Spree::Config.set({ accounts_distributor_id: "" })
|
||||
Spree::Config.set({ default_accounts_payment_method_id: "" })
|
||||
Spree::Config.set({ default_accounts_shipping_method_id: "" })
|
||||
spree_post :start_job, job: { name: "" }
|
||||
end
|
||||
|
||||
it "returns immediately and renders :edit" do
|
||||
expect(assigns(:settings).errors.count).to eq 3
|
||||
expect(response).to render_template :edit
|
||||
end
|
||||
end
|
||||
|
||||
context "when settings are valid" do
|
||||
before do
|
||||
Spree::Config.set({ accounts_distributor_id: accounts_distributor.id })
|
||||
Spree::Config.set({ default_accounts_payment_method_id: pm1.id })
|
||||
Spree::Config.set({ default_accounts_shipping_method_id: sm1.id })
|
||||
end
|
||||
|
||||
context "and job_name is not on the known_jobs list" do
|
||||
before do
|
||||
spree_post :start_job, job: { name: "" }
|
||||
end
|
||||
|
||||
it "returns immediately with an error" do
|
||||
expect(flash[:error]).to eq "Unknown Task: "
|
||||
expect(response).to redirect_to edit_admin_accounts_and_billing_settings_path
|
||||
end
|
||||
end
|
||||
|
||||
context "and job_name is update_account_invoices" do
|
||||
let!(:params) { { job: { name: "update_account_invoices" } } }
|
||||
|
||||
context "and no jobs are currently running" do
|
||||
before do
|
||||
allow(controller).to receive(:load_jobs)
|
||||
end
|
||||
|
||||
it "runs the job" do
|
||||
expect{spree_post :start_job, params}.to enqueue_job UpdateAccountInvoices
|
||||
expect(flash[:success]).to eq "Task Queued"
|
||||
expect(response).to redirect_to edit_admin_accounts_and_billing_settings_path
|
||||
end
|
||||
end
|
||||
|
||||
context "and there are jobs currently running" do
|
||||
before do
|
||||
allow(controller).to receive(:load_jobs)
|
||||
controller.instance_variable_set("@update_account_invoices_job", double(:update_account_invoices_job))
|
||||
end
|
||||
|
||||
it "does not run the job" do
|
||||
expect{spree_post :start_job, params}.to_not enqueue_job UpdateAccountInvoices
|
||||
expect(flash[:error]).to eq "A task is already running, please wait until it has finished"
|
||||
expect(response).to redirect_to edit_admin_accounts_and_billing_settings_path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "and job_name is finalize_account_invoices" do
|
||||
let!(:params) { { job: { name: "finalize_account_invoices" } } }
|
||||
|
||||
context "and no jobs are currently running" do
|
||||
before do
|
||||
allow(controller).to receive(:load_jobs)
|
||||
end
|
||||
|
||||
it "runs the job" do
|
||||
expect{spree_post :start_job, params}.to enqueue_job FinalizeAccountInvoices
|
||||
expect(flash[:success]).to eq "Task Queued"
|
||||
expect(response).to redirect_to edit_admin_accounts_and_billing_settings_path
|
||||
end
|
||||
end
|
||||
|
||||
context "and there are jobs currently running" do
|
||||
before do
|
||||
allow(controller).to receive(:load_jobs)
|
||||
controller.instance_variable_set("@finalize_account_invoices_job", double(:finalize_account_invoices_job))
|
||||
end
|
||||
|
||||
it "does not run the job" do
|
||||
expect{spree_post :start_job, params}.to_not enqueue_job FinalizeAccountInvoices
|
||||
expect(flash[:error]).to eq "A task is already running, please wait until it has finished"
|
||||
expect(response).to redirect_to edit_admin_accounts_and_billing_settings_path
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "show_methods" do
|
||||
context "as an enterprise user" do
|
||||
before do
|
||||
allow(controller).to receive(:spree_current_user) { user }
|
||||
spree_get :show_methods, enterprise_id: accounts_distributor.id
|
||||
end
|
||||
|
||||
it "does not allow access" do
|
||||
expect(response).to redirect_to spree.unauthorized_path
|
||||
end
|
||||
end
|
||||
|
||||
context "as super admin" do
|
||||
before do
|
||||
allow(controller).to receive(:spree_current_user) { admin }
|
||||
spree_get :show_methods, enterprise_id: accounts_distributor.id
|
||||
end
|
||||
|
||||
it "renders the method_settings template" do
|
||||
expect(assigns(:payment_methods)).to eq [pm1]
|
||||
expect(assigns(:shipping_methods)).to eq [sm1]
|
||||
expect(assigns(:enterprise)).to eq accounts_distributor
|
||||
expect(response).to render_template :method_settings
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,98 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Admin::BusinessModelConfigurationController, type: :controller do
|
||||
let(:user) { create(:user) }
|
||||
let(:admin) { create(:admin_user) }
|
||||
|
||||
before do
|
||||
Spree::Config.set({
|
||||
account_invoices_monthly_fixed: 5,
|
||||
account_invoices_monthly_rate: 0.02,
|
||||
account_invoices_monthly_cap: 50,
|
||||
account_invoices_tax_rate: 0.1,
|
||||
shop_trial_length_days: 30,
|
||||
minimum_billable_turnover: 0
|
||||
})
|
||||
end
|
||||
|
||||
describe "edit" do
|
||||
context "as an enterprise user" do
|
||||
before { allow(controller).to receive(:spree_current_user) { user } }
|
||||
|
||||
it "does not allow access" do
|
||||
spree_get :edit
|
||||
expect(response).to redirect_to spree.unauthorized_path
|
||||
end
|
||||
end
|
||||
|
||||
context "as super admin" do
|
||||
before { allow(controller).to receive(:spree_current_user) { admin } }
|
||||
|
||||
it "allows access" do
|
||||
spree_get :edit
|
||||
expect(response).to_not redirect_to spree.unauthorized_path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "update" do
|
||||
context "as an enterprise user" do
|
||||
before { allow(controller).to receive(:spree_current_user) { user } }
|
||||
|
||||
it "does not allow access" do
|
||||
spree_get :update
|
||||
expect(response).to redirect_to spree.unauthorized_path
|
||||
end
|
||||
end
|
||||
|
||||
context "as super admin" do
|
||||
before {allow(controller).to receive(:spree_current_user) { admin } }
|
||||
let(:params) { { settings: { } } }
|
||||
|
||||
context "when settings are invalid" do
|
||||
before do
|
||||
params[:settings][:account_invoices_monthly_fixed] = ''
|
||||
params[:settings][:account_invoices_monthly_rate] = '2'
|
||||
params[:settings][:account_invoices_monthly_cap] = '-1'
|
||||
params[:settings][:account_invoices_tax_rate] = '4'
|
||||
params[:settings][:shop_trial_length_days] = '-30'
|
||||
params[:settings][:minimum_billable_turnover] = '-1'
|
||||
spree_get :update, params
|
||||
end
|
||||
|
||||
it "does not allow them to be set" do
|
||||
expect(response).to render_template :edit
|
||||
expect(assigns(:settings).errors.count).to be 7
|
||||
expect(Spree::Config.account_invoices_monthly_fixed).to eq 5
|
||||
expect(Spree::Config.account_invoices_monthly_rate).to eq 0.02
|
||||
expect(Spree::Config.account_invoices_monthly_cap).to eq 50
|
||||
expect(Spree::Config.account_invoices_tax_rate).to eq 0.1
|
||||
expect(Spree::Config.shop_trial_length_days).to eq 30
|
||||
expect(Spree::Config.minimum_billable_turnover).to eq 0
|
||||
end
|
||||
end
|
||||
|
||||
context "when required settings are valid" do
|
||||
before do
|
||||
params[:settings][:account_invoices_monthly_fixed] = '10'
|
||||
params[:settings][:account_invoices_monthly_rate] = '0.05'
|
||||
params[:settings][:account_invoices_monthly_cap] = '30'
|
||||
params[:settings][:account_invoices_tax_rate] = '0.15'
|
||||
params[:settings][:shop_trial_length_days] = '20'
|
||||
params[:settings][:minimum_billable_turnover] = '10'
|
||||
end
|
||||
|
||||
it "sets global config to the specified values" do
|
||||
spree_get :update, params
|
||||
expect(assigns(:settings).errors.count).to be 0
|
||||
expect(Spree::Config.account_invoices_monthly_fixed).to eq 10
|
||||
expect(Spree::Config.account_invoices_monthly_rate).to eq 0.05
|
||||
expect(Spree::Config.account_invoices_monthly_cap).to eq 30
|
||||
expect(Spree::Config.account_invoices_tax_rate).to eq 0.15
|
||||
expect(Spree::Config.shop_trial_length_days).to eq 20
|
||||
expect(Spree::Config.minimum_billable_turnover).to eq 10
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -344,90 +344,20 @@ module Admin
|
||||
enterprise.save!
|
||||
end
|
||||
|
||||
context "if the trial has finished" do
|
||||
let(:trial_start) { 30.days.ago.beginning_of_day }
|
||||
|
||||
before do
|
||||
enterprise.update_attribute(:shop_trial_start_date, trial_start)
|
||||
end
|
||||
|
||||
it "is allowed" do
|
||||
Timecop.freeze(Time.zone.local(2015, 4, 16, 14, 0, 0)) do
|
||||
spree_post :register, { id: enterprise, sells: 'own' }
|
||||
expect(response).to redirect_to spree.admin_path
|
||||
expect(enterprise.reload.sells).to eq 'own'
|
||||
expect(enterprise.shop_trial_start_date).to eq trial_start
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "if the trial has not finished" do
|
||||
let(:trial_start) { Date.current.to_time }
|
||||
|
||||
before do
|
||||
enterprise.update_attribute(:shop_trial_start_date, trial_start)
|
||||
end
|
||||
|
||||
it "is allowed, but trial start date is not reset" do
|
||||
spree_post :register, { id: enterprise, sells: 'own' }
|
||||
expect(response).to redirect_to spree.admin_path
|
||||
expect(enterprise.reload.sells).to eq 'own'
|
||||
expect(enterprise.shop_trial_start_date).to eq trial_start
|
||||
end
|
||||
end
|
||||
|
||||
context "if a trial has not started" do
|
||||
it "is allowed" do
|
||||
spree_post :register, { id: enterprise, sells: 'own' }
|
||||
expect(response).to redirect_to spree.admin_path
|
||||
expect(flash[:success]).to eq "Congratulations! Registration for #{enterprise.name} is complete!"
|
||||
expect(enterprise.reload.sells).to eq 'own'
|
||||
expect(enterprise.reload.shop_trial_start_date).to be > Time.zone.now-(1.minute)
|
||||
end
|
||||
it "is allowed" do
|
||||
spree_post :register, { id: enterprise, sells: 'own' }
|
||||
expect(response).to redirect_to spree.admin_path
|
||||
expect(flash[:success]).to eq "Congratulations! Registration for #{enterprise.name} is complete!"
|
||||
expect(enterprise.reload.sells).to eq 'own'
|
||||
end
|
||||
end
|
||||
|
||||
context "setting 'sells' to any" do
|
||||
context "if the trial has finished" do
|
||||
let(:trial_start) { 30.days.ago.beginning_of_day }
|
||||
|
||||
before do
|
||||
enterprise.update_attribute(:shop_trial_start_date, trial_start)
|
||||
end
|
||||
|
||||
it "is allowed" do
|
||||
Timecop.freeze(Time.zone.local(2015, 4, 16, 14, 0, 0)) do
|
||||
spree_post :register, { id: enterprise, sells: 'any' }
|
||||
expect(response).to redirect_to spree.admin_path
|
||||
expect(enterprise.reload.sells).to eq 'any'
|
||||
expect(enterprise.shop_trial_start_date).to eq trial_start
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "if the trial has not finished" do
|
||||
let(:trial_start) { Date.current.to_time }
|
||||
|
||||
before do
|
||||
enterprise.update_attribute(:shop_trial_start_date, trial_start)
|
||||
end
|
||||
|
||||
it "is allowed, but trial start date is not reset" do
|
||||
spree_post :register, { id: enterprise, sells: 'any' }
|
||||
expect(response).to redirect_to spree.admin_path
|
||||
expect(enterprise.reload.sells).to eq 'any'
|
||||
expect(enterprise.shop_trial_start_date).to eq trial_start
|
||||
end
|
||||
end
|
||||
|
||||
context "if a trial has not started" do
|
||||
it "is allowed" do
|
||||
spree_post :register, { id: enterprise, sells: 'any' }
|
||||
expect(response).to redirect_to spree.admin_path
|
||||
expect(flash[:success]).to eq "Congratulations! Registration for #{enterprise.name} is complete!"
|
||||
expect(enterprise.reload.sells).to eq 'any'
|
||||
expect(enterprise.reload.shop_trial_start_date).to be > Time.zone.now-(1.minute)
|
||||
end
|
||||
it "is allowed" do
|
||||
spree_post :register, { id: enterprise, sells: 'any' }
|
||||
expect(response).to redirect_to spree.admin_path
|
||||
expect(flash[:success]).to eq "Congratulations! Registration for #{enterprise.name} is complete!"
|
||||
expect(enterprise.reload.sells).to eq 'any'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -23,18 +23,6 @@ module Api
|
||||
expect(json_response.length).to eq 1
|
||||
expect(json_response.first[:id]).to eq customer1.id
|
||||
end
|
||||
|
||||
context "when the accounts distributor id has been set" do
|
||||
before do
|
||||
Spree::Config.set(accounts_distributor_id: customer1.enterprise.id)
|
||||
end
|
||||
|
||||
it "ignores the customer for that enterprise (if it exists)" do
|
||||
spree_get :index
|
||||
expect(response.status).to eq 200
|
||||
expect(json_response.length).to eq 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#update" do
|
||||
|
||||
@@ -14,14 +14,11 @@ describe Spree::UsersController, type: :controller do
|
||||
let!(:d1_order_for_u2) { create(:completed_order_with_totals, distributor: distributor1, user_id: u2.id) }
|
||||
let!(:d1o3) { create(:order, state: 'cart', distributor: distributor1, user_id: u1.id) }
|
||||
let!(:d2o1) { create(:completed_order_with_totals, distributor: distributor2, user_id: u2.id) }
|
||||
let!(:accounts_distributor) { create :distributor_enterprise }
|
||||
let!(:order_account_invoice) { create(:order, distributor: accounts_distributor, state: 'complete', user: u1) }
|
||||
|
||||
let(:orders) { assigns(:orders) }
|
||||
let(:shops) { Enterprise.where(id: orders.pluck(:distributor_id)) }
|
||||
|
||||
before do
|
||||
Spree::Config.set(accounts_distributor_id: accounts_distributor.id)
|
||||
allow(controller).to receive(:spree_current_user) { u1 }
|
||||
end
|
||||
|
||||
@@ -32,10 +29,6 @@ describe Spree::UsersController, type: :controller do
|
||||
expect(orders).to_not include d1_order_for_u2, d1o3, d2o1
|
||||
expect(shops).to include distributor1
|
||||
|
||||
# Doesn't return orders belonging to the accounts distributor" do
|
||||
expect(orders).to_not include order_account_invoice
|
||||
expect(shops).to_not include accounts_distributor
|
||||
|
||||
# Doesn't return orders for irrelevant distributors" do
|
||||
expect(orders).not_to include d2o1
|
||||
expect(shops).not_to include distributor2
|
||||
|
||||
@@ -485,26 +485,6 @@ FactoryBot.define do
|
||||
bill_address { create(:address) }
|
||||
end
|
||||
|
||||
factory :billable_period do
|
||||
begins_at { Time.zone.now.beginning_of_month }
|
||||
ends_at { Time.zone.now.beginning_of_month + 1.month }
|
||||
sells { 'any' }
|
||||
trial { false }
|
||||
enterprise
|
||||
owner { enterprise.owner }
|
||||
turnover { rand(100000).to_f/100 }
|
||||
account_invoice do
|
||||
AccountInvoice.where(user_id: owner_id, year: begins_at.year, month: begins_at.month).first ||
|
||||
FactoryBot.create(:account_invoice, user: owner, year: begins_at.year, month: begins_at.month)
|
||||
end
|
||||
end
|
||||
|
||||
factory :account_invoice do
|
||||
user { FactoryBot.create :user }
|
||||
year { 2000 + rand(100) }
|
||||
month { 1 + rand(12) }
|
||||
end
|
||||
|
||||
factory :filter_order_cycles_tag_rule, class: TagRule::FilterOrderCycles do
|
||||
enterprise { FactoryBot.create :distributor_enterprise }
|
||||
end
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
feature 'Account Page' do
|
||||
include AuthenticationWorkflow
|
||||
|
||||
describe "updating" do
|
||||
let!(:user) { create(:user) }
|
||||
let!(:enterprise) { create(:distributor_enterprise, owner: user) }
|
||||
|
||||
before do
|
||||
quick_login_as user
|
||||
end
|
||||
|
||||
context "as an enterprise user" do
|
||||
it "loads the page" do
|
||||
visit admin_account_path
|
||||
expect(page).to have_content "Account"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,60 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
feature 'Account and Billing Settings' do
|
||||
include AuthenticationWorkflow
|
||||
include WebHelper
|
||||
|
||||
describe "updating" do
|
||||
let!(:admin) { create(:admin_user) }
|
||||
let!(:pm1) { create(:payment_method) }
|
||||
let!(:sm1) { create(:shipping_method) }
|
||||
let!(:accounts_distributor) { create(:distributor_enterprise, payment_methods: [pm1], shipping_methods: [sm1]) }
|
||||
|
||||
before do
|
||||
Spree::Config.set({
|
||||
accounts_distributor_id: 0,
|
||||
default_accounts_payment_method_id: 0,
|
||||
default_accounts_shipping_method_id: 0,
|
||||
auto_update_invoices: false,
|
||||
auto_finalize_invoices: false
|
||||
})
|
||||
end
|
||||
|
||||
before do
|
||||
quick_login_as_admin
|
||||
end
|
||||
|
||||
context "as an admin user", js: true do
|
||||
it "loads the page" do
|
||||
visit spree.admin_path
|
||||
click_link "Configuration"
|
||||
click_link "Accounts & Billing"
|
||||
|
||||
expect(page).to have_select2 "settings_accounts_distributor_id"
|
||||
select2_select accounts_distributor.name, from: "settings_accounts_distributor_id"
|
||||
expect(page).to have_select "settings_default_accounts_payment_method_id"
|
||||
expect(page).to have_select "settings_default_accounts_shipping_method_id"
|
||||
expect(page).to have_link "Update User Invoices", href: start_job_admin_accounts_and_billing_settings_path(job: { name: 'update_account_invoices'})
|
||||
expect(page).to have_link "Finalise User Invoices", href: start_job_admin_accounts_and_billing_settings_path(job: { name: 'finalize_account_invoices'})
|
||||
end
|
||||
|
||||
it "attributes can be changed", js: true do
|
||||
visit edit_admin_accounts_and_billing_settings_path
|
||||
|
||||
select2_select accounts_distributor.name, from: "settings_accounts_distributor_id"
|
||||
select pm1.name, from: "settings_default_accounts_payment_method_id"
|
||||
select sm1.name, from: "settings_default_accounts_shipping_method_id"
|
||||
check "settings_auto_update_invoices"
|
||||
check "settings_auto_finalize_invoices"
|
||||
|
||||
click_button "Update"
|
||||
|
||||
expect(Spree::Config.accounts_distributor_id).to eq accounts_distributor.id
|
||||
expect(Spree::Config.default_accounts_payment_method_id).to eq pm1.id
|
||||
expect(Spree::Config.default_accounts_shipping_method_id).to eq sm1.id
|
||||
expect(Spree::Config.auto_update_invoices).to be true
|
||||
expect(Spree::Config.auto_finalize_invoices).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,53 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
feature 'Business Model Configuration' do
|
||||
include AuthenticationWorkflow
|
||||
include WebHelper
|
||||
|
||||
describe "updating" do
|
||||
let!(:admin) { create(:admin_user) }
|
||||
|
||||
before do
|
||||
Spree::Config.set({
|
||||
account_invoices_monthly_fixed: 5,
|
||||
account_invoices_monthly_rate: 0.02,
|
||||
account_invoices_monthly_cap: 50,
|
||||
account_invoices_tax_rate: 0.1
|
||||
})
|
||||
end
|
||||
|
||||
before do
|
||||
quick_login_as_admin
|
||||
end
|
||||
|
||||
context "as an admin user", js: true do
|
||||
it "loads the page" do
|
||||
visit spree.admin_path
|
||||
click_link "Configuration"
|
||||
click_link "Business Model"
|
||||
|
||||
expect(page).to have_field "settings_account_invoices_monthly_fixed", with: 5.0
|
||||
expect(page).to have_field "settings_account_invoices_monthly_rate", with: 0.02
|
||||
expect(page).to have_field "settings_account_invoices_monthly_cap", with: 50.0
|
||||
expect(page).to have_field "settings_account_invoices_tax_rate", with: 0.1
|
||||
end
|
||||
|
||||
it "attributes can be changed", js: true do
|
||||
visit edit_admin_business_model_configuration_path
|
||||
|
||||
fill_in "settings_account_invoices_monthly_fixed", with: 10
|
||||
fill_in "settings_account_invoices_monthly_rate", with: 0.05
|
||||
fill_in "settings_account_invoices_monthly_cap", with: 30
|
||||
fill_in "settings_account_invoices_tax_rate", with: 0.15
|
||||
|
||||
click_button "Update"
|
||||
|
||||
expect(page).to have_content "Business Model has been successfully updated!"
|
||||
expect(Spree::Config.account_invoices_monthly_fixed).to eq 10
|
||||
expect(Spree::Config.account_invoices_monthly_rate).to eq 0.05
|
||||
expect(Spree::Config.account_invoices_monthly_cap).to eq 30
|
||||
expect(Spree::Config.account_invoices_tax_rate).to eq 0.15
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -493,36 +493,6 @@ xfeature %q{
|
||||
xero_invoice_summary_row('Delivery Shipping Cost (tax inclusive)', 100.55, 'GST on Income', opts)
|
||||
]
|
||||
end
|
||||
|
||||
describe "account invoices" do
|
||||
let(:accounts_distributor) { create(:distributor_enterprise) }
|
||||
let(:billable_period) { create(:billable_period, account_invoice: account_invoice) }
|
||||
let(:account_invoice) { create(:account_invoice, order: account_invoice_order) }
|
||||
let!(:account_invoice_order) { create(:order, order_cycle: order_cycle, distributor: accounts_distributor) }
|
||||
let!(:adjustment) { create(:adjustment, adjustable: account_invoice_order, source: billable_period, label: 'Account invoice item', amount: 12.34) } # Tax?
|
||||
|
||||
before do
|
||||
Spree::Config.accounts_distributor_id = accounts_distributor.id
|
||||
|
||||
account_invoice_order.update_attribute :email, 'customer@email.com'
|
||||
Timecop.travel(Time.zone.local(2015, 4, 25, 14, 0, 0)) { account_invoice_order.finalize! }
|
||||
|
||||
visit current_path
|
||||
end
|
||||
|
||||
it "generates a detailed report for account invoices" do
|
||||
select 'Detailed', from: 'report_type'
|
||||
select accounts_distributor.name, from: 'q_distributor_id_eq'
|
||||
click_button 'Search'
|
||||
|
||||
opts = {}
|
||||
|
||||
expect(xero_invoice_table).to match_table [
|
||||
xero_invoice_header,
|
||||
xero_invoice_account_invoice_row(adjustment)
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
@@ -549,11 +519,6 @@ xfeature %q{
|
||||
xero_invoice_row('', adjustment.label, adjustment.amount, '1', tax_type, opts)
|
||||
end
|
||||
|
||||
def xero_invoice_account_invoice_row(adjustment, opts={})
|
||||
opts.reverse_merge!({customer_name: '', address1: '', city: '', state: '', zipcode: '', country: '', invoice_number: account_invoice_order.number, order_number: account_invoice_order.number})
|
||||
xero_invoice_adjustment_row(adjustment, opts)
|
||||
end
|
||||
|
||||
def xero_invoice_row(sku, description, amount, quantity, tax_type, opts={})
|
||||
opts.reverse_merge!({customer_name: 'Customer Name', address1: 'customer l1', city: 'customer city', state: 'Victoria', zipcode: '1234', country: country.name, invoice_number: order1.number, order_number: order1.number, invoice_date: '2015-04-26', due_date: '2015-05-26', account_code: 'food sales'})
|
||||
|
||||
|
||||
@@ -13,12 +13,9 @@ feature %q{
|
||||
let!(:distributor2) { create(:distributor_enterprise) }
|
||||
let!(:distributor_credit) { create(:distributor_enterprise) }
|
||||
let!(:distributor_without_orders) { create(:distributor_enterprise) }
|
||||
let!(:accounts_distributor) {create :distributor_enterprise}
|
||||
let!(:order_account_invoice) { create(:order, distributor: accounts_distributor, state: 'complete', user: user) }
|
||||
|
||||
context "as a logged in user" do
|
||||
before do
|
||||
Spree::Config.accounts_distributor_id = accounts_distributor.id
|
||||
login_as user
|
||||
end
|
||||
|
||||
@@ -42,9 +39,6 @@ feature %q{
|
||||
|
||||
expect(page).to have_content I18n.t('spree.users.orders.past_orders')
|
||||
|
||||
# Doesn't show orders from the special Accounts & Billing distributor
|
||||
expect(page).not_to have_content accounts_distributor.name
|
||||
|
||||
# Lists all other orders
|
||||
expect(page).to have_content d1o1.number.to_s
|
||||
expect(page).to have_content d1o2.number.to_s
|
||||
@@ -59,8 +53,6 @@ feature %q{
|
||||
expect(page).to have_content distributor2.name
|
||||
expect(page).not_to have_content distributor_without_orders.name
|
||||
|
||||
# Exclude the special Accounts & Billing distributor
|
||||
expect(page).not_to have_content accounts_distributor.name
|
||||
expect(page).to have_content distributor1.name + " " + "Balance due"
|
||||
expect(page).to have_content distributor_credit.name + " Credit"
|
||||
|
||||
|
||||
@@ -1,574 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Admin::BusinessModelConfigurationHelper, type: :helper do
|
||||
describe "describing monthly bills for enterprises" do
|
||||
|
||||
context "when there is no free trial" do
|
||||
before { Spree::Config.set(:shop_trial_length_days, 0) }
|
||||
|
||||
context "when tax is applied to the service change" do
|
||||
before { Spree::Config.set(:account_invoices_tax_rate, 0.1) }
|
||||
|
||||
context "when minimum billable turnover is zero" do
|
||||
before { Spree::Config.set(:minimum_billable_turnover, 0) }
|
||||
|
||||
context "when a fixed cost is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 10) }
|
||||
|
||||
context "when a percentage of turnover is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0.05) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(helper.monthly_bill_description).to eq "#{with_currency(10, no_cents: true)} + 5.0% OF SALES, CAPPED AT #{with_currency(20, no_cents: true)} PER MONTH, PLUS GST" }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(helper.monthly_bill_description).to eq "#{with_currency(10, no_cents: true)} + 5.0% OF SALES PER MONTH, PLUS GST" }
|
||||
end
|
||||
end
|
||||
|
||||
context "when a percentage of turnover is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(helper.monthly_bill_description).to eq "#{with_currency(10, no_cents: true)} PER MONTH, PLUS GST" }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(helper.monthly_bill_description).to eq "#{with_currency(10, no_cents: true)} PER MONTH, PLUS GST" }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when a fixed cost is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 0) }
|
||||
|
||||
context "when a percentage of turnover is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0.05) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(helper.monthly_bill_description).to eq "5.0% OF SALES, CAPPED AT #{with_currency(20, no_cents: true)} PER MONTH, PLUS GST" }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(helper.monthly_bill_description).to eq "5.0% OF SALES PER MONTH, PLUS GST" }
|
||||
end
|
||||
end
|
||||
|
||||
context "when a percentage of turnover is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE" }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE" }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when minimum billable turnover is 100" do
|
||||
before { Spree::Config.set(:minimum_billable_turnover, 100) }
|
||||
|
||||
context "when a fixed cost is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 10) }
|
||||
|
||||
context "when a percentage of turnover is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0.05) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(helper.monthly_bill_description).to eq "#{with_currency(10, no_cents: true)} + 5.0% OF SALES ONCE TURNOVER EXCEEDS #{with_currency(100, no_cents: true)}, CAPPED AT #{with_currency(20, no_cents: true)} PER MONTH, PLUS GST" }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(helper.monthly_bill_description).to eq "#{with_currency(10, no_cents: true)} + 5.0% OF SALES ONCE TURNOVER EXCEEDS #{with_currency(100, no_cents: true)} PER MONTH, PLUS GST" }
|
||||
end
|
||||
end
|
||||
|
||||
context "when a percentage of turnover is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(helper.monthly_bill_description).to eq "#{with_currency(10, no_cents: true)} PER MONTH, PLUS GST" }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(helper.monthly_bill_description).to eq "#{with_currency(10, no_cents: true)} PER MONTH, PLUS GST" }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when a fixed cost is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 0) }
|
||||
|
||||
context "when a percentage of turnover is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0.05) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(helper.monthly_bill_description).to eq "5.0% OF SALES ONCE TURNOVER EXCEEDS #{with_currency(100, no_cents: true)}, CAPPED AT #{with_currency(20, no_cents: true)} PER MONTH, PLUS GST" }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(helper.monthly_bill_description).to eq "5.0% OF SALES ONCE TURNOVER EXCEEDS #{with_currency(100, no_cents: true)} PER MONTH, PLUS GST" }
|
||||
end
|
||||
end
|
||||
|
||||
context "when a percentage of turnover is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE" }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE" }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when tax is not applied to the service change" do
|
||||
before { Spree::Config.set(:account_invoices_tax_rate, 0.0) }
|
||||
|
||||
context "when minimum billable turnover is zero" do
|
||||
before { Spree::Config.set(:minimum_billable_turnover, 0) }
|
||||
|
||||
context "when a fixed cost is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 10) }
|
||||
|
||||
context "when a percentage of turnover is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0.05) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(helper.monthly_bill_description).to eq "#{with_currency(10, no_cents: true)} + 5.0% OF SALES, CAPPED AT #{with_currency(20, no_cents: true)} PER MONTH" }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(helper.monthly_bill_description).to eq "#{with_currency(10, no_cents: true)} + 5.0% OF SALES PER MONTH" }
|
||||
end
|
||||
end
|
||||
|
||||
context "when a percentage of turnover is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(helper.monthly_bill_description).to eq "#{with_currency(10, no_cents: true)} PER MONTH" }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(helper.monthly_bill_description).to eq "#{with_currency(10, no_cents: true)} PER MONTH" }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when a fixed cost is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 0) }
|
||||
|
||||
context "when a percentage of turnover is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0.05) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(helper.monthly_bill_description).to eq "5.0% OF SALES, CAPPED AT #{with_currency(20, no_cents: true)} PER MONTH" }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(helper.monthly_bill_description).to eq "5.0% OF SALES PER MONTH" }
|
||||
end
|
||||
end
|
||||
|
||||
context "when a percentage of turnover is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE" }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE" }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when minimum billable turnover is 100" do
|
||||
before { Spree::Config.set(:minimum_billable_turnover, 100) }
|
||||
|
||||
context "when a fixed cost is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 10) }
|
||||
|
||||
context "when a percentage of turnover is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0.05) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(helper.monthly_bill_description).to eq "#{with_currency(10, no_cents: true)} + 5.0% OF SALES ONCE TURNOVER EXCEEDS #{with_currency(100, no_cents: true)}, CAPPED AT #{with_currency(20, no_cents: true)} PER MONTH" }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(helper.monthly_bill_description).to eq "#{with_currency(10, no_cents: true)} + 5.0% OF SALES ONCE TURNOVER EXCEEDS #{with_currency(100, no_cents: true)} PER MONTH" }
|
||||
end
|
||||
end
|
||||
|
||||
context "when a percentage of turnover is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(helper.monthly_bill_description).to eq "#{with_currency(10, no_cents: true)} PER MONTH" }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(helper.monthly_bill_description).to eq "#{with_currency(10, no_cents: true)} PER MONTH" }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when a fixed cost is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 0) }
|
||||
|
||||
context "when a percentage of turnover is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0.05) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(helper.monthly_bill_description).to eq "5.0% OF SALES ONCE TURNOVER EXCEEDS #{with_currency(100, no_cents: true)}, CAPPED AT #{with_currency(20, no_cents: true)} PER MONTH" }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(helper.monthly_bill_description).to eq "5.0% OF SALES ONCE TURNOVER EXCEEDS #{with_currency(100, no_cents: true)} PER MONTH" }
|
||||
end
|
||||
end
|
||||
|
||||
context "when a percentage of turnover is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE" }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE" }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when there is a 30 day free trial" do
|
||||
before { Spree::Config.set(:shop_trial_length_days, 30) }
|
||||
|
||||
context "when tax is applied to the service change" do
|
||||
before { Spree::Config.set(:account_invoices_tax_rate, 0.1) }
|
||||
|
||||
context "when minimum billable turnover is zero" do
|
||||
before { Spree::Config.set(:minimum_billable_turnover, 0) }
|
||||
|
||||
context "when a fixed cost is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 10) }
|
||||
|
||||
context "when a percentage of turnover is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0.05) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE TRIAL THEN #{with_currency(10, no_cents: true)} + 5.0% OF SALES, CAPPED AT #{with_currency(20, no_cents: true)} PER MONTH, PLUS GST" }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE TRIAL THEN #{with_currency(10, no_cents: true)} + 5.0% OF SALES PER MONTH, PLUS GST" }
|
||||
end
|
||||
end
|
||||
|
||||
context "when a percentage of turnover is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE TRIAL THEN #{with_currency(10, no_cents: true)} PER MONTH, PLUS GST" }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE TRIAL THEN #{with_currency(10, no_cents: true)} PER MONTH, PLUS GST" }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when a fixed cost is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 0) }
|
||||
|
||||
context "when a percentage of turnover is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0.05) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE TRIAL THEN 5.0% OF SALES, CAPPED AT #{with_currency(20, no_cents: true)} PER MONTH, PLUS GST" }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE TRIAL THEN 5.0% OF SALES PER MONTH, PLUS GST" }
|
||||
end
|
||||
end
|
||||
|
||||
context "when a percentage of turnover is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE" }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE" }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when minimum billable turnover is 100" do
|
||||
before { Spree::Config.set(:minimum_billable_turnover, 100) }
|
||||
|
||||
context "when a fixed cost is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 10) }
|
||||
|
||||
context "when a percentage of turnover is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0.05) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE TRIAL THEN #{with_currency(10, no_cents: true)} + 5.0% OF SALES ONCE TURNOVER EXCEEDS #{with_currency(100, no_cents: true)}, CAPPED AT #{with_currency(20, no_cents: true)} PER MONTH, PLUS GST" }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE TRIAL THEN #{with_currency(10, no_cents: true)} + 5.0% OF SALES ONCE TURNOVER EXCEEDS #{with_currency(100, no_cents: true)} PER MONTH, PLUS GST" }
|
||||
end
|
||||
end
|
||||
|
||||
context "when a percentage of turnover is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE TRIAL THEN #{with_currency(10, no_cents: true)} PER MONTH, PLUS GST" }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE TRIAL THEN #{with_currency(10, no_cents: true)} PER MONTH, PLUS GST" }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when a fixed cost is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 0) }
|
||||
|
||||
context "when a percentage of turnover is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0.05) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE TRIAL THEN 5.0% OF SALES ONCE TURNOVER EXCEEDS #{with_currency(100, no_cents: true)}, CAPPED AT #{with_currency(20, no_cents: true)} PER MONTH, PLUS GST" }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE TRIAL THEN 5.0% OF SALES ONCE TURNOVER EXCEEDS #{with_currency(100, no_cents: true)} PER MONTH, PLUS GST" }
|
||||
end
|
||||
end
|
||||
|
||||
context "when a percentage of turnover is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE" }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE" }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when tax is not applied to the service change" do
|
||||
before { Spree::Config.set(:account_invoices_tax_rate, 0.0) }
|
||||
|
||||
context "when minimum billable turnover is zero" do
|
||||
before { Spree::Config.set(:minimum_billable_turnover, 0) }
|
||||
|
||||
context "when a fixed cost is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 10) }
|
||||
|
||||
context "when a percentage of turnover is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0.05) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE TRIAL THEN #{with_currency(10, no_cents: true)} + 5.0% OF SALES, CAPPED AT #{with_currency(20, no_cents: true)} PER MONTH" }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE TRIAL THEN #{with_currency(10, no_cents: true)} + 5.0% OF SALES PER MONTH" }
|
||||
end
|
||||
end
|
||||
|
||||
context "when a percentage of turnover is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE TRIAL THEN #{with_currency(10, no_cents: true)} PER MONTH" }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE TRIAL THEN #{with_currency(10, no_cents: true)} PER MONTH" }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when a fixed cost is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 0) }
|
||||
|
||||
context "when a percentage of turnover is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0.05) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE TRIAL THEN 5.0% OF SALES, CAPPED AT #{with_currency(20, no_cents: true)} PER MONTH" }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE TRIAL THEN 5.0% OF SALES PER MONTH" }
|
||||
end
|
||||
end
|
||||
|
||||
context "when a percentage of turnover is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE" }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE" }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when minimum billable turnover is 100" do
|
||||
before { Spree::Config.set(:minimum_billable_turnover, 100) }
|
||||
|
||||
context "when a fixed cost is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 10) }
|
||||
|
||||
context "when a percentage of turnover is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0.05) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE TRIAL THEN #{with_currency(10, no_cents: true)} + 5.0% OF SALES ONCE TURNOVER EXCEEDS #{with_currency(100, no_cents: true)}, CAPPED AT #{with_currency(20, no_cents: true)} PER MONTH" }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE TRIAL THEN #{with_currency(10, no_cents: true)} + 5.0% OF SALES ONCE TURNOVER EXCEEDS #{with_currency(100, no_cents: true)} PER MONTH" }
|
||||
end
|
||||
end
|
||||
|
||||
context "when a percentage of turnover is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE TRIAL THEN #{with_currency(10, no_cents: true)} PER MONTH" }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE TRIAL THEN #{with_currency(10, no_cents: true)} PER MONTH" }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when a fixed cost is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 0) }
|
||||
|
||||
context "when a percentage of turnover is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0.05) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE TRIAL THEN 5.0% OF SALES ONCE TURNOVER EXCEEDS #{with_currency(100, no_cents: true)}, CAPPED AT #{with_currency(20, no_cents: true)} PER MONTH" }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE TRIAL THEN 5.0% OF SALES ONCE TURNOVER EXCEEDS #{with_currency(100, no_cents: true)} PER MONTH" }
|
||||
end
|
||||
end
|
||||
|
||||
context "when a percentage of turnover is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE" }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(helper.monthly_bill_description).to eq "FREE" }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,216 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
def travel_to(time)
|
||||
around { |example| Timecop.travel(start_of_july + time) { example.run } }
|
||||
end
|
||||
|
||||
|
||||
xdescribe FinalizeAccountInvoices do
|
||||
let!(:year) { Time.zone.now.year }
|
||||
|
||||
describe "unit specs" do
|
||||
let!(:finalizer) { FinalizeAccountInvoices.new }
|
||||
let!(:start_of_july) { Time.zone.local(year, 7) }
|
||||
|
||||
describe "perform" do
|
||||
let!(:accounts_distributor) { create(:distributor_enterprise) }
|
||||
|
||||
#Invoice from June
|
||||
let!(:account_invoice1) { create(:account_invoice, year: year, month: 6, order: create(:order, completed_at: nil))}
|
||||
|
||||
# We don't care when it was completed, in the future or past
|
||||
let!(:account_invoice2) { create(:account_invoice, year: year, month: 6, order: create(:order, completed_at: start_of_july - 10.days))}
|
||||
let!(:account_invoice3) { create(:account_invoice, year: year, month: 6, order: create(:order, completed_at: start_of_july + 10.days))}
|
||||
|
||||
# Invoices from July
|
||||
let!(:account_invoice4) { create(:account_invoice, year: year, month: 7, order: create(:order, completed_at: nil))}
|
||||
let!(:account_invoice5) { create(:account_invoice, year: year, month: 7, order: create(:order, completed_at: start_of_july + 10.days))}
|
||||
|
||||
before do
|
||||
allow(Enterprise).to receive(:find_by_id) { accounts_distributor }
|
||||
allow(accounts_distributor).to receive(:payment_methods) { double(:payment_methods, find_by_id: true) }
|
||||
allow(accounts_distributor).to receive(:shipping_methods) { double(:shipping_methods, find_by_id: true) }
|
||||
allow(finalizer).to receive(:finalize)
|
||||
allow(Bugsnag).to receive(:notify)
|
||||
end
|
||||
|
||||
context "when necessary global config setting have not been set" do
|
||||
travel_to(20.days)
|
||||
|
||||
context "when accounts_distributor has been set" do
|
||||
before do
|
||||
allow(Enterprise).to receive(:find_by_id) { false }
|
||||
finalizer.perform
|
||||
end
|
||||
|
||||
it "snags errors and doesn't run" do
|
||||
expect(Bugsnag).to have_received(:notify).with(RuntimeError.new("InvalidJobSettings"), anything)
|
||||
expect(finalizer).to_not have_received(:finalize)
|
||||
end
|
||||
end
|
||||
|
||||
context "when default payment method has been set" do
|
||||
before do
|
||||
allow(accounts_distributor).to receive(:payment_methods) { double(:payment_methods, find_by_id: false) }
|
||||
finalizer.perform
|
||||
end
|
||||
|
||||
it "snags errors and doesn't run" do
|
||||
expect(Bugsnag).to have_received(:notify).with(RuntimeError.new("InvalidJobSettings"), anything)
|
||||
expect(finalizer).to_not have_received(:finalize)
|
||||
end
|
||||
end
|
||||
|
||||
context "when default shipping method has been set" do
|
||||
before do
|
||||
allow(accounts_distributor).to receive(:shipping_methods) { double(:shipping_methods, find_by_id: false) }
|
||||
finalizer.perform
|
||||
end
|
||||
|
||||
it "snags errors and doesn't run" do
|
||||
expect(Bugsnag).to have_received(:notify).with(RuntimeError.new("InvalidJobSettings"), anything)
|
||||
expect(finalizer).to_not have_received(:finalize)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when necessary global config setting have been set" do
|
||||
context "and no date arguments are passed to the job" do
|
||||
travel_to(3.days)
|
||||
|
||||
it "finalizes the uncompleted orders from account_invoices for the previous calendar month" do
|
||||
finalizer.perform
|
||||
expect(finalizer).to have_received(:finalize).with(account_invoice1.order)
|
||||
expect(finalizer).to_not have_received(:finalize).with(account_invoice2.order)
|
||||
expect(finalizer).to_not have_received(:finalize).with(account_invoice3.order)
|
||||
expect(finalizer).to_not have_received(:finalize).with(account_invoice4.order)
|
||||
expect(finalizer).to_not have_received(:finalize).with(account_invoice5.order)
|
||||
end
|
||||
end
|
||||
|
||||
context "and a specific year and month are passed as arguments" do
|
||||
let!(:finalizer) { FinalizeAccountInvoices.new(year, 7) }
|
||||
|
||||
before do
|
||||
allow(finalizer).to receive(:finalizer)
|
||||
end
|
||||
|
||||
context "that ends in the past" do
|
||||
travel_to(1.month + 3.hours)
|
||||
|
||||
it "finalizes the uncompleted orders from account_invoices for the specified calendar month" do
|
||||
finalizer.perform
|
||||
expect(finalizer).to_not have_received(:finalize).with(account_invoice1.order)
|
||||
expect(finalizer).to_not have_received(:finalize).with(account_invoice2.order)
|
||||
expect(finalizer).to_not have_received(:finalize).with(account_invoice3.order)
|
||||
expect(finalizer).to have_received(:finalize).with(account_invoice4.order)
|
||||
expect(finalizer).to_not have_received(:finalize).with(account_invoice5.order)
|
||||
end
|
||||
end
|
||||
|
||||
context "that ends in the future" do
|
||||
travel_to 3.days
|
||||
|
||||
it "does not finalize any orders" do
|
||||
finalizer.perform
|
||||
expect(Bugsnag).to have_received(:notify).with(RuntimeError.new("InvalidJobSettings"), anything)
|
||||
expect(finalizer).to_not have_received(:finalize)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "finalize" do
|
||||
let!(:pm) { create(:payment_method, name: "PM1") }
|
||||
let!(:sm) { create(:shipping_method, name: "ship1") }
|
||||
let!(:accounts_distributor) { create(:distributor_enterprise, payment_methods: [pm], shipping_methods: [sm]) }
|
||||
let!(:invoice_order) { create(:order, distributor: accounts_distributor) }
|
||||
|
||||
before do
|
||||
Spree::Config.set({ accounts_distributor_id: accounts_distributor.id })
|
||||
Spree::Config.set({ default_accounts_payment_method_id: pm.id })
|
||||
Spree::Config.set({ default_accounts_shipping_method_id: sm.id })
|
||||
invoice_order.line_items.clear
|
||||
end
|
||||
|
||||
it "creates payment, assigns shipping method and finalizes the order" do
|
||||
expect(invoice_order.completed_at).to be nil
|
||||
finalizer.finalize(invoice_order)
|
||||
expect(invoice_order.completed_at).to_not be nil
|
||||
expect(invoice_order.payments.count).to eq 1
|
||||
expect(invoice_order.payments.first.payment_method).to eq pm
|
||||
expect(invoice_order.shipping_method).to eq sm
|
||||
end
|
||||
|
||||
it "does not send a confirmation email" do
|
||||
expect(invoice_order).to receive(:deliver_order_confirmation_email).and_call_original
|
||||
expect{finalizer.finalize(invoice_order)}.to_not enqueue_job ConfirmOrderJob
|
||||
end
|
||||
|
||||
context "when errors exist on the order" do
|
||||
before do
|
||||
allow(invoice_order).to receive(:errors) { double(:errors, any?: true, full_messages: ["Error message 1", "Error message 2"]) }
|
||||
allow(Bugsnag).to receive(:notify)
|
||||
end
|
||||
|
||||
it "Snags a bug and does not finalize the order" do
|
||||
finalizer.finalize(invoice_order)
|
||||
expect(Bugsnag).to have_received(:notify).with(RuntimeError.new("FinalizeInvoiceError"), anything)
|
||||
expect(invoice_order).to_not be_completed
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "validation spec" do
|
||||
let!(:start_of_july) { Time.zone.local(year, 7) }
|
||||
|
||||
let!(:updater) { UpdateAccountInvoices.new }
|
||||
let!(:finalizer) { FinalizeAccountInvoices.new }
|
||||
|
||||
let!(:pm) { create(:payment_method, name: "Default Payment Method") }
|
||||
let!(:sm) { create(:shipping_method, name: "Default Shipping Method") }
|
||||
let!(:accounts_distributor) { create(:distributor_enterprise, payment_methods: [pm], shipping_methods: [sm]) }
|
||||
|
||||
let!(:user) { create(:user) }
|
||||
let!(:billable_period1) { create(:billable_period, sells: 'any', owner: user, begins_at: start_of_july - 1.month, ends_at: start_of_july) }
|
||||
let!(:billable_period2) { create(:billable_period, owner: user, begins_at: start_of_july, ends_at: start_of_july + 10.days) }
|
||||
let!(:billable_period3) { create(:billable_period, owner: user, begins_at: start_of_july + 12.days, ends_at: start_of_july + 20.days) }
|
||||
|
||||
before do
|
||||
sm.calculator.set_preference(:amount, 0); sm.calculator.save!
|
||||
|
||||
Spree::Config.set({ accounts_distributor_id: accounts_distributor.id })
|
||||
Spree::Config.set({ default_accounts_payment_method_id: pm.id })
|
||||
Spree::Config.set({ default_accounts_shipping_method_id: sm.id })
|
||||
|
||||
# Make sure that bills are > 0
|
||||
Spree::Config.set(:account_invoices_monthly_fixed, 5)
|
||||
Spree::Config.set(:account_invoices_monthly_rate, 0.02)
|
||||
Spree::Config.set(:account_invoices_monthly_cap, 50)
|
||||
Spree::Config.set(:minimum_billable_turnover, 0)
|
||||
end
|
||||
|
||||
context "finalizing an invoice" do
|
||||
travel_to(3.hours)
|
||||
|
||||
it "finalizes it" do
|
||||
# Create an invoice using the updater, to make sure we are using
|
||||
# an order as it would be when generated this way
|
||||
expect{updater.perform}.to change{Spree::Order.count}.from(0).to(1)
|
||||
invoice = user.orders.first
|
||||
|
||||
# Finalize invoices
|
||||
finalizer.perform
|
||||
invoice.reload
|
||||
|
||||
expect(invoice.completed_at).to_not be_nil
|
||||
expect(invoice.total).to eq billable_period1.bill.round(2)
|
||||
expect(invoice.payments.count).to eq 1
|
||||
expect(invoice.payments.first.amount).to eq billable_period1.bill.round(2)
|
||||
expect(invoice.state).to eq 'complete'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,448 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
def travel_to(time)
|
||||
around { |example| Timecop.travel(start_of_july + time) { example.run } }
|
||||
end
|
||||
|
||||
xdescribe UpdateAccountInvoices do
|
||||
let(:year) { Time.zone.now.year }
|
||||
|
||||
before do
|
||||
# Make sure that bills are > 0
|
||||
Spree::Config.set(:account_invoices_monthly_fixed, 5)
|
||||
Spree::Config.set(:account_invoices_monthly_rate, 0.02)
|
||||
Spree::Config.set(:account_invoices_monthly_cap, 50)
|
||||
Spree::Config.set(:minimum_billable_turnover, 0)
|
||||
end
|
||||
|
||||
describe "units specs" do
|
||||
let!(:start_of_july) { Time.zone.local(year, 7) }
|
||||
|
||||
let!(:updater) { UpdateAccountInvoices.new }
|
||||
|
||||
let!(:user) { create(:user) }
|
||||
let!(:june_billable_period1) { create(:billable_period, owner: user, begins_at: start_of_july - 1.month, ends_at: start_of_july - 20.days) }
|
||||
let!(:june_billable_period2) { create(:billable_period, owner: user, begins_at: start_of_july - 20.days, ends_at: start_of_july - 10.days, turnover: 45, sells: "none" ) }
|
||||
let!(:june_billable_period3) { create(:billable_period, owner: user, begins_at: start_of_july - 10.days, ends_at: start_of_july - 1.days, turnover: 0, sells: "any" ) }
|
||||
let!(:july_billable_period1) { create(:billable_period, owner: user, begins_at: start_of_july, ends_at: start_of_july + 12.days) }
|
||||
let!(:july_billable_period2) { create(:billable_period, owner: user, begins_at: start_of_july + 12.days, ends_at: start_of_july + 20.days) }
|
||||
let!(:july_billable_period3) { create(:billable_period, owner: user, begins_at: start_of_july + 20.days, ends_at: start_of_july + 25.days, turnover: 45, sells: 'none') }
|
||||
let!(:july_billable_period4) { create(:billable_period, owner: user, begins_at: start_of_july + 25.days, ends_at: start_of_july + 28.days, turnover: 0, sells: 'any') }
|
||||
let(:june_account_invoice) { june_billable_period1.account_invoice }
|
||||
let(:july_account_invoice) { july_billable_period1.account_invoice }
|
||||
|
||||
describe "perform" do
|
||||
let(:accounts_distributor) { double(:accounts_distributor) }
|
||||
before do
|
||||
allow(Enterprise).to receive(:find_by_id) { accounts_distributor }
|
||||
allow(updater).to receive(:update)
|
||||
allow(Bugsnag).to receive(:notify)
|
||||
end
|
||||
|
||||
context "when necessary global config setting have not been set" do
|
||||
travel_to(20.days)
|
||||
|
||||
context "when accounts_distributor has been set" do
|
||||
before do
|
||||
allow(Enterprise).to receive(:find_by_id) { false }
|
||||
updater.perform
|
||||
end
|
||||
|
||||
it "snags errors and doesn't run" do
|
||||
expect(Bugsnag).to have_received(:notify).with(RuntimeError.new("InvalidJobSettings"), anything)
|
||||
expect(updater).to_not have_received(:update)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when necessary global config setting have been set" do
|
||||
context "on the first of the month" do
|
||||
travel_to(3.hours)
|
||||
|
||||
it "updates invoices from the previous month" do
|
||||
updater.perform
|
||||
expect(updater).to have_received(:update).once
|
||||
.with(june_account_invoice)
|
||||
expect(updater).to_not have_received(:update)
|
||||
.with(july_account_invoice)
|
||||
end
|
||||
end
|
||||
|
||||
context "on other days" do
|
||||
travel_to(20.days)
|
||||
|
||||
it "updates invoices from the current month" do
|
||||
updater.perform
|
||||
expect(updater).to have_received(:update).once
|
||||
.with(july_account_invoice)
|
||||
end
|
||||
end
|
||||
|
||||
context "when specfic a specific month (and year) are passed as arguments" do
|
||||
let!(:updater) { UpdateAccountInvoices.new(year, 7) }
|
||||
|
||||
before do
|
||||
allow(updater).to receive(:update)
|
||||
end
|
||||
|
||||
context "that just ended (in the past)" do
|
||||
travel_to(1.month)
|
||||
|
||||
it "updates invoices from the previous month" do
|
||||
updater.perform
|
||||
expect(updater).to have_received(:update).once
|
||||
.with(july_account_invoice)
|
||||
end
|
||||
end
|
||||
|
||||
context "that starts in the past and ends in the future (ie. current_month)" do
|
||||
travel_to 30.days
|
||||
|
||||
it "updates invoices from that current month" do
|
||||
updater.perform
|
||||
expect(updater).to have_received(:update).once
|
||||
.with(july_account_invoice)
|
||||
end
|
||||
end
|
||||
|
||||
context "that starts in the future" do
|
||||
travel_to(-1.days)
|
||||
|
||||
it "snags an error and does not update invoices" do
|
||||
updater.perform
|
||||
expect(Bugsnag).to have_received(:notify).with(RuntimeError.new("InvalidJobSettings"), anything)
|
||||
expect(updater).to_not have_received(:update)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "update" do
|
||||
before do
|
||||
allow(june_account_invoice).to receive(:save).and_call_original
|
||||
allow(july_account_invoice).to receive(:save).and_call_original
|
||||
allow(updater).to receive(:clean_up)
|
||||
allow(updater).to receive(:finalize)
|
||||
allow(Bugsnag).to receive(:notify)
|
||||
end
|
||||
|
||||
context "where an order for the invoice already exists" do
|
||||
let!(:invoice_order) { create(:order, user: user) }
|
||||
|
||||
before do
|
||||
expect(Spree::Order).to_not receive(:new)
|
||||
allow(june_account_invoice).to receive(:order) { invoice_order }
|
||||
end
|
||||
|
||||
context "where the order is already complete" do
|
||||
before do
|
||||
allow(invoice_order).to receive(:complete?) { true }
|
||||
updater.update(june_account_invoice)
|
||||
end
|
||||
|
||||
it "snags a bug" do
|
||||
expect(Bugsnag).to have_received(:notify)
|
||||
end
|
||||
|
||||
it "does not save the order" do
|
||||
expect(june_account_invoice).to_not have_received(:save)
|
||||
end
|
||||
|
||||
it "does not clean up the order" do
|
||||
expect(updater).to_not have_received(:clean_up).with(invoice_order, anything)
|
||||
end
|
||||
end
|
||||
|
||||
context "where the order is not complete" do
|
||||
before do
|
||||
allow(invoice_order).to receive(:complete?) { false }
|
||||
june_billable_period1.enterprise.update_attributes(contact_name: "Firstname Lastname Something Else", phone: '12345')
|
||||
updater.update(june_account_invoice)
|
||||
end
|
||||
|
||||
it "creates adjustments for each billing item where bill is not 0" do
|
||||
adjustments = invoice_order.adjustments
|
||||
expect(adjustments.map(&:source_id)).to eq [june_billable_period1.id, june_billable_period3.id]
|
||||
expect(adjustments.map(&:amount)).to eq [june_billable_period1.bill.round(2), june_billable_period3.bill.round(2)]
|
||||
expect(adjustments.map(&:label)).to eq [june_billable_period1.adjustment_label, june_billable_period3.adjustment_label]
|
||||
end
|
||||
|
||||
it "assigns a addresses to the order" do
|
||||
expect(invoice_order.billing_address).to be_a Spree::Address
|
||||
expect(invoice_order.shipping_address).to be_a Spree::Address
|
||||
expect(invoice_order.shipping_address).to eq invoice_order.billing_address
|
||||
[:address1, :address2, :city, :zipcode, :state_id, :country_id].each do |attr|
|
||||
expect(invoice_order.billing_address[attr]).to eq june_billable_period1.enterprise.address[attr]
|
||||
end
|
||||
expect(invoice_order.billing_address.firstname).to eq "Firstname"
|
||||
expect(invoice_order.billing_address.lastname).to eq "Lastname Something Else"
|
||||
expect(invoice_order.billing_address.phone).to eq "12345"
|
||||
end
|
||||
|
||||
it "saves the order" do
|
||||
expect(june_account_invoice).to have_received(:save)
|
||||
expect(june_account_invoice.order).to be_persisted
|
||||
end
|
||||
|
||||
it "cleans up the order" do
|
||||
expect(updater).to have_received(:clean_up).with(invoice_order, anything).once
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "where an order for the invoice does not already exist" do
|
||||
let!(:accounts_distributor) { create(:distributor_enterprise) }
|
||||
before do
|
||||
Spree::Config.set({ accounts_distributor_id: accounts_distributor.id })
|
||||
updater.update(july_account_invoice)
|
||||
end
|
||||
|
||||
it "creates adjustments for each billing item where bill is not 0" do
|
||||
adjustments = july_account_invoice.order.adjustments
|
||||
expect(adjustments.map(&:source_id)).to eq [july_billable_period1.id, july_billable_period2.id,july_billable_period4.id]
|
||||
expect(adjustments.map(&:amount)).to eq [july_billable_period1.bill.round(2), july_billable_period2.bill.round(2), july_billable_period4.bill.round(2)]
|
||||
expect(adjustments.map(&:label)).to eq [july_billable_period1.adjustment_label, july_billable_period2.adjustment_label, july_billable_period4.adjustment_label]
|
||||
end
|
||||
|
||||
it "saves the order" do
|
||||
expect(july_account_invoice).to have_received(:save)
|
||||
expect(july_account_invoice.order).to be_persisted
|
||||
end
|
||||
|
||||
it "cleans up order" do
|
||||
expect(updater).to have_received(:clean_up).with(july_account_invoice.order, anything).once
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "clean_up" do
|
||||
let!(:invoice_order) { create(:order) }
|
||||
let!(:obsolete1) { create(:adjustment, adjustable: invoice_order) }
|
||||
let!(:obsolete2) { create(:adjustment, adjustable: invoice_order) }
|
||||
let!(:current1) { create(:adjustment, adjustable: invoice_order) }
|
||||
let!(:current2) { create(:adjustment, adjustable: invoice_order) }
|
||||
|
||||
before do
|
||||
allow(invoice_order).to receive(:save)
|
||||
allow(invoice_order).to receive(:destroy)
|
||||
allow(Bugsnag).to receive(:notify)
|
||||
end
|
||||
|
||||
context "when current adjustments are present" do
|
||||
let!(:current_adjustments) { [current1, current2] }
|
||||
|
||||
context "and obsolete adjustments are present" do
|
||||
let!(:obsolete_adjustments) { [obsolete1, obsolete2] }
|
||||
|
||||
before do
|
||||
allow(obsolete_adjustments).to receive(:destroy_all)
|
||||
allow(invoice_order).to receive(:adjustments) { double(:adjustments, where: obsolete_adjustments) }
|
||||
updater.clean_up(invoice_order, current_adjustments)
|
||||
end
|
||||
|
||||
it "destroys obsolete adjustments and snags a bug" do
|
||||
expect(obsolete_adjustments).to have_received(:destroy_all)
|
||||
expect(Bugsnag).to have_received(:notify).with(RuntimeError.new("Obsolete Adjustments"), anything)
|
||||
end
|
||||
end
|
||||
|
||||
context "and obsolete adjustments are not present" do
|
||||
let!(:obsolete_adjustments) { [] }
|
||||
|
||||
before do
|
||||
allow(invoice_order).to receive(:adjustments) { double(:adjustments, where: obsolete_adjustments) }
|
||||
updater.clean_up(invoice_order, current_adjustments)
|
||||
end
|
||||
|
||||
it "has no bugs to snag" do
|
||||
expect(Bugsnag).to_not have_received(:notify)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when current adjustments are not present" do
|
||||
let!(:current_adjustments) { [] }
|
||||
|
||||
context "and obsolete adjustments are present" do
|
||||
let!(:obsolete_adjustments) { [obsolete1, obsolete2] }
|
||||
|
||||
before do
|
||||
allow(obsolete_adjustments).to receive(:destroy_all)
|
||||
allow(invoice_order).to receive(:adjustments) { double(:adjustments, where: obsolete_adjustments) }
|
||||
end
|
||||
|
||||
it "destroys obsolete adjustments and snags a bug" do
|
||||
updater.clean_up(invoice_order, current_adjustments)
|
||||
expect(obsolete_adjustments).to have_received(:destroy_all)
|
||||
expect(Bugsnag).to have_received(:notify).with(RuntimeError.new("Obsolete Adjustments"), anything)
|
||||
end
|
||||
|
||||
context "when the order is not persisted" do
|
||||
before do
|
||||
allow(invoice_order).to receive(:persisted?) { false }
|
||||
end
|
||||
|
||||
it "destroys the order" do
|
||||
updater.clean_up(invoice_order, current_adjustments)
|
||||
expect(invoice_order).to have_received(:destroy)
|
||||
end
|
||||
end
|
||||
|
||||
context "when the order is persisted" do
|
||||
before do
|
||||
allow(invoice_order).to receive(:persisted?) { true }
|
||||
end
|
||||
|
||||
it "snags a bug" do
|
||||
updater.clean_up(invoice_order, current_adjustments)
|
||||
expect(Bugsnag).to have_received(:notify).with(RuntimeError.new("Empty Persisted Invoice"), anything)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "and obsolete adjustments are not present" do
|
||||
let!(:obsolete_adjustments) { [] }
|
||||
|
||||
before do
|
||||
allow(invoice_order).to receive(:adjustments) { double(:adjustments, where: obsolete_adjustments) }
|
||||
end
|
||||
|
||||
it "has no bugs to snag" do
|
||||
expect(Bugsnag).to_not have_received(:notify).with(RuntimeError.new("Obsolete Adjustments"), anything)
|
||||
end
|
||||
|
||||
context "when the order is not persisted" do
|
||||
before do
|
||||
allow(invoice_order).to receive(:persisted?) { false }
|
||||
end
|
||||
|
||||
it "destroys the order" do
|
||||
updater.clean_up(invoice_order, current_adjustments)
|
||||
expect(invoice_order).to have_received(:destroy)
|
||||
end
|
||||
end
|
||||
|
||||
context "when the order is persisted" do
|
||||
before do
|
||||
allow(invoice_order).to receive(:persisted?) { true }
|
||||
end
|
||||
|
||||
it "snags a bug" do
|
||||
updater.clean_up(invoice_order, current_adjustments)
|
||||
expect(Bugsnag).to have_received(:notify).with(RuntimeError.new("Empty Persisted Invoice"), anything)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "validation spec" do
|
||||
let!(:start_of_july) { Time.zone.local(year, 7) }
|
||||
|
||||
let!(:updater) { UpdateAccountInvoices.new }
|
||||
|
||||
let!(:accounts_distributor) { create(:distributor_enterprise) }
|
||||
|
||||
let!(:user) { create(:user) }
|
||||
let!(:july_billable_period1) { create(:billable_period, sells: 'any', owner: user, begins_at: start_of_july - 1.month, ends_at: start_of_july) }
|
||||
let!(:july_billable_period2) { create(:billable_period, owner: user, begins_at: start_of_july, ends_at: start_of_july + 10.days) }
|
||||
let!(:july_billable_period3) { create(:billable_period, owner: user, begins_at: start_of_july + 12.days, ends_at: start_of_july + 20.days) }
|
||||
let!(:july_account_invoice) { july_billable_period2.account_invoice }
|
||||
let!(:august_account_invoice) { create(:account_invoice, user: user, year: july_account_invoice.year, month: 8)}
|
||||
|
||||
before do
|
||||
Spree::Config.set({ accounts_distributor_id: accounts_distributor.id })
|
||||
july_billable_period2.enterprise.update_attributes(contact_name: 'Anna Karenina', phone: '3433523')
|
||||
end
|
||||
|
||||
context "when no invoice_order currently exists" do
|
||||
context "when relevant billable periods exist" do
|
||||
travel_to(20.days)
|
||||
|
||||
it "creates an invoice_order" do
|
||||
expect{updater.perform}.to change{Spree::Order.count}.from(0).to(1)
|
||||
invoice_order = july_account_invoice.reload.order
|
||||
expect(user.orders.first).to eq invoice_order
|
||||
expect(invoice_order.completed_at).to be_nil
|
||||
billable_adjustments = invoice_order.adjustments.where('source_type = (?)', 'BillablePeriod')
|
||||
expect(billable_adjustments.map(&:amount)).to eq [july_billable_period2.bill.round(2), july_billable_period3.bill.round(2)]
|
||||
expect(invoice_order.total).to eq july_billable_period2.bill.round(2) + july_billable_period3.bill.round(2)
|
||||
expect(invoice_order.payments.count).to eq 0
|
||||
expect(invoice_order.state).to eq 'cart'
|
||||
expect(invoice_order.bill_address).to be_a Spree::Address
|
||||
expect(invoice_order.ship_address).to be_a Spree::Address
|
||||
expect(invoice_order.shipping_address).to eq invoice_order.billing_address
|
||||
[:address1, :address2, :city, :zipcode, :state_id, :country_id].each do |attr|
|
||||
expect(invoice_order.billing_address[attr]).to eq july_billable_period2.enterprise.address[attr]
|
||||
end
|
||||
expect(invoice_order.billing_address.firstname).to eq "Anna"
|
||||
expect(invoice_order.billing_address.lastname).to eq "Karenina"
|
||||
expect(invoice_order.billing_address.phone).to eq "3433523"
|
||||
end
|
||||
end
|
||||
|
||||
context "when no relevant billable periods exist" do
|
||||
travel_to(1.month + 5.days)
|
||||
|
||||
it "does not create an order" do
|
||||
expect(updater).to receive(:update).with(august_account_invoice).and_call_original
|
||||
expect{updater.perform}.to_not change{Spree::Order.count}.from(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when an order already exists" do
|
||||
context "when relevant billable periods exist" do
|
||||
let!(:invoice_order) { create(:order, user: user, distributor: accounts_distributor, created_at: start_of_july) }
|
||||
let!(:billable_adjustment) { create(:adjustment, adjustable: invoice_order, source_type: 'BillablePeriod') }
|
||||
|
||||
before do
|
||||
invoice_order.line_items.clear
|
||||
july_account_invoice.update_attribute(:order, invoice_order)
|
||||
end
|
||||
|
||||
travel_to(20.days)
|
||||
|
||||
it "updates the order, and clears any obsolete invoices" do
|
||||
expect{updater.perform}.to_not change{Spree::Order.count}
|
||||
invoice_order = user.orders.first
|
||||
expect(invoice_order.completed_at).to be_nil
|
||||
billable_adjustments = invoice_order.adjustments.where('source_type = (?)', 'BillablePeriod')
|
||||
expect(billable_adjustments).to_not include billable_adjustment
|
||||
expect(billable_adjustments.map(&:amount)).to eq [july_billable_period2.bill.round(2), july_billable_period3.bill.round(2)]
|
||||
expect(invoice_order.total).to eq july_billable_period2.bill.round(2) + july_billable_period3.bill.round(2)
|
||||
expect(invoice_order.payments.count).to eq 0
|
||||
expect(invoice_order.state).to eq 'cart'
|
||||
expect(invoice_order.bill_address).to be_a Spree::Address
|
||||
expect(invoice_order.ship_address).to be_a Spree::Address
|
||||
expect(invoice_order.shipping_address).to eq invoice_order.billing_address
|
||||
[:address1, :address2, :city, :zipcode, :state_id, :country_id].each do |attr|
|
||||
expect(invoice_order.billing_address[attr]).to eq july_billable_period2.enterprise.address[attr]
|
||||
end
|
||||
expect(invoice_order.billing_address.firstname).to eq "Anna"
|
||||
expect(invoice_order.billing_address.lastname).to eq "Karenina"
|
||||
expect(invoice_order.billing_address.phone).to eq "3433523"
|
||||
end
|
||||
end
|
||||
|
||||
context "when no relevant billable periods exist" do
|
||||
let!(:invoice_order) { create(:order, user: user, distributor: accounts_distributor) }
|
||||
|
||||
before do
|
||||
invoice_order.line_items.clear
|
||||
august_account_invoice.update_attribute(:order, invoice_order)
|
||||
end
|
||||
|
||||
travel_to(1.month + 5.days)
|
||||
|
||||
it "snags a bug" do
|
||||
expect(updater).to receive(:update).with(august_account_invoice).and_call_original
|
||||
expect(Bugsnag).to receive(:notify).with(RuntimeError.new("Empty Persisted Invoice"), anything)
|
||||
expect{updater.perform}.to_not change{Spree::Order.count}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,725 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
def travel_to(time)
|
||||
around { |example| Timecop.travel(start_of_july + time) { example.run } }
|
||||
end
|
||||
|
||||
describe UpdateBillablePeriods do
|
||||
let!(:year) { Time.zone.now.year }
|
||||
|
||||
describe "unit specs" do
|
||||
let!(:start_of_july) { Time.zone.local(year, 7) }
|
||||
|
||||
let!(:updater) { UpdateBillablePeriods.new }
|
||||
|
||||
describe "perform", versioning: true do
|
||||
let!(:enterprise) { create(:supplier_enterprise, created_at: start_of_july - 1.month, sells: 'any') }
|
||||
|
||||
context "when no date arguments are passed to the job" do
|
||||
before do
|
||||
expect(updater).to receive(:clean_up_untouched_billable_periods_for).once
|
||||
end
|
||||
|
||||
context "on the first of the month" do
|
||||
travel_to(3.hours)
|
||||
|
||||
it "processes the previous month" do
|
||||
expect(updater).to receive(:split_for_trial)
|
||||
.with(enterprise, start_of_july - 1.month, start_of_july, nil, nil)
|
||||
updater.perform
|
||||
end
|
||||
end
|
||||
|
||||
context "on all other days" do
|
||||
travel_to(1.day + 3.hours)
|
||||
|
||||
it "processes the current month up until previous midnight" do
|
||||
expect(updater).to receive(:split_for_trial)
|
||||
.with(enterprise, start_of_july, start_of_july + 1.day, nil, nil)
|
||||
updater.perform
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when a specfic year and month are passed as arguments" do
|
||||
let!(:updater) { UpdateBillablePeriods.new(year, 6) }
|
||||
|
||||
before do
|
||||
allow(updater).to receive(:split_for_trial)
|
||||
end
|
||||
|
||||
context "that ends in the past" do
|
||||
travel_to(3.hours)
|
||||
|
||||
it "processes the month" do
|
||||
expect(updater).to receive(:split_for_trial)
|
||||
.with(enterprise, start_of_july - 1.month, start_of_july, nil, nil)
|
||||
updater.perform
|
||||
end
|
||||
end
|
||||
|
||||
context "that starts in the past and ends in the future (ie. current month)" do
|
||||
travel_to(-3.days)
|
||||
|
||||
it "processes the current month up to the previous midnight" do
|
||||
expect(updater).to receive(:split_for_trial)
|
||||
.with(enterprise, start_of_july - 1.month, start_of_july-3.days, nil, nil)
|
||||
updater.perform
|
||||
end
|
||||
end
|
||||
|
||||
context "that starts in the future" do
|
||||
travel_to(-31.days)
|
||||
|
||||
it "does not run" do
|
||||
expect(updater).to_not receive(:split_for_trial)
|
||||
updater.perform
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when an enterprise is created before the beginning of the current month" do
|
||||
before do
|
||||
expect(updater).to receive(:clean_up_untouched_billable_periods_for).once
|
||||
end
|
||||
|
||||
travel_to(28.days)
|
||||
|
||||
context "when no alterations to sells or owner have been made during the current month" do
|
||||
|
||||
it "begins at the start of the month" do
|
||||
expect(updater).to receive(:split_for_trial)
|
||||
.with(enterprise, start_of_july, start_of_july + 28.days, nil, nil)
|
||||
updater.perform
|
||||
end
|
||||
end
|
||||
|
||||
context "when sells has been changed within the current month" do
|
||||
before do
|
||||
Timecop.freeze(start_of_july + 10.days) do
|
||||
# NOTE: Sells is changed between when order1 and order2 are placed
|
||||
enterprise.update_attribute(:sells, 'own')
|
||||
end
|
||||
end
|
||||
|
||||
travel_to(28.days)
|
||||
|
||||
it "processes each sells period separately" do
|
||||
allow(updater).to receive(:split_for_trial).twice
|
||||
updater.perform
|
||||
|
||||
expect(updater).to have_received(:split_for_trial)
|
||||
.with(enterprise.versions.first.reify, start_of_july, start_of_july + 10.days, nil, nil)
|
||||
|
||||
expect(updater).to have_received(:split_for_trial)
|
||||
.with(enterprise, start_of_july + 10.days, start_of_july + 28.days, nil, nil)
|
||||
end
|
||||
end
|
||||
|
||||
context "when owner has been changed within the current month" do
|
||||
let!(:new_owner) { create(:user) }
|
||||
|
||||
before do
|
||||
Timecop.freeze(start_of_july + 10.days) do
|
||||
# NOTE: Sells is changed between when order1 and order2 are placed
|
||||
enterprise.update_attribute(:owner, new_owner)
|
||||
end
|
||||
end
|
||||
|
||||
travel_to(28.days)
|
||||
|
||||
it "processes each ownership period separately" do
|
||||
allow(updater).to receive(:split_for_trial).twice
|
||||
updater.perform
|
||||
|
||||
expect(updater).to have_received(:split_for_trial)
|
||||
.with(enterprise.versions.first.reify, start_of_july, start_of_july + 10.days, nil, nil)
|
||||
|
||||
expect(updater).to have_received(:split_for_trial)
|
||||
.with(enterprise, start_of_july + 10.days, start_of_july + 28.days, nil, nil)
|
||||
end
|
||||
end
|
||||
|
||||
context "when some other attribute has been changed within the current month" do
|
||||
before do
|
||||
Timecop.freeze(start_of_july + 10.days) do
|
||||
# NOTE: Sells is changed between when order1 and order2 are placed
|
||||
enterprise.update_attribute(:name, 'Some New Name')
|
||||
end
|
||||
end
|
||||
|
||||
travel_to(28.days)
|
||||
|
||||
it "does not create a version, and so does not split the period" do
|
||||
expect(enterprise.versions).to eq []
|
||||
allow(updater).to receive(:split_for_trial).once
|
||||
updater.perform
|
||||
expect(updater).to have_received(:split_for_trial)
|
||||
.with(enterprise, start_of_july, start_of_july + 28.days, nil, nil)
|
||||
end
|
||||
end
|
||||
|
||||
context "where sells or owner_id were altered during the previous month (ie. June)" do
|
||||
let!(:new_owner) { create(:user) }
|
||||
|
||||
before do
|
||||
Timecop.freeze(start_of_july - 20.days) do
|
||||
# NOTE: Sells is changed between when order1 and order2 are placed
|
||||
enterprise.update_attribute(:sells, 'own')
|
||||
end
|
||||
Timecop.freeze(start_of_july - 10.days) do
|
||||
# NOTE: Sells is changed between when order1 and order2 are placed
|
||||
enterprise.update_attribute(:owner, new_owner)
|
||||
end
|
||||
end
|
||||
|
||||
travel_to(28.days)
|
||||
|
||||
it "ignores those verions" do
|
||||
allow(updater).to receive(:split_for_trial).once
|
||||
updater.perform
|
||||
expect(updater).to have_received(:split_for_trial)
|
||||
.with(enterprise, start_of_july, start_of_july + 28.days, nil, nil)
|
||||
end
|
||||
end
|
||||
|
||||
context "where sells or owner_id were altered in the future" do
|
||||
let!(:new_owner) { create(:user) }
|
||||
|
||||
before do
|
||||
Timecop.freeze(start_of_july + 17.days) do
|
||||
enterprise.update_attribute(:sells, 'own')
|
||||
end
|
||||
Timecop.freeze(start_of_july + 35.days) do
|
||||
enterprise.update_attribute(:owner, new_owner)
|
||||
end
|
||||
end
|
||||
|
||||
travel_to(15.days)
|
||||
|
||||
it "ignores those verions" do
|
||||
allow(updater).to receive(:split_for_trial).once
|
||||
updater.perform
|
||||
expect(updater).to have_received(:split_for_trial)
|
||||
.with(enterprise, start_of_july, start_of_july + 15.days, nil, nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when an enterprise is created during the current month" do
|
||||
before do
|
||||
expect(updater).to receive(:clean_up_untouched_billable_periods_for).once
|
||||
enterprise.update_attribute(:created_at, start_of_july + 10.days)
|
||||
end
|
||||
|
||||
travel_to(28.days)
|
||||
|
||||
it "begins at the date the enterprise was created" do
|
||||
allow(updater).to receive(:split_for_trial).once
|
||||
updater.perform
|
||||
expect(updater).to have_received(:split_for_trial)
|
||||
.with(enterprise, start_of_july + 10.days, start_of_july + 28.days, nil, nil)
|
||||
end
|
||||
end
|
||||
|
||||
context "when an enterprise is created after the previous midnight" do
|
||||
before do
|
||||
expect(updater).to_not receive(:clean_up_untouched_billable_periods_for)
|
||||
enterprise.update_attribute(:created_at, start_of_july + 29.days)
|
||||
end
|
||||
|
||||
travel_to(28.days)
|
||||
|
||||
it "ignores the enterprise" do
|
||||
allow(updater).to receive(:split_for_trial)
|
||||
updater.perform
|
||||
expect(updater).to_not have_received(:split_for_trial)
|
||||
end
|
||||
end
|
||||
|
||||
pending "when an enterprise is deleted during the current month" do
|
||||
before do
|
||||
expect(updater).to receive(:clean_up_untouched_billable_periods_for).once
|
||||
enterprise.update_attribute(:deleted_at, start_of_july + 20.days)
|
||||
end
|
||||
|
||||
travel_to(28.days)
|
||||
|
||||
it "ends at the date the enterprise was deleted" do
|
||||
allow(updater).to receive(:split_for_trial)
|
||||
updater.perform
|
||||
expect(updater).to have_received(:split_for_trial)
|
||||
.with(enterprise, start_of_july, start_of_july + 20.days, nil, nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "split_for_trial" do
|
||||
let!(:enterprise) { double(:enterprise) }
|
||||
let(:begins_at) { start_of_july }
|
||||
let(:ends_at) { begins_at + 30.days }
|
||||
|
||||
context "when trial_start is nil" do
|
||||
let(:trial_start) { nil }
|
||||
let(:trial_expiry) { begins_at + 3.days }
|
||||
|
||||
before do
|
||||
allow(updater).to receive(:update_billable_period).once
|
||||
updater.split_for_trial(enterprise, begins_at, ends_at, trial_start, trial_expiry)
|
||||
end
|
||||
|
||||
it "calls update_billable_period once for the entire period" do
|
||||
expect(updater).to have_received(:update_billable_period)
|
||||
.with(enterprise, begins_at, ends_at, false)
|
||||
end
|
||||
end
|
||||
|
||||
context "when trial_expiry is nil" do
|
||||
let(:trial_start) { begins_at + 3.days }
|
||||
let(:trial_expiry) { nil }
|
||||
|
||||
before do
|
||||
allow(updater).to receive(:update_billable_period).once
|
||||
updater.split_for_trial(enterprise, begins_at, ends_at, trial_start, trial_expiry)
|
||||
end
|
||||
|
||||
it "calls update_billable_period once for the entire period" do
|
||||
expect(updater).to have_received(:update_billable_period)
|
||||
.with(enterprise, begins_at, ends_at, false)
|
||||
end
|
||||
end
|
||||
|
||||
context "when the trial begins before begins_at" do
|
||||
let(:trial_start) { begins_at - 10.days }
|
||||
|
||||
context "and the trial ends before begins_at" do
|
||||
let(:trial_expiry) { begins_at - 5.days }
|
||||
|
||||
before do
|
||||
allow(updater).to receive(:update_billable_period).once
|
||||
updater.split_for_trial(enterprise, begins_at, ends_at, trial_start, trial_expiry)
|
||||
end
|
||||
|
||||
it "calls update_billable_period once for the entire period" do
|
||||
expect(updater).to have_received(:update_billable_period)
|
||||
.with(enterprise, begins_at, ends_at, false)
|
||||
end
|
||||
end
|
||||
|
||||
context "and the trial ends after begins_at" do
|
||||
let(:trial_expiry) { begins_at + 5.days }
|
||||
|
||||
before do
|
||||
allow(updater).to receive(:update_billable_period).twice
|
||||
updater.split_for_trial(enterprise, begins_at, ends_at, trial_start, trial_expiry)
|
||||
end
|
||||
|
||||
it "calls update_billable_period once for the trial period" do
|
||||
expect(updater).to have_received(:update_billable_period)
|
||||
.with(enterprise, begins_at, trial_expiry, true)
|
||||
end
|
||||
|
||||
it "calls update_billable_period once for the non-trial period" do
|
||||
expect(updater).to have_received(:update_billable_period)
|
||||
.with(enterprise, trial_expiry, ends_at, false)
|
||||
end
|
||||
end
|
||||
|
||||
context "and the trial ends after ends_at" do
|
||||
let(:trial_expiry) { ends_at + 5.days }
|
||||
|
||||
before do
|
||||
allow(updater).to receive(:update_billable_period).once
|
||||
updater.split_for_trial(enterprise, begins_at, ends_at, trial_start, trial_expiry)
|
||||
end
|
||||
|
||||
it "calls update_billable_period once for the entire (trial) period" do
|
||||
expect(updater).to have_received(:update_billable_period)
|
||||
.with(enterprise, begins_at, ends_at, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when the trial begins after begins_at" do
|
||||
let(:trial_start) { begins_at + 5.days }
|
||||
|
||||
context "and the trial begins after ends_at" do
|
||||
let(:trial_start) { ends_at + 5.days }
|
||||
let(:trial_expiry) { ends_at + 10.days }
|
||||
|
||||
before do
|
||||
allow(updater).to receive(:update_billable_period).once
|
||||
updater.split_for_trial(enterprise, begins_at, ends_at, trial_start, trial_expiry)
|
||||
end
|
||||
|
||||
it "calls update_billable_period once for the entire period" do
|
||||
expect(updater).to have_received(:update_billable_period)
|
||||
.with(enterprise, begins_at, ends_at, false)
|
||||
end
|
||||
end
|
||||
|
||||
context "and the trial ends before ends_at" do
|
||||
let(:trial_expiry) { ends_at - 2.days }
|
||||
|
||||
before do
|
||||
allow(updater).to receive(:update_billable_period).exactly(3).times
|
||||
updater.split_for_trial(enterprise, begins_at, ends_at, trial_start, trial_expiry)
|
||||
end
|
||||
|
||||
it "calls update_billable_period once for the non-trial period before the trial" do
|
||||
expect(updater).to have_received(:update_billable_period)
|
||||
.with(enterprise, begins_at, trial_start, false)
|
||||
end
|
||||
|
||||
it "calls update_billable_period once for the trial period" do
|
||||
expect(updater).to have_received(:update_billable_period)
|
||||
.with(enterprise, trial_start, trial_expiry, true)
|
||||
end
|
||||
|
||||
it "calls update_billable_period once for the non-trial period after the trial" do
|
||||
expect(updater).to have_received(:update_billable_period)
|
||||
.with(enterprise, trial_expiry, ends_at, false)
|
||||
end
|
||||
end
|
||||
|
||||
context "and the trial ends after ends_at" do
|
||||
let(:trial_expiry) { ends_at + 5.days }
|
||||
|
||||
before do
|
||||
allow(updater).to receive(:update_billable_period).twice
|
||||
updater.split_for_trial(enterprise, begins_at, ends_at, trial_start, trial_expiry)
|
||||
end
|
||||
|
||||
it "calls update_billable_period once for the non-trial period" do
|
||||
expect(updater).to have_received(:update_billable_period)
|
||||
.with(enterprise, begins_at, trial_start, false)
|
||||
end
|
||||
|
||||
it "calls update_billable_period once for the trial period" do
|
||||
expect(updater).to have_received(:update_billable_period)
|
||||
.with(enterprise, trial_start, ends_at, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "update_billable_period" do
|
||||
let!(:enterprise) { create(:enterprise, sells: 'any') }
|
||||
|
||||
let!(:existing) { create(:billable_period, enterprise: enterprise, begins_at: start_of_july) }
|
||||
|
||||
before do
|
||||
allow(Spree::Order).to receive(:where) { [
|
||||
double(:order, total: 10),
|
||||
double(:order, total: 20),
|
||||
double(:order, total: 30)
|
||||
]
|
||||
}
|
||||
end
|
||||
|
||||
context "when the account invoice is already_complete" do
|
||||
before do
|
||||
allow(BillablePeriod).to receive(:where) { [existing] }
|
||||
allow(existing.account_invoice).to receive(:order) { double(:order, complete?: true ) }
|
||||
allow(AccountInvoice).to receive(:find_or_create_by_user_id_and_year_and_month) { existing.account_invoice }
|
||||
end
|
||||
|
||||
it "does not update the billing period, but changes updated_at by touching the billable period " do
|
||||
expect(existing).to_not receive(:update_attributes)
|
||||
expect(existing).to receive(:touch)
|
||||
expect(Bugsnag).to_not receive(:notify)
|
||||
expect{
|
||||
updater.update_billable_period(enterprise, start_of_july, start_of_july + 20.days, false)
|
||||
}.to_not change{ BillablePeriod.count }
|
||||
end
|
||||
end
|
||||
|
||||
context "when arguments match both 'begins_at' and 'enterprise_id' of an existing billable period" do
|
||||
it "updates the existing billable period" do
|
||||
expect{
|
||||
updater.update_billable_period(enterprise, start_of_july, start_of_july + 20.days, false)
|
||||
}.to_not change{ BillablePeriod.count }
|
||||
existing.reload
|
||||
expect(existing.owner_id).to eq enterprise.owner_id
|
||||
expect(existing.ends_at).to eq start_of_july + 20.days
|
||||
expect(existing.sells).to eq enterprise.sells
|
||||
expect(existing.trial).to eq false
|
||||
expect(existing.turnover).to eq 60
|
||||
end
|
||||
|
||||
context "when there is nothing to update" do
|
||||
before do
|
||||
Timecop.freeze(start_of_july + 3.days) {
|
||||
existing.update_attributes(
|
||||
begins_at: start_of_july,
|
||||
ends_at: start_of_july + 20.days,
|
||||
trial: false,
|
||||
sells: enterprise.sells,
|
||||
turnover: 60
|
||||
)
|
||||
}
|
||||
end
|
||||
|
||||
it "changes updated_at anyway by touching the billable period" do
|
||||
Timecop.freeze(start_of_july + 10.days) {
|
||||
expect{
|
||||
updater.update_billable_period(enterprise, start_of_july, start_of_july + 20.days, false)
|
||||
}.to change{ existing.reload.updated_at }
|
||||
.from(start_of_july + 3.days)
|
||||
.to(start_of_july + 10.days)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when 'begins_at' does not match an existing billable period" do
|
||||
before do
|
||||
expect{
|
||||
updater.update_billable_period(enterprise, start_of_july + 20.days, start_of_july + 30.days, false)
|
||||
}.to change{ BillablePeriod.count }.from(1).to(2)
|
||||
end
|
||||
|
||||
it "creates a new existing billable period" do
|
||||
billable_period = BillablePeriod.last
|
||||
expect(billable_period.owner_id).to eq enterprise.owner_id
|
||||
expect(billable_period.ends_at).to eq start_of_july + 30.days
|
||||
expect(billable_period.sells).to eq enterprise.sells
|
||||
expect(billable_period.trial).to eq false
|
||||
expect(billable_period.turnover).to eq 60
|
||||
end
|
||||
end
|
||||
|
||||
context "when 'enterprise_id' does not match an existing billable period" do
|
||||
let!(:new_enterprise) { create(:enterprise, sells: 'own') }
|
||||
|
||||
before do
|
||||
expect{
|
||||
updater.update_billable_period(new_enterprise, start_of_july, start_of_july + 20.days, false)
|
||||
}.to change{ BillablePeriod.count }.from(1).to(2)
|
||||
end
|
||||
|
||||
it "creates a new existing billable period" do
|
||||
billable_period = BillablePeriod.last
|
||||
expect(billable_period.owner_id).to eq new_enterprise.owner_id
|
||||
expect(billable_period.ends_at).to eq start_of_july + 20.days
|
||||
expect(billable_period.sells).to eq new_enterprise.sells
|
||||
expect(billable_period.trial).to eq false
|
||||
expect(billable_period.turnover).to eq 60
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "cleaning up untouched billable periods" do
|
||||
let(:job_start_time) { Time.zone.now }
|
||||
let(:enterprise) { create(:enterprise) }
|
||||
# Updated after start
|
||||
let!(:bp1) { create(:billable_period, enterprise: enterprise, updated_at: job_start_time + 2.seconds, begins_at: start_of_july, ends_at: start_of_july + 5.days ) }
|
||||
let!(:bp2) { create(:billable_period, enterprise: enterprise, updated_at: job_start_time + 2.seconds, begins_at: start_of_july + 5.days, ends_at: start_of_july + 10.days ) }
|
||||
# Updated before start
|
||||
let!(:bp3) { create(:billable_period, enterprise: enterprise, updated_at: job_start_time - 5.seconds, begins_at: start_of_july, ends_at: start_of_july + 10.days ) }
|
||||
# Updated before start but begins after end_date
|
||||
let!(:bp4) { create(:billable_period, enterprise: enterprise, updated_at: job_start_time - 5.seconds, begins_at: start_of_july + 10.days, ends_at: start_of_july + 15.days ) }
|
||||
# Updated before start but begins at end_date (ie. not before end_date, so should be ignored) EDGE CASE
|
||||
let!(:bp5) { create(:billable_period, enterprise: enterprise, updated_at: job_start_time - 5.seconds, begins_at: start_of_july + 8.days, ends_at: start_of_july + 10.days ) }
|
||||
# Updated before start but ends before start_date
|
||||
let!(:bp6) { create(:billable_period, enterprise: enterprise, updated_at: job_start_time - 5.seconds, begins_at: start_of_july - 10.days, ends_at: start_of_july - 5.days ) }
|
||||
# Updated before start but ends at start_date (ie. not after start_date, so should be ignored) EDGE CASE
|
||||
let!(:bp7) { create(:billable_period, enterprise: enterprise, updated_at: job_start_time - 5.seconds, begins_at: start_of_july - 5.days, ends_at: start_of_july ) }
|
||||
# Updated before start, but order is already complete, so should not be deleted
|
||||
let!(:bp8) { create(:billable_period, enterprise: enterprise, updated_at: job_start_time - 5.seconds, begins_at: start_of_july, ends_at: start_of_july + 10.days, account_invoice: create(:account_invoice, order: create(:order, state: 'complete', completed_at: 5.minutes.ago))) }
|
||||
|
||||
before do
|
||||
allow(Bugsnag).to receive(:notify)
|
||||
allow(updater).to receive(:start_date) { start_of_july }
|
||||
allow(updater).to receive(:end_date) { start_of_july + 8.days }
|
||||
updater.clean_up_untouched_billable_periods_for(enterprise, job_start_time)
|
||||
end
|
||||
|
||||
it "soft deletes untouched billable_periods" do
|
||||
expect(bp1.reload.deleted_at).to be_nil
|
||||
expect(bp2.reload.deleted_at).to be_nil
|
||||
expect(bp3.reload.deleted_at).to_not be_nil
|
||||
expect(bp4.reload.deleted_at).to be_nil
|
||||
expect(bp5.reload.deleted_at).to be_nil
|
||||
expect(bp6.reload.deleted_at).to be_nil
|
||||
expect(bp7.reload.deleted_at).to be_nil
|
||||
expect(bp8.reload.deleted_at).to be_nil
|
||||
end
|
||||
|
||||
it "notifies bugsnag" do
|
||||
expect(Bugsnag).to have_received(:notify).once
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "validation spec" do
|
||||
# Chose july to test with because June has 30 days and so is easy to calculate end date for shop trial
|
||||
let!(:year) { Time.zone.now.year }
|
||||
let!(:start_of_july) { Time.zone.local(year, 7) }
|
||||
|
||||
let!(:enterprise) { create(:supplier_enterprise, sells: 'any') }
|
||||
|
||||
let!(:original_owner) { enterprise.owner }
|
||||
|
||||
let!(:new_owner) { create(:user) }
|
||||
|
||||
let!(:account_invoice1) { create(:account_invoice, user: original_owner, year: year, month: 7)}
|
||||
let!(:account_invoice2) { create(:account_invoice, user: new_owner, year: year, month: 7)}
|
||||
|
||||
# This BP was updated before the current run and so should be marked for deletion at the end of the run
|
||||
let!(:obsolete_bp) { create(:billable_period, enterprise: enterprise, updated_at: start_of_july + 10.days, begins_at: start_of_july + 6.5.days, ends_at: start_of_july + 10.days ) }
|
||||
|
||||
# This one has an updated_at in the future (so that it doesn't get deleted)
|
||||
# It also has a begins_at date which matches a period that would otherwise be created,
|
||||
# and so it should be picked up and overwritten
|
||||
let!(:bp_to_overwrite) { create(:billable_period, enterprise: enterprise, updated_at: start_of_july + 21.days, begins_at: start_of_july + 10.days, ends_at: start_of_july + 15.days ) }
|
||||
|
||||
let!(:order1) { create(:order, completed_at: start_of_july + 1.days, distributor: enterprise) }
|
||||
let!(:order2) { create(:order, completed_at: start_of_july + 3.days, distributor: enterprise) }
|
||||
let!(:order3) { create(:order, completed_at: start_of_july + 5.days, distributor: enterprise) }
|
||||
let!(:order4) { create(:order, completed_at: start_of_july + 7.days, distributor: enterprise) }
|
||||
let!(:order5) { create(:order, completed_at: start_of_july + 9.days, distributor: enterprise) }
|
||||
let!(:order6) { create(:order, completed_at: start_of_july + 11.days, distributor: enterprise) }
|
||||
let!(:order7) { create(:order, completed_at: start_of_july + 13.days, distributor: enterprise) }
|
||||
let!(:order8) { create(:order, completed_at: start_of_july + 15.days, distributor: enterprise) }
|
||||
let!(:order9) { create(:order, completed_at: start_of_july + 17.days, distributor: enterprise) }
|
||||
let!(:order10) { create(:order, completed_at: start_of_july + 19.days, distributor: enterprise) }
|
||||
|
||||
before do
|
||||
order1.line_items = [ create(:line_item_with_shipment, price: 12.56, order: order1) ]
|
||||
order2.line_items = [ create(:line_item_with_shipment, price: 87.44, order: order2) ]
|
||||
order3.line_items = [ create(:line_item_with_shipment, price: 50.00, order: order3) ]
|
||||
order4.line_items = [ create(:line_item_with_shipment, price: 73.37, order: order4) ]
|
||||
order5.line_items = [ create(:line_item_with_shipment, price: 22.46, order: order5) ]
|
||||
order6.line_items = [ create(:line_item_with_shipment, price: 44.85, order: order6) ]
|
||||
order7.line_items = [ create(:line_item_with_shipment, price: 93.45, order: order7) ]
|
||||
order8.line_items = [ create(:line_item_with_shipment, price: 59.38, order: order8) ]
|
||||
order9.line_items = [ create(:line_item_with_shipment, price: 47.23, order: order9) ]
|
||||
order10.line_items = [ create(:line_item_with_shipment, price: 2.35, order: order10) ]
|
||||
[order1, order2, order3, order4, order5, order6, order7, order8, order9, order10].each(&:update!)
|
||||
|
||||
allow(Enterprise).to receive(:where) { double(:enterprises, select: [enterprise]) }
|
||||
end
|
||||
|
||||
context "super complex example", versioning: true do
|
||||
before do
|
||||
enterprise.update_attribute(:created_at, start_of_july + 2.days)
|
||||
|
||||
Timecop.freeze(start_of_july + 4.days) { enterprise.update_attribute(:sells, 'own') }
|
||||
|
||||
Timecop.freeze(start_of_july + 6.days) { enterprise.update_attribute(:owner, new_owner) }
|
||||
|
||||
enterprise.update_attribute(:shop_trial_start_date, start_of_july + 8.days)
|
||||
|
||||
Timecop.freeze(start_of_july + 10.days) { enterprise.update_attribute(:owner, original_owner) }
|
||||
|
||||
Timecop.freeze(start_of_july + 12.days) { enterprise.update_attribute(:sells, 'any') }
|
||||
|
||||
allow(enterprise).to receive(:shop_trial_expiry) { start_of_july + 14.days }
|
||||
|
||||
Timecop.freeze(start_of_july + 16.days) { enterprise.update_attribute(:sells, 'own') }
|
||||
|
||||
Timecop.freeze(start_of_july + 18.days) { enterprise.update_attribute(:owner, new_owner) }
|
||||
end
|
||||
|
||||
travel_to(20.days)
|
||||
|
||||
before do
|
||||
UpdateBillablePeriods.new.perform
|
||||
end
|
||||
|
||||
let(:billable_periods) { BillablePeriod.order(:updated_at) }
|
||||
|
||||
it "creates the correct billable periods and deleted obsolete ones" do
|
||||
expect(obsolete_bp.reload.deleted_at).to_not be_nil
|
||||
|
||||
bp_to_overwrite.reload
|
||||
|
||||
expect(bp_to_overwrite.sells).to eq 'own'
|
||||
expect(bp_to_overwrite.trial).to be true
|
||||
expect(bp_to_overwrite.owner).to eq original_owner
|
||||
expect(bp_to_overwrite.begins_at).to eq start_of_july + 10.days
|
||||
expect(bp_to_overwrite.ends_at).to eq start_of_july + 12.days
|
||||
expect(bp_to_overwrite.turnover).to eq order6.total
|
||||
expect(bp_to_overwrite.account_invoice).to eq account_invoice1
|
||||
|
||||
expect(billable_periods.count).to eq 9
|
||||
|
||||
expect(account_invoice1.billable_periods.sort).to eq billable_periods.sort.select{ |bp| bp.owner == original_owner }
|
||||
expect(account_invoice2.billable_periods.sort).to eq billable_periods.sort.select{ |bp| bp.owner == new_owner }
|
||||
|
||||
expect(billable_periods.map(&:begins_at)).to eq [
|
||||
start_of_july + 2.days,
|
||||
start_of_july + 4.days,
|
||||
start_of_july + 6.days,
|
||||
start_of_july + 8.days,
|
||||
start_of_july + 10.days,
|
||||
start_of_july + 12.days,
|
||||
start_of_july + 14.days,
|
||||
start_of_july + 16.days,
|
||||
start_of_july + 18.days
|
||||
]
|
||||
|
||||
expect(billable_periods.map(&:ends_at)).to eq [
|
||||
start_of_july + 4.days,
|
||||
start_of_july + 6.days,
|
||||
start_of_july + 8.days,
|
||||
start_of_july + 10.days,
|
||||
start_of_july + 12.days,
|
||||
start_of_july + 14.days,
|
||||
start_of_july + 16.days,
|
||||
start_of_july + 18.days,
|
||||
start_of_july + 20.days
|
||||
]
|
||||
|
||||
expect(billable_periods.map(&:owner)).to eq [
|
||||
original_owner,
|
||||
original_owner,
|
||||
new_owner,
|
||||
new_owner,
|
||||
original_owner,
|
||||
original_owner,
|
||||
original_owner,
|
||||
original_owner,
|
||||
new_owner
|
||||
]
|
||||
|
||||
expect(billable_periods.map(&:sells)).to eq [
|
||||
'any',
|
||||
'own',
|
||||
'own',
|
||||
'own',
|
||||
'own',
|
||||
'any',
|
||||
'any',
|
||||
'own',
|
||||
'own'
|
||||
]
|
||||
|
||||
expect(billable_periods.map(&:trial)).to eq [
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
]
|
||||
|
||||
expect(billable_periods.map(&:turnover)).to eq [
|
||||
order2.total,
|
||||
order3.total,
|
||||
order4.total,
|
||||
order5.total,
|
||||
order6.total,
|
||||
order7.total,
|
||||
order8.total,
|
||||
order9.total,
|
||||
order10.total
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -31,7 +31,6 @@ module OpenFoodNetwork
|
||||
allow(report).to receive(:shipping_summary_rows) { ['shipping'] }
|
||||
allow(report).to receive(:payment_summary_rows) { ['payment'] }
|
||||
allow(report).to receive(:admin_adjustment_summary_rows) { ['admin'] }
|
||||
allow(order).to receive(:account_invoice?) { false }
|
||||
end
|
||||
|
||||
it "displays produce summary rows when summary report" do
|
||||
@@ -46,22 +45,14 @@ module OpenFoodNetwork
|
||||
|
||||
it "displays fee summary rows when summary report" do
|
||||
allow(report).to receive(:detail?) { false }
|
||||
allow(order).to receive(:account_invoice?) { true }
|
||||
expect(summary_rows).to include 'fee'
|
||||
end
|
||||
|
||||
it "displays fee summary rows when this is not an account invoice" do
|
||||
it "displays fee summary rows when detail report" do
|
||||
allow(report).to receive(:detail?) { true }
|
||||
allow(order).to receive(:account_invoice?) { false }
|
||||
expect(summary_rows).to include 'fee'
|
||||
end
|
||||
|
||||
it "does not display fee summary rows when this is a detail report for an account invoice" do
|
||||
allow(report).to receive(:detail?) { true }
|
||||
allow(order).to receive(:account_invoice?) { true }
|
||||
expect(summary_rows).not_to include 'fee'
|
||||
end
|
||||
|
||||
it "always displays shipping summary rows" do
|
||||
expect(summary_rows).to include 'shipping'
|
||||
end
|
||||
@@ -76,24 +67,6 @@ module OpenFoodNetwork
|
||||
end
|
||||
end
|
||||
|
||||
describe "finding account invoice adjustments" do
|
||||
let(:report) { XeroInvoicesReport.new user, initial_invoice_number: '', invoice_date: '', due_date: '', account_code: '' }
|
||||
let!(:order) { create(:order) }
|
||||
let(:billable_period) { create(:billable_period) }
|
||||
let(:shipping_method) { create(:shipping_method) }
|
||||
let!(:adj_invoice) { create(:adjustment, adjustable: order, label: 'Account invoice item', source: billable_period) }
|
||||
let!(:adj_shipping) { create(:adjustment, adjustable: order, label: "Shipping", originator: shipping_method) }
|
||||
|
||||
it "returns BillablePeriod adjustments only" do
|
||||
expect(report.send(:account_invoice_adjustments, order)).to eq([adj_invoice])
|
||||
end
|
||||
|
||||
it "excludes adjustments where the source is missing" do
|
||||
billable_period.destroy
|
||||
expect(report.send(:account_invoice_adjustments, order)).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
describe "generating invoice numbers" do
|
||||
let(:order) { double(:order, number: 'R731032860') }
|
||||
|
||||
|
||||
@@ -1,558 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe BillablePeriod, type: :model do
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'ensure_correct_adjustment' do
|
||||
let!(:start_of_july) { Time.zone.now.beginning_of_year + 6.months }
|
||||
let!(:user) { create(:user) }
|
||||
let!(:invoice) { create(:order, user: user) }
|
||||
let!(:subject) { create(:billable_period, owner: user, begins_at: start_of_july, ends_at: start_of_july + 12.days) }
|
||||
|
||||
before do
|
||||
allow(subject).to receive(:bill) { 99 }
|
||||
allow(subject).to receive(:adjustment_label) { "Label for adjustment" }
|
||||
Spree::Config.set({ account_invoices_tax_rate: 0.1 })
|
||||
end
|
||||
|
||||
context "when no adjustment currently exists" do
|
||||
it "creates an adjustment on the given order" do
|
||||
expect(invoice.total_tax).to eq 0.0
|
||||
expect(subject.adjustment).to be nil
|
||||
subject.ensure_correct_adjustment_for(invoice)
|
||||
expect(subject.adjustment).to be_a Spree::Adjustment
|
||||
expect(invoice.total_tax).to eq 9.0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "calculating monthly bills for enterprises with no turnover" do
|
||||
let!(:subject) { create(:billable_period, turnover: 0) }
|
||||
|
||||
context "when no tax is charged" do
|
||||
before { Spree::Config.set(:account_invoices_tax_rate, 0) }
|
||||
|
||||
context "when minimum billable turnover is zero" do
|
||||
before { Spree::Config.set(:minimum_billable_turnover, 0) }
|
||||
|
||||
context "when a fixed cost is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 10) }
|
||||
it { expect(subject.bill).to eq 10 }
|
||||
end
|
||||
|
||||
context "when no fixed cost is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 0) }
|
||||
it { expect(subject.bill).to eq 0 }
|
||||
end
|
||||
end
|
||||
|
||||
context "when minimum billable turnover is > zero" do
|
||||
before { Spree::Config.set(:minimum_billable_turnover, 1) }
|
||||
|
||||
context "when a fixed cost is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 10) }
|
||||
it { expect(subject.bill).to eq 0 }
|
||||
end
|
||||
|
||||
context "when no fixed cost is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 0) }
|
||||
it { expect(subject.bill).to eq 0 }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when tax is charged" do
|
||||
before { Spree::Config.set(:account_invoices_tax_rate, 0.1) }
|
||||
|
||||
context "when minimum billable turnover is zero" do
|
||||
before { Spree::Config.set(:minimum_billable_turnover, 0) }
|
||||
|
||||
context "when a fixed cost is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 10) }
|
||||
it { expect(subject.bill).to eq 11 }
|
||||
end
|
||||
|
||||
context "when no fixed cost is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 0) }
|
||||
it { expect(subject.bill).to eq 0 }
|
||||
end
|
||||
end
|
||||
|
||||
context "when minimum billable turnover is > zero" do
|
||||
before { Spree::Config.set(:minimum_billable_turnover, 1) }
|
||||
|
||||
context "when a fixed cost is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 10) }
|
||||
it { expect(subject.bill).to eq 0 }
|
||||
end
|
||||
|
||||
context "when no fixed cost is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 0) }
|
||||
it { expect(subject.bill).to eq 0 }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "calculating monthly bills for enterprises" do
|
||||
let!(:subject) { create(:billable_period, turnover: 100) }
|
||||
|
||||
context "when no tax is charged" do
|
||||
before { Spree::Config.set(:account_invoices_tax_rate, 0) }
|
||||
|
||||
context "when no minimum billable turnover" do
|
||||
before { Spree::Config.set(:minimum_billable_turnover, 0) }
|
||||
|
||||
context "when a fixed cost is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 10) }
|
||||
|
||||
context "when a percentage of turnover is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0.5) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
context "at a level higher than the fixed charge plus the product of the rate and turnover" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 65) }
|
||||
it { expect(subject.bill).to eq 60 }
|
||||
end
|
||||
|
||||
context "at a level lower than the fixed charge plus the product of the rate and turnover" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 55) }
|
||||
it { expect(subject.bill).to eq 55 }
|
||||
end
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(subject.bill).to eq 60 }
|
||||
end
|
||||
end
|
||||
|
||||
context "when a percentage of turnover is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
context "at a level higher than the fixed charge" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 15) }
|
||||
it { expect(subject.bill).to eq 10 }
|
||||
end
|
||||
|
||||
context "at a level lower than the fixed charge" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 5) }
|
||||
it { expect(subject.bill).to eq 5 }
|
||||
end
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(subject.bill).to eq 10 }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when a fixed cost is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 0) }
|
||||
|
||||
context "when a percentage of turnover is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0.5) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
context "at a level higher than the product of the rate and turnover" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 55) }
|
||||
it { expect(subject.bill).to eq 50 }
|
||||
end
|
||||
|
||||
context "at a level lower than the product of the rate and turnover" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 45) }
|
||||
it { expect(subject.bill).to eq 45 }
|
||||
end
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(subject.bill).to eq 50 }
|
||||
end
|
||||
end
|
||||
|
||||
context "when a percentage of turnover is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(subject.bill).to eq 0 }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(subject.bill).to eq 0 }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when turnover is above minimum billable turnover" do
|
||||
before { Spree::Config.set(:minimum_billable_turnover, 99) }
|
||||
|
||||
context "when a fixed cost is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 10) }
|
||||
|
||||
context "when a percentage of turnover is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0.5) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
context "at a level higher than the fixed charge plus the product of the rate and turnover" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 65) }
|
||||
it { expect(subject.bill).to eq 60 }
|
||||
end
|
||||
|
||||
context "at a level lower than the fixed charge plus the product of the rate and turnover" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 55) }
|
||||
it { expect(subject.bill).to eq 55 }
|
||||
end
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(subject.bill).to eq 60 }
|
||||
end
|
||||
end
|
||||
|
||||
context "when a percentage of turnover is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
context "at a level higher than the fixed charge" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 15) }
|
||||
it { expect(subject.bill).to eq 10 }
|
||||
end
|
||||
|
||||
context "at a level lower than the fixed charge" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 5) }
|
||||
it { expect(subject.bill).to eq 5 }
|
||||
end
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(subject.bill).to eq 10 }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when a fixed cost is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 0) }
|
||||
|
||||
context "when a percentage of turnover is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0.5) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
context "at a level higher than the product of the rate and turnover" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 55) }
|
||||
it { expect(subject.bill).to eq 50 }
|
||||
end
|
||||
|
||||
context "at a level lower than the product of the rate and turnover" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 45) }
|
||||
it { expect(subject.bill).to eq 45 }
|
||||
end
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(subject.bill).to eq 50 }
|
||||
end
|
||||
end
|
||||
|
||||
context "when a percentage of turnover is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(subject.bill).to eq 0 }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(subject.bill).to eq 0 }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when turnover is below minimum billable turnover" do
|
||||
before { Spree::Config.set(:minimum_billable_turnover, 101) }
|
||||
|
||||
context "when a fixed cost is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 10) }
|
||||
|
||||
context "when a percentage of turnover is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0.5) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
context "at a level higher than the fixed charge plus the product of the rate and turnover" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 65) }
|
||||
it { expect(subject.bill).to eq 0 }
|
||||
end
|
||||
|
||||
context "at a level lower than the fixed charge plus the product of the rate and turnover" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 55) }
|
||||
it { expect(subject.bill).to eq 0 }
|
||||
end
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(subject.bill).to eq 0 }
|
||||
end
|
||||
end
|
||||
|
||||
context "when a percentage of turnover is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
context "at a level higher than the fixed charge" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 15) }
|
||||
it { expect(subject.bill).to eq 0 }
|
||||
end
|
||||
|
||||
context "at a level lower than the fixed charge" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 5) }
|
||||
it { expect(subject.bill).to eq 0 }
|
||||
end
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(subject.bill).to eq 0 }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when a fixed cost is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 0) }
|
||||
|
||||
context "when a percentage of turnover is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0.5) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
context "at a level higher than the product of the rate and turnover" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 55) }
|
||||
it { expect(subject.bill).to eq 0 }
|
||||
end
|
||||
|
||||
context "at a level lower than the product of the rate and turnover" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 45) }
|
||||
it { expect(subject.bill).to eq 0 }
|
||||
end
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(subject.bill).to eq 0 }
|
||||
end
|
||||
end
|
||||
|
||||
context "when a percentage of turnover is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(subject.bill).to eq 0 }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(subject.bill).to eq 0 }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when tax is charged" do
|
||||
before { Spree::Config.set(:account_invoices_tax_rate, 0.1) }
|
||||
|
||||
context "when turnover is above minimum billable turnover" do
|
||||
before { Spree::Config.set(:minimum_billable_turnover, 99) }
|
||||
|
||||
context "when a fixed cost is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 10) }
|
||||
|
||||
context "when a percentage of turnover is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0.5) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
context "at a level higher than the fixed charge plus the product of the rate and turnover" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 61) }
|
||||
it { expect(subject.bill).to eq 66 }
|
||||
end
|
||||
|
||||
context "at a level lower than the fixed charge plus the product of the rate and turnover" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 59) }
|
||||
it {
|
||||
expect(subject.bill.to_f).to eq 64.9
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(subject.bill).to eq 66 }
|
||||
end
|
||||
end
|
||||
|
||||
context "when a percentage of turnover is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
context "at a level higher than the fixed charge" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 11) }
|
||||
it { expect(subject.bill).to eq 11 }
|
||||
end
|
||||
|
||||
context "at a level lower than the fixed charge" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 9) }
|
||||
it { expect(subject.bill.to_f).to eq 9.9 }
|
||||
end
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(subject.bill).to eq 11 }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when a fixed cost is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 0) }
|
||||
|
||||
context "when a percentage of turnover is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0.5) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
context "at a level higher than the product of the rate and turnover" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 51) }
|
||||
it { expect(subject.bill).to eq 55 }
|
||||
end
|
||||
|
||||
context "at a level lower than the product of the rate and turnover" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 49) }
|
||||
it { expect(subject.bill.to_f).to eq 53.9 }
|
||||
end
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(subject.bill).to eq 55 }
|
||||
end
|
||||
end
|
||||
|
||||
context "when a percentage of turnover is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(subject.bill).to eq 0 }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(subject.bill).to eq 0 }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when turnover is below minimum billable turnover" do
|
||||
before { Spree::Config.set(:minimum_billable_turnover, 101) }
|
||||
|
||||
context "when a fixed cost is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 10) }
|
||||
|
||||
context "when a percentage of turnover is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0.5) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
context "at a level higher than the fixed charge plus the product of the rate and turnover" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 61) }
|
||||
it { expect(subject.bill).to eq 0 }
|
||||
end
|
||||
|
||||
context "at a level lower than the fixed charge plus the product of the rate and turnover" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 59) }
|
||||
it {
|
||||
expect(subject.bill.to_f).to eq 0
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(subject.bill).to eq 0 }
|
||||
end
|
||||
end
|
||||
|
||||
context "when a percentage of turnover is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
context "at a level higher than the fixed charge" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 11) }
|
||||
it { expect(subject.bill).to eq 0 }
|
||||
end
|
||||
|
||||
context "at a level lower than the fixed charge" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 9) }
|
||||
it { expect(subject.bill.to_f).to eq 0 }
|
||||
end
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(subject.bill).to eq 0 }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when a fixed cost is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_fixed, 0) }
|
||||
|
||||
context "when a percentage of turnover is included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0.5) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
context "at a level higher than the product of the rate and turnover" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 51) }
|
||||
it { expect(subject.bill).to eq 0 }
|
||||
end
|
||||
|
||||
context "at a level lower than the product of the rate and turnover" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 49) }
|
||||
it { expect(subject.bill.to_f).to eq 0 }
|
||||
end
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(subject.bill).to eq 0 }
|
||||
end
|
||||
end
|
||||
|
||||
context "when a percentage of turnover is not included" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_rate, 0) }
|
||||
|
||||
context "when the bill is capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 20) }
|
||||
it { expect(subject.bill).to eq 0 }
|
||||
end
|
||||
|
||||
context "when the bill is not capped" do
|
||||
before { Spree::Config.set(:account_invoices_monthly_cap, 0) }
|
||||
it { expect(subject.bill).to eq 0 }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -533,24 +533,6 @@ describe Spree::Order do
|
||||
end
|
||||
end
|
||||
|
||||
describe "checking if an order is an account invoice" do
|
||||
let(:accounts_distributor) { create(:distributor_enterprise) }
|
||||
let(:order_account_invoice) { create(:order, distributor: accounts_distributor) }
|
||||
let(:order_general) { create(:order, distributor: create(:distributor_enterprise)) }
|
||||
|
||||
before do
|
||||
Spree::Config.accounts_distributor_id = accounts_distributor.id
|
||||
end
|
||||
|
||||
it "returns true when the order is distributed by the accounts distributor" do
|
||||
order_account_invoice.should be_account_invoice
|
||||
end
|
||||
|
||||
it "returns false otherwise" do
|
||||
order_general.should_not be_account_invoice
|
||||
end
|
||||
end
|
||||
|
||||
describe "sending confirmation emails" do
|
||||
let!(:distributor) { create(:distributor_enterprise) }
|
||||
let!(:order) { create(:order, distributor: distributor) }
|
||||
@@ -561,14 +543,6 @@ describe Spree::Order do
|
||||
end.to enqueue_job ConfirmOrderJob
|
||||
end
|
||||
|
||||
it "does not send confirmation emails when distributor is the accounts_distributor" do
|
||||
Spree::Config.set({ accounts_distributor_id: distributor.id })
|
||||
|
||||
expect do
|
||||
order.deliver_order_confirmation_email
|
||||
end.to_not enqueue_job ConfirmOrderJob
|
||||
end
|
||||
|
||||
it "does not send confirmation emails when the order belongs to a subscription" do
|
||||
create(:proxy_order, order: order)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user