diff --git a/Gemfile b/Gemfile index 3ab52d3267..49319ab065 100644 --- a/Gemfile +++ b/Gemfile @@ -57,7 +57,6 @@ gem 'oauth2', '~> 1.4.7' # Used for Stripe Connect gem 'pagy', '~> 4.11' -gem 'andand' gem 'angularjs-rails', '1.8.0' gem 'aws-sdk', '1.67.0' gem 'bugsnag' diff --git a/Gemfile.lock b/Gemfile.lock index e1a321b2c5..cc06b102d2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -142,7 +142,6 @@ GEM addressable (2.8.0) public_suffix (>= 2.0.2, < 5.0) afm (0.2.2) - andand (1.3.3) angular-rails-templates (1.1.0) railties (>= 4.2, < 7) sprockets (>= 3.0, < 5) @@ -687,7 +686,6 @@ DEPENDENCIES activerecord-session_store acts-as-taggable-on (~> 8.1) acts_as_list (= 1.0.4) - andand angular-rails-templates (>= 0.3.0) angular_rails_csrf angularjs-file-upload-rails (~> 2.4.1) diff --git a/app/controllers/admin/bulk_line_items_controller.rb b/app/controllers/admin/bulk_line_items_controller.rb index 666a8aef2b..bf4b16fc70 100644 --- a/app/controllers/admin/bulk_line_items_controller.rb +++ b/app/controllers/admin/bulk_line_items_controller.rb @@ -6,7 +6,7 @@ module Admin # GET /admin/bulk_line_items.json # def index - order_params = params[:q].andand.delete :order + order_params = params[:q]&.delete :order orders = order_permissions.editable_orders.ransack(order_params).result @line_items = order_permissions. diff --git a/app/controllers/admin/enterprise_groups_controller.rb b/app/controllers/admin/enterprise_groups_controller.rb index 56b2468b5f..65c62ecb93 100644 --- a/app/controllers/admin/enterprise_groups_controller.rb +++ b/app/controllers/admin/enterprise_groups_controller.rb @@ -50,7 +50,7 @@ module Admin end def load_object_data - @owner_email = @enterprise_group.andand.owner.andand.email || "" + @owner_email = @enterprise_group&.owner&.email || "" end def collection diff --git a/app/controllers/admin/order_cycles_controller.rb b/app/controllers/admin/order_cycles_controller.rb index f8becca16c..2c0dc4ce71 100644 --- a/app/controllers/admin/order_cycles_controller.rb +++ b/app/controllers/admin/order_cycles_controller.rb @@ -73,7 +73,7 @@ module Admin end def bulk_update - if order_cycle_set.andand.save + if order_cycle_set&.save render_as_json @order_cycles, ams_prefix: 'index', current_user: spree_current_user, @@ -155,7 +155,7 @@ module Admin if json_request? # Split ransack params into all those that currently exist and new ones # to limit returned ocs to recent or undated - orders_close_at_gt = raw_params[:q].andand.delete(:orders_close_at_gt) || 31.days.ago + orders_close_at_gt = raw_params[:q]&.delete(:orders_close_at_gt) || 31.days.ago raw_params[:q] = { g: [raw_params.delete(:q) || {}, { m: 'or', orders_close_at_gt: orders_close_at_gt, @@ -217,7 +217,7 @@ module Admin (order_cycle_bulk_params[:collection_attributes] || []).keep_if do |_index, hash| order_cycle = OrderCycle.find(hash[:id]) - managed_ids.include?(order_cycle.andand.coordinator_id) + managed_ids.include?(order_cycle&.coordinator_id) end end diff --git a/app/controllers/admin/subscription_line_items_controller.rb b/app/controllers/admin/subscription_line_items_controller.rb index b16d486225..c0b3f650eb 100644 --- a/app/controllers/admin/subscription_line_items_controller.rb +++ b/app/controllers/admin/subscription_line_items_controller.rb @@ -28,7 +28,7 @@ module Admin def load_build_context @shop = Enterprise.managed_by(spree_current_user).find_by(id: params[:shop_id]) @schedule = permissions.editable_schedules.find_by(id: params[:schedule_id]) - @order_cycle = @schedule.andand.current_or_next_order_cycle + @order_cycle = @schedule&.current_or_next_order_cycle @variant = variant_if_eligible(subscription_line_item_params[:variant_id]) if @shop.present? end diff --git a/app/controllers/api/v0/order_cycles_controller.rb b/app/controllers/api/v0/order_cycles_controller.rb index 88241b23a4..110edc7920 100644 --- a/app/controllers/api/v0/order_cycles_controller.rb +++ b/app/controllers/api/v0/order_cycles_controller.rb @@ -94,7 +94,7 @@ module Api end def customer - @current_api_user.andand.customer_of(distributor) || nil + @current_api_user&.customer_of(distributor) || nil end def distributed_products diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 98ee863988..a3c4433397 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -152,7 +152,7 @@ class ApplicationController < ActionController::Base end def check_order_cycle_expiry - if current_order_cycle.andand.closed? + if current_order_cycle&.closed? current_order.empty! current_order.set_order_cycle! nil flash[:info] = I18n.t('order_cycle_closed') diff --git a/app/controllers/enterprises_controller.rb b/app/controllers/enterprises_controller.rb index 93fb69053f..f047b1745d 100644 --- a/app/controllers/enterprises_controller.rb +++ b/app/controllers/enterprises_controller.rb @@ -31,7 +31,7 @@ class EnterprisesController < BaseController respond_to do |format| format.json do - enterprises = @enterprise.andand.relatives.andand.activated + enterprises = @enterprise&.relatives&.activated render(json: enterprises, each_serializer: Api::EnterpriseSerializer, data: OpenFoodNetwork::EnterpriseInjectionData.new) diff --git a/app/controllers/spree/admin/base_controller.rb b/app/controllers/spree/admin/base_controller.rb index a29d6eeb1c..a51ac28730 100644 --- a/app/controllers/spree/admin/base_controller.rb +++ b/app/controllers/spree/admin/base_controller.rb @@ -106,7 +106,7 @@ module Spree raise "Suffix '#{ams_prefix}' not found in ams_prefix_whitelist for #{self.class.name}." end - prefix = ams_prefix.andand.classify || "" + prefix = ams_prefix&.classify || "" name = controller_name.classify "::Api::Admin::#{prefix}#{name}Serializer".constantize end diff --git a/app/controllers/spree/admin/payment_methods_controller.rb b/app/controllers/spree/admin/payment_methods_controller.rb index e4d1d8f3ed..9a882fc5c2 100644 --- a/app/controllers/spree/admin/payment_methods_controller.rb +++ b/app/controllers/spree/admin/payment_methods_controller.rb @@ -136,7 +136,7 @@ module Spree def restrict_stripe_account_change return unless @payment_method return unless stripe_payment_method? - return unless @payment_method.preferred_enterprise_id.andand > 0 + return unless @payment_method.preferred_enterprise_id&.positive? @stripe_account_holder = Enterprise.find(@payment_method.preferred_enterprise_id) return if spree_current_user.enterprises.include? @stripe_account_holder diff --git a/app/controllers/spree/admin/variants_controller.rb b/app/controllers/spree/admin/variants_controller.rb index fff1c5c139..7877f7e93b 100644 --- a/app/controllers/spree/admin/variants_controller.rb +++ b/app/controllers/spree/admin/variants_controller.rb @@ -82,7 +82,7 @@ module Spree def create_before option_values = params[:new_variant] - option_values.andand.each_value { |id| @object.option_values << OptionValue.find(id) } + option_values&.each_value { |id| @object.option_values << OptionValue.find(id) } @object.save end diff --git a/app/controllers/spree/orders_controller.rb b/app/controllers/spree/orders_controller.rb index 5990cf69c0..327c6cc3ac 100644 --- a/app/controllers/spree/orders_controller.rb +++ b/app/controllers/spree/orders_controller.rb @@ -171,16 +171,16 @@ module Spree # changes are allowed and the user has access. Return nil if not. def changeable_order_from_number order = Spree::Order.complete.find_by(number: params[:id]) - return nil unless order.andand.changes_allowed? && can?(:update, order) + return nil unless order&.changes_allowed? && can?(:update, order) order end def check_at_least_one_line_item - return unless order_to_update.andand.complete? + return unless order_to_update&.complete? items = params[:order][:line_items_attributes] - .andand.select{ |_k, attrs| attrs["quantity"].to_i > 0 } + &.select{ |_k, attrs| attrs["quantity"].to_i > 0 } if items.empty? flash[:error] = I18n.t(:orders_cannot_remove_the_final_item) diff --git a/app/helpers/enterprises_helper.rb b/app/helpers/enterprises_helper.rb index 397dff60f8..ba0de9938f 100644 --- a/app/helpers/enterprises_helper.rb +++ b/app/helpers/enterprises_helper.rb @@ -4,7 +4,7 @@ require 'open_food_network/available_payment_method_filter' module EnterprisesHelper def current_distributor - @current_distributor ||= current_order(false).andand.distributor + @current_distributor ||= current_order(false)&.distributor end def current_customer @@ -19,7 +19,7 @@ module EnterprisesHelper shipping_methods = current_distributor.shipping_methods.display_on_checkout.to_a applicator = OpenFoodNetwork::TagRuleApplicator.new(current_distributor, - "FilterShippingMethods", current_customer.andand.tag_list) + "FilterShippingMethods", current_customer&.tag_list) applicator.filter!(shipping_methods) shipping_methods.uniq @@ -34,7 +34,7 @@ module EnterprisesHelper filter.filter!(payment_methods) applicator = OpenFoodNetwork::TagRuleApplicator.new(current_distributor, - "FilterPaymentMethods", current_customer.andand.tag_list) + "FilterPaymentMethods", current_customer&.tag_list) applicator.filter!(payment_methods) payment_methods @@ -90,7 +90,7 @@ module EnterprisesHelper end def order_changes_allowed? - current_order.andand.distributor.andand.allow_order_changes? + current_order&.distributor&.allow_order_changes? end def show_bought_items? diff --git a/app/helpers/groups_helper.rb b/app/helpers/groups_helper.rb index 5f6b188abf..0c1d722c5a 100644 --- a/app/helpers/groups_helper.rb +++ b/app/helpers/groups_helper.rb @@ -17,6 +17,6 @@ module GroupsHelper end def strip_url(url) - url.andand.sub(%r{^https?://}i, '') + url&.sub(%r{^https?://}i, '') end end diff --git a/app/helpers/order_cycles_helper.rb b/app/helpers/order_cycles_helper.rb index 6341d230c6..741613e246 100644 --- a/app/helpers/order_cycles_helper.rb +++ b/app/helpers/order_cycles_helper.rb @@ -4,7 +4,7 @@ require 'open_food_network/permissions' module OrderCyclesHelper def current_order_cycle - @current_order_cycle ||= current_order(false).andand.order_cycle + @current_order_cycle ||= current_order(false)&.order_cycle end def permitted_enterprises_for(order_cycle) diff --git a/app/helpers/shared_helper.rb b/app/helpers/shared_helper.rb index 8d087e8aaa..b1f51ab004 100644 --- a/app/helpers/shared_helper.rb +++ b/app/helpers/shared_helper.rb @@ -12,11 +12,11 @@ module SharedHelper end def enterprise_user? - spree_current_user.andand.enterprises.andand.count.to_i > 0 + spree_current_user&.enterprises&.count.to_i > 0 end def admin_user? - spree_current_user.andand.has_spree_role? 'admin' + spree_current_user&.has_spree_role? 'admin' end def current_shop_products_path diff --git a/app/helpers/spree/orders_helper.rb b/app/helpers/spree/orders_helper.rb index a2f4837b8a..268d1876c1 100644 --- a/app/helpers/spree/orders_helper.rb +++ b/app/helpers/spree/orders_helper.rb @@ -12,7 +12,7 @@ module Spree end def cart_count - current_order.andand.line_items.andand.count || 0 + current_order&.line_items&.count || 0 end def changeable_orders diff --git a/app/helpers/spree/reports_helper.rb b/app/helpers/spree/reports_helper.rb index 38fcd2a35e..6e640ee27c 100644 --- a/app/helpers/spree/reports_helper.rb +++ b/app/helpers/spree/reports_helper.rb @@ -6,15 +6,15 @@ module Spree module ReportsHelper def report_order_cycle_options(order_cycles) order_cycles.map do |oc| - orders_open_at = oc.orders_open_at.andand.to_s(:short) || 'NA' - orders_close_at = oc.orders_close_at.andand.to_s(:short) || 'NA' + orders_open_at = oc.orders_open_at&.to_s(:short) || 'NA' + orders_close_at = oc.orders_close_at&.to_s(:short) || 'NA' ["#{oc.name}   (#{orders_open_at} - #{orders_close_at})".html_safe, oc.id] end end def report_payment_method_options(orders) orders.map do |order| - payment_method = order.payments.first.andand.payment_method + payment_method = order.payments.first&.payment_method next unless payment_method @@ -25,7 +25,7 @@ module Spree def report_shipping_method_options(orders) orders.map do |o| sm = o.shipping_method - [sm.andand.name, sm.andand.id] + [sm&.name, sm&.id] end.uniq end diff --git a/app/models/calculator/weight.rb b/app/models/calculator/weight.rb index 405598ebb7..b17bc9fca1 100644 --- a/app/models/calculator/weight.rb +++ b/app/models/calculator/weight.rb @@ -50,9 +50,9 @@ module Calculator def weight_per_variant(line_item) if variant_unit(line_item) == 'weight' # Convert unit_value to the preferred unit - convert_weight(line_item.variant.andand.unit_value) + convert_weight(line_item.variant&.unit_value) else - line_item.variant.andand.weight || 0 + line_item.variant&.weight || 0 end end @@ -79,7 +79,7 @@ module Calculator end def variant_unit(line_item) - line_item.variant.product.andand.variant_unit + line_item.variant.product&.variant_unit end def convert_weight(value) diff --git a/app/models/customer.rb b/app/models/customer.rb index 27a6d150c5..7f23c60589 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -35,7 +35,7 @@ class Customer < ApplicationRecord private def downcase_email - email.andand.downcase! + email&.downcase! end def empty_code diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index a2c0ffe60f..aef90188da 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -410,7 +410,7 @@ class Enterprise < ApplicationRecord end def strip_url(url) - url.andand.sub(%r{(https?://)?}, '') + url&.sub(%r{(https?://)?}, '') end def set_unused_address_fields diff --git a/app/models/order_cycle.rb b/app/models/order_cycle.rb index e46935e2a2..48f0afb416 100644 --- a/app/models/order_cycle.rb +++ b/app/models/order_cycle.rb @@ -231,15 +231,15 @@ class OrderCycle < ApplicationRecord end def receival_instructions_for(supplier) - exchange_for_supplier(supplier).andand.receival_instructions + exchange_for_supplier(supplier)&.receival_instructions end def pickup_time_for(distributor) - exchange_for_distributor(distributor).andand.pickup_time || distributor.next_collection_at + exchange_for_distributor(distributor)&.pickup_time || distributor.next_collection_at end def pickup_instructions_for(distributor) - exchange_for_distributor(distributor).andand.pickup_instructions + exchange_for_distributor(distributor)&.pickup_instructions end def exchanges_carrying(variant, distributor) diff --git a/app/models/product_import/entry_validator.rb b/app/models/product_import/entry_validator.rb index debc68fb64..9710cb37dc 100644 --- a/app/models/product_import/entry_validator.rb +++ b/app/models/product_import/entry_validator.rb @@ -424,7 +424,7 @@ module ProductImport end def import_into_inventory? - @import_settings[:settings].andand['import_into'] == 'inventories' + @import_settings.dig(:settings, 'import_into') == 'inventories' end def validate_inventory_item(entry, variant_override) diff --git a/app/models/product_import/product_importer.rb b/app/models/product_import/product_importer.rb index f5464f7e6b..cc8e94edf8 100644 --- a/app/models/product_import/product_importer.rb +++ b/app/models/product_import/product_importer.rb @@ -86,7 +86,7 @@ module ProductImport end def enterprise_products - @processor.andand.enterprise_products + @processor&.enterprise_products end def total_enterprise_products diff --git a/app/models/product_import/spreadsheet_data.rb b/app/models/product_import/spreadsheet_data.rb index 99a46fbfd0..6ec2efb086 100644 --- a/app/models/product_import/spreadsheet_data.rb +++ b/app/models/product_import/spreadsheet_data.rb @@ -37,7 +37,7 @@ module ProductImport private def import_into_inventory? - @import_settings[:settings].andand['import_into'] == 'inventories' + @import_settings.dig(:settings, 'import_into') == 'inventories' end def create_enterprises_index diff --git a/app/models/proxy_order.rb b/app/models/proxy_order.rb index 484c76faf8..b258208e4d 100644 --- a/app/models/proxy_order.rb +++ b/app/models/proxy_order.rb @@ -33,7 +33,7 @@ class ProxyOrder < ApplicationRecord end def cancel - return false unless order_cycle.orders_close_at.andand > Time.zone.now + return false unless order_cycle.orders_close_at&.>(Time.zone.now) transaction do update_column(:canceled_at, Time.zone.now) @@ -43,7 +43,7 @@ class ProxyOrder < ApplicationRecord end def resume - return false unless order_cycle.orders_close_at.andand > Time.zone.now + return false unless order_cycle.orders_close_at&.>(Time.zone.now) transaction do update_column(:canceled_at, nil) @@ -72,7 +72,7 @@ class ProxyOrder < ApplicationRecord end def cart? - order.andand.state == 'complete' && + order&.state == 'complete' && order_cycle.orders_close_at > Time.zone.now end diff --git a/app/models/spree/ability.rb b/app/models/spree/ability.rb index 94fa8ebc2f..c7e8de5aaf 100644 --- a/app/models/spree/ability.rb +++ b/app/models/spree/ability.rb @@ -197,7 +197,7 @@ module Spree end can [:admin, :index, :read, :update, :bulk_update, :bulk_reset], VariantOverride do |vo| - next false unless vo.hub.present? && vo.variant.andand.product.andand.supplier.present? + next false unless vo.hub.present? && vo.variant&.product&.supplier.present? hub_auth = OpenFoodNetwork::Permissions.new(user). variant_override_hubs. @@ -212,7 +212,7 @@ module Spree can [:admin, :create, :update], InventoryItem do |ii| next false unless ii.enterprise.present? && - ii.variant.andand.product.andand.supplier.present? + ii.variant&.product&.supplier.present? hub_auth = OpenFoodNetwork::Permissions.new(user). variant_override_hubs. @@ -267,7 +267,7 @@ module Spree # Enterprise User can access orders that they are a distributor for user.enterprises.include?(order.distributor) || # Enterprise User can access orders that are placed inside a OC they coordinate - order.order_cycle.andand.coordinated_by?(user) + order.order_cycle&.coordinated_by?(user) end can [:admin, :bulk_management, :managed], Spree::Order do user.admin? || user.enterprises.any?(&:is_distributor) @@ -280,7 +280,7 @@ module Spree order = item.order user.admin? || user.enterprises.include?(order.distributor) || - order.order_cycle.andand.coordinated_by?(user) + order.order_cycle&.coordinated_by?(user) end can [:admin, :index, :read, :create, :edit, :update, :fire], Spree::Payment @@ -293,7 +293,7 @@ module Spree else order = adjustment.order user.enterprises.include?(order.distributor) || - order.order_cycle.andand.coordinated_by?(user) + order.order_cycle&.coordinated_by?(user) end end diff --git a/app/models/spree/address.rb b/app/models/spree/address.rb index f4462e63d6..24ed00ef5c 100644 --- a/app/models/spree/address.rb +++ b/app/models/spree/address.rb @@ -90,7 +90,7 @@ module Spree end def full_address - render_address([address1, address2, city, zipcode, state.andand.name]) + render_address([address1, address2, city, zipcode, state&.name]) end def address_part1 @@ -98,7 +98,7 @@ module Spree end def address_part2 - render_address([city, zipcode, state.andand.name]) + render_address([city, zipcode, state&.name]) end private diff --git a/app/models/spree/gateway/stripe_connect.rb b/app/models/spree/gateway/stripe_connect.rb index fdd1d25a99..91090569ff 100644 --- a/app/models/spree/gateway/stripe_connect.rb +++ b/app/models/spree/gateway/stripe_connect.rb @@ -22,7 +22,7 @@ module Spree end def stripe_account_id - StripeAccount.find_by(enterprise_id: preferred_enterprise_id).andand.stripe_user_id + StripeAccount.find_by(enterprise_id: preferred_enterprise_id)&.stripe_user_id end # NOTE: the name of this method is determined by Spree::Payment::Processing @@ -100,7 +100,7 @@ module Spree end def ensure_enterprise_selected - return if preferred_enterprise_id.andand > 0 + return if preferred_enterprise_id&.positive? errors.add(:stripe_account_owner, I18n.t(:error_required)) end diff --git a/app/models/spree/gateway/stripe_sca.rb b/app/models/spree/gateway/stripe_sca.rb index 0d73858fc3..c623f4190d 100644 --- a/app/models/spree/gateway/stripe_sca.rb +++ b/app/models/spree/gateway/stripe_sca.rb @@ -33,7 +33,7 @@ module Spree end def stripe_account_id - StripeAccount.find_by(enterprise_id: preferred_enterprise_id).andand.stripe_user_id + StripeAccount.find_by(enterprise_id: preferred_enterprise_id)&.stripe_user_id end # NOTE: the name of this method is determined by Spree::Payment::Processing @@ -169,7 +169,7 @@ module Spree end def ensure_enterprise_selected - return if preferred_enterprise_id.andand.positive? + return if preferred_enterprise_id&.positive? errors.add(:stripe_account_owner, I18n.t(:error_required)) end diff --git a/app/models/spree/line_item.rb b/app/models/spree/line_item.rb index 886432e7c6..5c3412199b 100644 --- a/app/models/spree/line_item.rb +++ b/app/models/spree/line_item.rb @@ -172,7 +172,7 @@ module Spree end def tax_rates - product.tax_category.andand.tax_rates || [] + product.tax_category&.tax_rates || [] end def price_with_adjustments @@ -251,8 +251,8 @@ module Spree def calculate_final_weight_volume if final_weight_volume.present? && quantity_was > 0 self.final_weight_volume = final_weight_volume * quantity / quantity_was - elsif variant.andand.unit_value.present? - self.final_weight_volume = variant.andand.unit_value * quantity + elsif variant&.unit_value.present? + self.final_weight_volume = variant&.unit_value * quantity end end end diff --git a/app/models/spree/order.rb b/app/models/spree/order.rb index 29d4e78156..197ad99eea 100644 --- a/app/models/spree/order.rb +++ b/app/models/spree/order.rb @@ -192,7 +192,7 @@ module Spree end def changes_allowed? - complete? && distributor.andand.allow_order_changes? && order_cycle.andand.open? + complete? && distributor&.allow_order_changes? && order_cycle&.open? end # Is this a free order in which case the payment step should be skipped @@ -569,7 +569,7 @@ module Spree def set_distributor!(distributor) self.distributor = distributor - self.order_cycle = nil unless order_cycle.andand.has_distributor? distributor + self.order_cycle = nil unless order_cycle&.has_distributor? distributor save! end @@ -677,7 +677,7 @@ module Spree end def using_guest_checkout? - require_email && !user.andand.id + require_email && !user&.id end def registered_email? @@ -689,7 +689,7 @@ module Spree end def skip_payment_for_subscription? - subscription.present? && order_cycle.orders_close_at.andand > Time.zone.now + subscription.present? && order_cycle.orders_close_at&.>(Time.zone.now) end def require_customer? @@ -705,7 +705,7 @@ module Spree end def email_for_customer - (user.andand.email || email).andand.downcase + (user&.email || email)&.downcase end def associate_customer @@ -721,9 +721,9 @@ module Spree enterprise: distributor, email: email_for_customer, user: user, - name: bill_address.andand.full_name, - bill_address: bill_address.andand.clone, - ship_address: ship_address.andand.clone + name: bill_address&.full_name, + bill_address: bill_address&.clone, + ship_address: ship_address&.clone ) customer.save diff --git a/app/models/spree/payment.rb b/app/models/spree/payment.rb index 915ada2f2e..3212aab007 100644 --- a/app/models/spree/payment.rb +++ b/app/models/spree/payment.rb @@ -110,7 +110,7 @@ module Spree def build_source return if source_attributes.nil? - return unless payment_method.andand.payment_source_class + return unless payment_method&.payment_source_class self.source = payment_method.payment_source_class.new(source_attributes) source.payment_method_id = payment_method.id diff --git a/app/models/spree/stock/availability_validator.rb b/app/models/spree/stock/availability_validator.rb index 2679457d51..fc94efd1c6 100644 --- a/app/models/spree/stock/availability_validator.rb +++ b/app/models/spree/stock/availability_validator.rb @@ -28,7 +28,7 @@ module Spree def line_item_shipment(line_item) return line_item.target_shipment if line_item.target_shipment - return line_item.order.shipments.first if line_item.order.andand.shipments.any? + return line_item.order.shipments.first if line_item.order&.shipments.any? end # Overrides Spree v2.0.4 validate method version to: diff --git a/app/models/spree/variant.rb b/app/models/spree/variant.rb index 16012423ae..1b2b085de1 100644 --- a/app/models/spree/variant.rb +++ b/app/models/spree/variant.rb @@ -60,13 +60,13 @@ module Spree if: proc { Spree::Config[:require_master_price] } validates :unit_value, presence: true, if: ->(variant) { - %w(weight volume).include?(variant.product.andand.variant_unit) + %w(weight volume).include?(variant.product&.variant_unit) } validates :unit_value, numericality: { greater_than: 0 } validates :unit_description, presence: true, if: ->(variant) { - variant.product.andand.variant_unit.present? && variant.unit_value.nil? + variant.product&.variant_unit.present? && variant.unit_value.nil? } before_validation :set_cost_currency diff --git a/app/models/tag_rule/filter_order_cycles.rb b/app/models/tag_rule/filter_order_cycles.rb index c9048593f6..dd32314e3b 100644 --- a/app/models/tag_rule/filter_order_cycles.rb +++ b/app/models/tag_rule/filter_order_cycles.rb @@ -5,7 +5,7 @@ class TagRule::FilterOrderCycles < TagRule preference :exchange_tags, :string, default: "" def tags_match?(order_cycle) - exchange_tags = exchange_for(order_cycle).andand.tag_list || [] + exchange_tags = exchange_for(order_cycle)&.tag_list || [] preferred_tags = preferred_exchange_tags.split(",") ( exchange_tags & preferred_tags ).any? end diff --git a/app/models/tag_rule/filter_payment_methods.rb b/app/models/tag_rule/filter_payment_methods.rb index 6bcf2709ef..aee60a46fb 100644 --- a/app/models/tag_rule/filter_payment_methods.rb +++ b/app/models/tag_rule/filter_payment_methods.rb @@ -5,7 +5,7 @@ class TagRule::FilterPaymentMethods < TagRule preference :payment_method_tags, :string, default: "" def tags_match?(payment_method) - payment_method_tags = payment_method.andand.tag_list || [] + payment_method_tags = payment_method&.tag_list || [] preferred_tags = preferred_payment_method_tags.split(",") ( payment_method_tags & preferred_tags ).any? end diff --git a/app/models/tag_rule/filter_products.rb b/app/models/tag_rule/filter_products.rb index 20ff29bfc9..fb3908fefa 100644 --- a/app/models/tag_rule/filter_products.rb +++ b/app/models/tag_rule/filter_products.rb @@ -10,7 +10,7 @@ class TagRule end def tags_match?(variant) - variant_tags = variant.andand["tag_list"] || [] + variant_tags = variant&.[]("tag_list") || [] preferred_tags = preferred_variant_tags.split(",") (variant_tags & preferred_tags).any? end diff --git a/app/models/tag_rule/filter_shipping_methods.rb b/app/models/tag_rule/filter_shipping_methods.rb index 43b58a2052..e0cdd404c3 100644 --- a/app/models/tag_rule/filter_shipping_methods.rb +++ b/app/models/tag_rule/filter_shipping_methods.rb @@ -9,7 +9,7 @@ class TagRule::FilterShippingMethods < TagRule end def tags_match?(shipping_method) - shipping_method_tags = shipping_method.andand.tag_list || [] + shipping_method_tags = shipping_method&.tag_list || [] preferred_tags = preferred_shipping_method_tags.split(",") ( shipping_method_tags & preferred_tags ).any? end diff --git a/app/serializers/api/address_serializer.rb b/app/serializers/api/address_serializer.rb index acc986d5f7..6edbc6adc9 100644 --- a/app/serializers/api/address_serializer.rb +++ b/app/serializers/api/address_serializer.rb @@ -9,10 +9,10 @@ class Api::AddressSerializer < ActiveModel::Serializer :zipcode, :country_name def country_name - object.country.andand.name + object.country&.name end def state_name - object.state.andand.abbr + object.state&.abbr end end diff --git a/app/serializers/api/admin/basic_order_cycle_serializer.rb b/app/serializers/api/admin/basic_order_cycle_serializer.rb index 924b9bb2a5..86807fc2bc 100644 --- a/app/serializers/api/admin/basic_order_cycle_serializer.rb +++ b/app/serializers/api/admin/basic_order_cycle_serializer.rb @@ -15,11 +15,11 @@ module Api end def orders_open_at - object.orders_open_at.andand.strftime("%F %T %z") + object.orders_open_at&.strftime("%F %T %z") end def orders_close_at - object.orders_close_at.andand.strftime("%F %T %z") + object.orders_close_at&.strftime("%F %T %z") end end end diff --git a/app/serializers/api/admin/customer_serializer.rb b/app/serializers/api/admin/customer_serializer.rb index 99d8bad28c..30c067349b 100644 --- a/app/serializers/api/admin/customer_serializer.rb +++ b/app/serializers/api/admin/customer_serializer.rb @@ -10,7 +10,7 @@ module Api has_one :bill_address, serializer: Api::AddressSerializer def name - object.name.presence || object.bill_address.andand.full_name + object.name.presence || object.bill_address&.full_name end def tag_list @@ -19,7 +19,7 @@ module Api def tags customer_tag_list.map do |tag| - tag_rule_map = options[:tag_rule_mapping].andand[tag] + tag_rule_map = options.dig(:tag_rule_mapping, tag) tag_rule_map || { text: tag, rules: nil } end end @@ -35,7 +35,7 @@ module Api def customer_tag_list return object.tag_list unless options[:customer_tags] - options[:customer_tags].andand[object.id] || [] + options.dig(:customer_tags, object.id) || [] end end end diff --git a/app/serializers/api/admin/enterprise_fee_serializer.rb b/app/serializers/api/admin/enterprise_fee_serializer.rb index 55e3d00b7b..d149d6c3fb 100644 --- a/app/serializers/api/admin/enterprise_fee_serializer.rb +++ b/app/serializers/api/admin/enterprise_fee_serializer.rb @@ -7,11 +7,11 @@ module Api :calculator_type, :enterprise_name, :calculator_description, :calculator_settings def enterprise_name - object.enterprise.andand.name + object.enterprise&.name end def calculator_description - object.calculator.andand.description + object.calculator&.description end def calculator_settings diff --git a/app/serializers/api/admin/for_order_cycle/supplied_product_serializer.rb b/app/serializers/api/admin/for_order_cycle/supplied_product_serializer.rb index 883ae5909a..f5ed38c76a 100644 --- a/app/serializers/api/admin/for_order_cycle/supplied_product_serializer.rb +++ b/app/serializers/api/admin/for_order_cycle/supplied_product_serializer.rb @@ -7,7 +7,7 @@ module Api attributes :name, :supplier_name, :image_url, :master_id, :variants def supplier_name - object.supplier.andand.name + object.supplier&.name end def image_url diff --git a/app/serializers/api/admin/order_serializer.rb b/app/serializers/api/admin/order_serializer.rb index 7dea1a8963..4a35d593fa 100644 --- a/app/serializers/api/admin/order_serializer.rb +++ b/app/serializers/api/admin/order_serializer.rb @@ -17,7 +17,7 @@ module Api end def distributor_name - object.distributor.andand.name + object.distributor&.name end def display_outstanding_balance diff --git a/app/serializers/api/admin/proxy_order_serializer.rb b/app/serializers/api/admin/proxy_order_serializer.rb index 97c6f402a0..61a0940d40 100644 --- a/app/serializers/api/admin/proxy_order_serializer.rb +++ b/app/serializers/api/admin/proxy_order_serializer.rb @@ -13,7 +13,7 @@ module Api end def update_issues - options[:order_update_issues].andand[object.order_id] || [] + options[:order_update_issues]&.[](object.order_id) || [] end def completed_at diff --git a/app/serializers/api/admin/subscription_line_item_serializer.rb b/app/serializers/api/admin/subscription_line_item_serializer.rb index 452d95ad0c..999a7aeeb2 100644 --- a/app/serializers/api/admin/subscription_line_item_serializer.rb +++ b/app/serializers/api/admin/subscription_line_item_serializer.rb @@ -11,7 +11,7 @@ module Api end def price_estimate - object.price_estimate.andand.to_f || "?" + object.price_estimate&.to_f || "?" end def in_open_and_upcoming_order_cycles @@ -23,11 +23,11 @@ module Api private def option_or_assigned_shop - @options[:shop] || object.subscription.andand.shop + @options[:shop] || object.subscription&.shop end def option_or_assigned_schedule - @options[:schedule] || object.subscription.andand.schedule + @options[:schedule] || object.subscription&.schedule end end end diff --git a/app/serializers/api/admin/subscription_serializer.rb b/app/serializers/api/admin/subscription_serializer.rb index 4a2cb33db9..c75657ba99 100644 --- a/app/serializers/api/admin/subscription_serializer.rb +++ b/app/serializers/api/admin/subscription_serializer.rb @@ -15,31 +15,31 @@ module Api has_one :ship_address, serializer: Api::AddressSerializer def begins_at - object.begins_at.andand.strftime('%F') + object.begins_at&.strftime('%F') end def ends_at - object.ends_at.andand.strftime('%F') + object.ends_at&.strftime('%F') end def paused_at - object.paused_at.andand.strftime('%F') + object.paused_at&.strftime('%F') end def canceled_at - object.canceled_at.andand.strftime('%F') + object.canceled_at&.strftime('%F') end def customer_email - object.customer.andand.email + object.customer&.email end def customer_name - object.customer.andand.name + object.customer&.name end def schedule_name - object.schedule.andand.name + object.schedule&.name end def edit_path diff --git a/app/serializers/api/cached_enterprise_serializer.rb b/app/serializers/api/cached_enterprise_serializer.rb index f3e4700284..ede433065b 100644 --- a/app/serializers/api/cached_enterprise_serializer.rb +++ b/app/serializers/api/cached_enterprise_serializer.rb @@ -9,7 +9,7 @@ module Api cached def cache_key - enterprise.andand.cache_key + enterprise&.cache_key end attributes :name, :id, :description, :latitude, :longitude, @@ -119,7 +119,7 @@ module Api end def active - @active ||= data.active_distributor_ids.andand.include? enterprise.id + @active ||= data.active_distributor_ids&.include? enterprise.id end # Map svg icons. diff --git a/app/serializers/api/current_order_serializer.rb b/app/serializers/api/current_order_serializer.rb index 9860f64821..6c2a7c784f 100644 --- a/app/serializers/api/current_order_serializer.rb +++ b/app/serializers/api/current_order_serializer.rb @@ -11,11 +11,11 @@ class Api::CurrentOrderSerializer < ActiveModel::Serializer has_many :finalised_line_items, serializer: Api::LineItemSerializer def payment_method_id - object.payments.first.andand.payment_method_id + object.payments.first&.payment_method_id end def shipping_method_id - object.shipping_method.andand.id + object.shipping_method&.id end def display_total diff --git a/app/serializers/api/enterprise_shopfront_serializer.rb b/app/serializers/api/enterprise_shopfront_serializer.rb index 9707356799..29197dcb38 100644 --- a/app/serializers/api/enterprise_shopfront_serializer.rb +++ b/app/serializers/api/enterprise_shopfront_serializer.rb @@ -16,7 +16,7 @@ module Api has_many :distributed_properties, serializer: Api::PropertySerializer def orders_close_at - OrderCycle.with_distributor(enterprise).soonest_closing.first.andand.orders_close_at + OrderCycle.with_distributor(enterprise).soonest_closing.first&.orders_close_at end def active diff --git a/app/serializers/api/order_serializer.rb b/app/serializers/api/order_serializer.rb index b4a9460ce3..067d23b76d 100644 --- a/app/serializers/api/order_serializer.rb +++ b/app/serializers/api/order_serializer.rb @@ -34,7 +34,7 @@ module Api def changes_allowed_until return I18n.t(:not_allowed) unless object.changes_allowed? - I18n.l(object.order_cycle.andand.orders_close_at, format: "%b %d, %Y %H:%M") + I18n.l(object.order_cycle&.orders_close_at, format: "%b %d, %Y %H:%M") end def shipment_state diff --git a/app/serializers/api/uncached_enterprise_serializer.rb b/app/serializers/api/uncached_enterprise_serializer.rb index fb6b478a28..d92db46d28 100644 --- a/app/serializers/api/uncached_enterprise_serializer.rb +++ b/app/serializers/api/uncached_enterprise_serializer.rb @@ -11,7 +11,7 @@ module Api end def active - options[:data].active_distributor_ids.andand.include? object.id + options[:data].active_distributor_ids&.include? object.id end end end diff --git a/app/serializers/api/variant_serializer.rb b/app/serializers/api/variant_serializer.rb index 3c2ede89ae..524d940656 100644 --- a/app/serializers/api/variant_serializer.rb +++ b/app/serializers/api/variant_serializer.rb @@ -11,7 +11,7 @@ class Api::VariantSerializer < ActiveModel::Serializer delegate :price, to: :object def fees - options[:enterprise_fee_calculator].andand.indexed_fees_by_type_for(object) || + options[:enterprise_fee_calculator]&.indexed_fees_by_type_for(object) || object.fees_by_type_for(options[:current_distributor], options[:current_order_cycle]) end diff --git a/app/services/order_syncer.rb b/app/services/order_syncer.rb index f7b38a3e7b..a618f59452 100644 --- a/app/services/order_syncer.rb +++ b/app/services/order_syncer.rb @@ -13,7 +13,7 @@ class OrderSyncer def sync! orders_in_order_cycles_not_closed.all? do |order| - order.assign_attributes(customer_id: customer_id, email: customer.andand.email, + order.assign_attributes(customer_id: customer_id, email: customer&.email, distributor_id: shop_id) update_associations_for(order) line_item_syncer.sync!(order) @@ -59,7 +59,7 @@ class OrderSyncer payment = order.payments. with_state('checkout').where(payment_method_id: payment_method_id_was).last if payment - payment.andand.void_transaction! + payment&.void_transaction! order.payments.create(payment_method_id: payment_method_id, amount: order.reload.total) else unless order.payments.with_state('checkout').where(payment_method_id: payment_method_id).any? diff --git a/app/services/product_tag_rules_filterer.rb b/app/services/product_tag_rules_filterer.rb index 50b6168dc6..39a5c1e585 100644 --- a/app/services/product_tag_rules_filterer.rb +++ b/app/services/product_tag_rules_filterer.rb @@ -110,6 +110,6 @@ class ProductTagRulesFilterer end def customer_tag_list - customer.andand.tag_list || [] + customer&.tag_list || [] end end diff --git a/app/services/sets/model_set.rb b/app/services/sets/model_set.rb index 4cafcd924b..d5ff4e2ccb 100644 --- a/app/services/sets/model_set.rb +++ b/app/services/sets/model_set.rb @@ -28,7 +28,7 @@ module Sets end if found_element.nil? - @collection << @klass.new(attributes) unless @reject_if.andand.call(attributes) + @collection << @klass.new(attributes) unless @reject_if&.call(attributes) else process(found_element, attributes) end @@ -64,12 +64,12 @@ module Sets # Allows us to render @model_set.collection without deleted elements deleted = [] @collection = collection.to_a - collection.delete_if { |e| deleted << e if @delete_if.andand.call(e.attributes) } + collection.delete_if { |e| deleted << e if @delete_if&.call(e.attributes) } deleted end def collection_to_keep - collection.reject { |e| @delete_if.andand.call(e.attributes) } + collection.reject { |e| @delete_if&.call(e.attributes) } end def persisted? diff --git a/app/services/shop/order_cycles_list.rb b/app/services/shop/order_cycles_list.rb index 99bc34532a..1afed9acd8 100644 --- a/app/services/shop/order_cycles_list.rb +++ b/app/services/shop/order_cycles_list.rb @@ -22,7 +22,7 @@ module Shop def apply_tag_rules!(order_cycles) applicator = OpenFoodNetwork::TagRuleApplicator.new(@distributor, "FilterOrderCycles", - @customer.andand.tag_list) + @customer&.tag_list) applicator.filter!(order_cycles) order_cycles diff --git a/app/services/user_default_address_setter.rb b/app/services/user_default_address_setter.rb index 20a80afc3d..90a92d280a 100644 --- a/app/services/user_default_address_setter.rb +++ b/app/services/user_default_address_setter.rb @@ -27,13 +27,13 @@ class UserDefaultAddressSetter def set_bill_address_attributes(object, new_address) object.update( - bill_address_attributes: new_address.merge('id' => object.bill_address.andand.id) + bill_address_attributes: new_address.merge('id' => object.bill_address&.id) ) end def set_ship_address_attributes(object, new_address) object.update( - ship_address_attributes: new_address.merge('id' => object.ship_address.andand.id) + ship_address_attributes: new_address.merge('id' => object.ship_address&.id) ) end end diff --git a/app/views/admin/enterprise_groups/_form_users.html.haml b/app/views/admin/enterprise_groups/_form_users.html.haml index f96212064e..e501ce83be 100644 --- a/app/views/admin/enterprise_groups/_form_users.html.haml +++ b/app/views/admin/enterprise_groups/_form_users.html.haml @@ -10,6 +10,6 @@ - if spree_current_user.admin? = f.hidden_field :owner_id, class: "select2 fullwidth", - 'user-select' => "{id:'#{@enterprise_group.owner.andand.id}', email:'#{@enterprise_group.owner.andand.email}'}" + 'user-select' => "{id:'#{@enterprise_group.owner&.id}', email:'#{@enterprise_group.owner&.email}'}" - else - = @enterprise_group.owner.andand.email + = @enterprise_group.owner&.email diff --git a/app/views/admin/enterprise_groups/index.html.haml b/app/views/admin/enterprise_groups/index.html.haml index 6b63676910..f1aadfed21 100644 --- a/app/views/admin/enterprise_groups/index.html.haml +++ b/app/views/admin/enterprise_groups/index.html.haml @@ -24,7 +24,7 @@ %tr %td.name= enterprise_group.name - if spree_current_user.admin? - %td= enterprise_group.owner.andand.email || "" + %td= enterprise_group.owner&.email || "" %td= enterprise_group.on_front_page ? 'Y' : 'N' %td= enterprise_group.enterprises.map(&:name).join ', ' %td.actions diff --git a/app/views/admin/enterprises/_new_form.html.haml b/app/views/admin/enterprises/_new_form.html.haml index fb8ece2995..a0b99d6508 100644 --- a/app/views/admin/enterprises/_new_form.html.haml +++ b/app/views/admin/enterprises/_new_form.html.haml @@ -13,7 +13,7 @@ %div{'ofn-with-tip' => t('.owner_tip')} %a= t('admin.whats_this') .nine.columns.omega - - owner_email = @enterprise.andand.owner.andand.email || "" + - owner_email = @enterprise&.owner&.email || "" = f.hidden_field :owner_id, class: "select2 fullwidth", 'user-select' => 'Enterprise.owner' .row .three.columns.alpha diff --git a/app/views/admin/enterprises/form/_users.html.haml b/app/views/admin/enterprises/form/_users.html.haml index 89696d112b..9e75d65eca 100644 --- a/app/views/admin/enterprises/form/_users.html.haml +++ b/app/views/admin/enterprises/form/_users.html.haml @@ -1,5 +1,5 @@ -- owner_email = @enterprise.andand.owner.andand.email || "" -- full_permissions = (spree_current_user.admin? || spree_current_user == @enterprise.andand.owner) +- owner_email = @enterprise&.owner&.email || "" +- full_permissions = (spree_current_user.admin? || spree_current_user == @enterprise&.owner) .row .three.columns.alpha diff --git a/app/views/shopping_shared/_header.html.haml b/app/views/shopping_shared/_header.html.haml index caf3ccc6ad..643ba2912f 100644 --- a/app/views/shopping_shared/_header.html.haml +++ b/app/views/shopping_shared/_header.html.haml @@ -1,4 +1,4 @@ -- distributor = @order.andand.distributor || current_distributor +- distributor = @order&.distributor || current_distributor %navigation %distributor.details.row diff --git a/app/views/shopping_shared/_tabs.html.haml b/app/views/shopping_shared/_tabs.html.haml index 1790a46590..e1c95af47d 100644 --- a/app/views/shopping_shared/_tabs.html.haml +++ b/app/views/shopping_shared/_tabs.html.haml @@ -1,4 +1,4 @@ -- if (@order.andand.distributor || current_distributor) == current_distributor +- if (@order&.distributor || current_distributor) == current_distributor - shop_tabs.each do |tab| = render "shopping_shared/tabs/#{tab[:name]}" diff --git a/app/views/spree/admin/orders/_form/_distribution_fields.html.haml b/app/views/spree/admin/orders/_form/_distribution_fields.html.haml index c51fe5c006..52a1fb212c 100644 --- a/app/views/spree/admin/orders/_form/_distribution_fields.html.haml +++ b/app/views/spree/admin/orders/_form/_distribution_fields.html.haml @@ -5,13 +5,13 @@ .alpha.six.columns %p %b= t('.distributor') - = @order.distributor.andand.name || t(:none) - %input{type: "hidden", id: "order_distributor_id", value: @order.distributor.andand.id} + = @order.distributor&.name || t(:none) + %input{type: "hidden", id: "order_distributor_id", value: @order.distributor&.id} .omega.six.columns %p %b= t('.order_cycle') - = @order.order_cycle.andand.name || t(:none) - %input{type: "hidden", id: "order_order_cycle_id", value: @order.order_cycle.andand.id} + = @order.order_cycle&.name || t(:none) + %input{type: "hidden", id: "order_order_cycle_id", value: @order.order_cycle&.id} - else .alpha.six.columns .field diff --git a/app/views/spree/admin/orders/invoice.html.haml b/app/views/spree/admin/orders/invoice.html.haml index d4c20a02e1..73629cea18 100644 --- a/app/views/spree/admin/orders/invoice.html.haml +++ b/app/views/spree/admin/orders/invoice.html.haml @@ -15,7 +15,7 @@ %td{width: "10%" }   %td{ :align => "right" } - %h4= @order.order_cycle.andand.name + %h4= @order.order_cycle&.name %tr{ valign: "top" } %td{ align: "left", colspan: 3 } %strong= "#{t('.from')}: #{@order.distributor.name}" @@ -35,14 +35,14 @@ %br - if @order.bill_address = @order.bill_address.full_name - - if @order.andand.customer.andand.code.present? + - if @order&.customer&.code.present? %br = "#{t('.code')}: #{@order.customer.code}" %br - if @order.bill_address = @order.bill_address.full_address %br - - if @order.andand.customer.andand.email.present? + - if @order&.customer&.email.present? = "#{@order.customer.email}," - if @order.bill_address = "#{@order.bill_address.phone}" diff --git a/app/views/spree/admin/orders/invoice2.html.haml b/app/views/spree/admin/orders/invoice2.html.haml index 7344f7ead5..c38472e0d9 100644 --- a/app/views/spree/admin/orders/invoice2.html.haml +++ b/app/views/spree/admin/orders/invoice2.html.haml @@ -46,7 +46,7 @@ %br - if @order.bill_address %strong= @order.bill_address.full_name - - if @order.andand.customer.andand.code.present? + - if @order&.customer&.code.present? %br = "Code: #{@order.customer.code}" %br diff --git a/app/views/spree/admin/payment_methods/_stripe_connect.html.haml b/app/views/spree/admin/payment_methods/_stripe_connect.html.haml index 891aa71b48..bc3ba014b4 100644 --- a/app/views/spree/admin/payment_methods/_stripe_connect.html.haml +++ b/app/views/spree/admin/payment_methods/_stripe_connect.html.haml @@ -13,7 +13,7 @@ placeholder: t(".enterprise_select_placeholder"), data: 'shops', ng: { model: 'paymentMethod.preferred_enterprise_id' } } - else - %strong= Enterprise.find_by(id: @payment_method).andand.name + %strong= Enterprise.find_by(id: @payment_method)&.name #stripe-account-status{ ng: { show: "paymentMethod.preferred_enterprise_id" } } .alert-box.warning{ ng: { hide: "stripe_account.status" } } diff --git a/app/views/spree/admin/reports/users_and_enterprises.html.haml b/app/views/spree/admin/reports/users_and_enterprises.html.haml index 03f255820b..54adef9bb7 100644 --- a/app/views/spree/admin/reports/users_and_enterprises.html.haml +++ b/app/views/spree/admin/reports/users_and_enterprises.html.haml @@ -1,11 +1,11 @@ = form_tag spree.users_and_enterprises_admin_reports_url do |f| .row .alpha.two.columns= label_tag nil, t(:report_enterprises) - .omega.fourteen.columns= select_tag(:enterprise_id_in, options_from_collection_for_select(Enterprise.all, :id, :name, params[:enterprise_id_in].andand.split(",")), {class: "select2 fullwidth", multiple: true}) + .omega.fourteen.columns= select_tag(:enterprise_id_in, options_from_collection_for_select(Enterprise.all, :id, :name, params[:enterprise_id_in]&.split(",")), {class: "select2 fullwidth", multiple: true}) .row .alpha.two.columns= label_tag nil, t(:report_users) - .omega.fourteen.columns= select_tag(:user_id_in, options_from_collection_for_select(Spree::User.all, :id, :email, params[:user_id_in].andand.split(",")), {class: "select2 fullwidth", multiple: true}) + .omega.fourteen.columns= select_tag(:user_id_in, options_from_collection_for_select(Spree::User.all, :id, :email, params[:user_id_in]&.split(",")), {class: "select2 fullwidth", multiple: true}) -# Might need this later if we add different kinds of reports -# .row diff --git a/app/views/spree/order_mailer/_shipping.html.haml b/app/views/spree/order_mailer/_shipping.html.haml index a020f2774f..e0403f8b83 100644 --- a/app/views/spree/order_mailer/_shipping.html.haml +++ b/app/views/spree/order_mailer/_shipping.html.haml @@ -1,17 +1,17 @@ -- if @order.shipping_method.andand.delivery? +- if @order.shipping_method&.delivery? / Delivery details %p.callout %strong - - if @order.shipping_method.andand.name + - if @order.shipping_method&.name #{@order.shipping_method.name.html_safe} - else = t :email_shipping_delivery_details - - if @order.order_cycle.andand.pickup_time_for(@order.distributor) + - if @order.order_cycle&.pickup_time_for(@order.distributor) %h4 = t :email_shipping_delivery_time %strong #{@order.order_cycle.pickup_time_for(@order.distributor)} - - if @order.shipping_method.andand.description + - if @order.shipping_method&.description %p %em #{@order.shipping_method.description.html_safe} %br   @@ -32,22 +32,22 @@ / Collection details %p.callout %strong - - if @order.shipping_method.andand.name + - if @order.shipping_method&.name #{@order.shipping_method.name.html_safe} - else = t :email_shipping_collection_details - - if @order.order_cycle.andand.pickup_time_for(@order.distributor).present? + - if @order.order_cycle&.pickup_time_for(@order.distributor).present? %h4 = t :email_shipping_collection_time %strong #{@order.order_cycle.pickup_time_for(@order.distributor)} - - if @order.shipping_method.andand.description.present? + - if @order.shipping_method&.description.present? %p %em #{@order.shipping_method.description.html_safe} %br   - - if @order.order_cycle.andand.pickup_instructions_for(@order.distributor).present? + - if @order.order_cycle&.pickup_instructions_for(@order.distributor).present? %p %strong = t :email_shipping_collection_instructions diff --git a/app/views/spree/orders/_line_item.html.haml b/app/views/spree/orders/_line_item.html.haml index 7e5028d33c..52c8a07728 100644 --- a/app/views/spree/orders/_line_item.html.haml +++ b/app/views/spree/orders/_line_item.html.haml @@ -8,12 +8,12 @@ = render 'spree/shared/line_item_name', line_item: line_item - - if @insufficient_stock_lines.andand.include? line_item + - if @insufficient_stock_lines&.include? line_item %span.out-of-stock = variant.in_stock? ? t(".insufficient_stock", :on_hand => variant.on_hand) : t(".out_of_stock") %br/ - - if @unavailable_order_variants.andand.include? line_item.variant + - if @unavailable_order_variants&.include? line_item.variant %span.out-of-stock = t(".unavailable_item") %br/ diff --git a/app/views/spree/shared/_order_details.html.haml b/app/views/spree/shared/_order_details.html.haml index 3368215cc5..7e47f2d100 100644 --- a/app/views/spree/shared/_order_details.html.haml +++ b/app/views/spree/shared/_order_details.html.haml @@ -29,7 +29,7 @@ = order.bill_address.phone .columns.large-6 - - if order.shipping_method.andand.require_ship_address + - if order.shipping_method&.require_ship_address = render 'spree/shared/shipment_delivery_details', order: order - else = render 'spree/shared/shipment_pickup_details', order: order diff --git a/app/views/spree/shared/_shipment_delivery_details.html.haml b/app/views/spree/shared/_shipment_delivery_details.html.haml index 465146db49..3ae739a8aa 100644 --- a/app/views/spree/shared/_shipment_delivery_details.html.haml +++ b/app/views/spree/shared/_shipment_delivery_details.html.haml @@ -5,7 +5,7 @@ = t :order_delivery_time %strong #{order.order_cycle.pickup_time_for(order.distributor)} %p.text-small.text-skinny.pre-line - %em= order.shipping_method.description.andand.html_safe || "" + %em= order.shipping_method.description&.html_safe || "" .order-summary.text-small %strong = t :order_delivery_address diff --git a/app/views/spree/shared/_shipment_pickup_details.html.haml b/app/views/spree/shared/_shipment_pickup_details.html.haml index 1f9d7e1fe2..94b6dbe153 100644 --- a/app/views/spree/shared/_shipment_pickup_details.html.haml +++ b/app/views/spree/shared/_shipment_pickup_details.html.haml @@ -5,7 +5,7 @@ = t :order_pickup_time %strong #{order.order_cycle.pickup_time_for(order.distributor)} %p.text-small.text-skinny.pre-line - %em= order.shipping_method.description.andand.html_safe || "" + %em= order.shipping_method.description&.html_safe || "" - if order.order_cycle.pickup_instructions_for(order.distributor).present? %br diff --git a/config/routes.rb b/config/routes.rb index 69d1561185..b124475299 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -23,8 +23,8 @@ Openfoodnetwork::Application.routes.draw do resources :locales, only: [:show] # Redirects to global website - get "/connect", to: redirect("https://openfoodnetwork.org/#{ENV['DEFAULT_COUNTRY_CODE'].andand.downcase}/connect/") - get "/learn", to: redirect("https://openfoodnetwork.org/#{ENV['DEFAULT_COUNTRY_CODE'].andand.downcase}/learn/") + get "/connect", to: redirect("https://openfoodnetwork.org/#{ENV['DEFAULT_COUNTRY_CODE']&.downcase}/connect/") + get "/learn", to: redirect("https://openfoodnetwork.org/#{ENV['DEFAULT_COUNTRY_CODE']&.downcase}/learn/") get "/cart", :to => "spree/orders#edit", :as => :cart patch "/cart", :to => "spree/orders#update", :as => :update_cart diff --git a/engines/order_management/app/services/order_management/subscriptions/estimator.rb b/engines/order_management/app/services/order_management/subscriptions/estimator.rb index e358e031bf..0ae41a2b2d 100644 --- a/engines/order_management/app/services/order_management/subscriptions/estimator.rb +++ b/engines/order_management/app/services/order_management/subscriptions/estimator.rb @@ -42,7 +42,7 @@ module OrderManagement def fee_calculator return @fee_calculator unless @fee_calculator.nil? - next_oc = subscription.schedule.andand.current_or_next_order_cycle + next_oc = subscription.schedule&.current_or_next_order_cycle return nil unless shop && next_oc @fee_calculator = OpenFoodNetwork::EnterpriseFeeCalculator.new(shop, next_oc) diff --git a/engines/order_management/app/services/order_management/subscriptions/validator.rb b/engines/order_management/app/services/order_management/subscriptions/validator.rb index a8bc6b3086..6fdc0aa9ea 100644 --- a/engines/order_management/app/services/order_management/subscriptions/validator.rb +++ b/engines/order_management/app/services/order_management/subscriptions/validator.rb @@ -87,7 +87,7 @@ module OrderManagement return unless customer && payment_method return unless stripe_payment_method?(payment_method) return errors.add(:payment_method, :charges_not_allowed) unless customer.allow_charges - return if customer.user.andand.default_card.present? + return if customer.user&.default_card.present? errors.add(:payment_method, :no_default_card) end diff --git a/lib/open_food_network/address_finder.rb b/lib/open_food_network/address_finder.rb index 53b5290ff9..7af08a5a7c 100644 --- a/lib/open_food_network/address_finder.rb +++ b/lib/open_food_network/address_finder.rb @@ -50,27 +50,27 @@ module OpenFoodNetwork end def customer_preferred_bill_address - customer.andand.bill_address + customer&.bill_address end def customer_preferred_ship_address - customer.andand.ship_address + customer&.ship_address end def user_preferred_bill_address - user.andand.bill_address + user&.bill_address end def user_preferred_ship_address - user.andand.ship_address + user&.ship_address end def fallback_bill_address - last_used_bill_address.andand.clone || Spree::Address.default + last_used_bill_address&.clone || Spree::Address.default end def fallback_ship_address - last_used_ship_address.andand.clone || Spree::Address.default + last_used_ship_address&.clone || Spree::Address.default end def last_used_bill_address @@ -78,7 +78,7 @@ module OpenFoodNetwork Spree::Order.joins(:bill_address).order('id DESC') .complete.where(email: email) - .first.andand.bill_address + .first&.bill_address end def last_used_ship_address @@ -86,7 +86,7 @@ module OpenFoodNetwork Spree::Order.complete.joins(:ship_address, shipments: :shipping_methods).order('id DESC') .where(email: email, spree_shipping_methods: { require_ship_address: true }) - .first.andand.ship_address + .first&.ship_address end # Only allow search for address by email if a customer or user with the @@ -99,7 +99,7 @@ module OpenFoodNetwork end def email_matches_customer_or_user? - email == customer.andand.email || email == user.andand.email + email == customer&.email || email == user&.email end end end diff --git a/lib/open_food_network/customers_report.rb b/lib/open_food_network/customers_report.rb index 0b3dd440c5..60a7863dea 100644 --- a/lib/open_food_network/customers_report.rb +++ b/lib/open_food_network/customers_report.rb @@ -39,15 +39,15 @@ module OpenFoodNetwork order.billing_address.city] else ba = order.billing_address - da = order.distributor.andand.address + da = order.distributor&.address [ba.firstname, ba.lastname, [ba.address1, ba.address2, ba.city].join(" "), order.email, ba.phone, - order.distributor.andand.name, - [da.andand.address1, da.andand.address2, da.andand.city].join(" "), - order.shipping_method.andand.name] + order.distributor&.name, + [da&.address1, da&.address2, da&.city].join(" "), + order.shipping_method&.name] end end end diff --git a/lib/open_food_network/i18n_config.rb b/lib/open_food_network/i18n_config.rb index 6e39493c8a..92e48bd6d3 100644 --- a/lib/open_food_network/i18n_config.rb +++ b/lib/open_food_network/i18n_config.rb @@ -12,7 +12,7 @@ module OpenFoodNetwork # Locales that can be selected by users. def self.selectable_locales - ENV["AVAILABLE_LOCALES"].andand.split(/[\s,]+/) || [] + ENV["AVAILABLE_LOCALES"]&.split(/[\s,]+/) || [] end # All locales that can be accessed by the application, including fallbacks. diff --git a/lib/open_food_network/order_and_distributor_report.rb b/lib/open_food_network/order_and_distributor_report.rb index 310e8c537d..9764184b02 100644 --- a/lib/open_food_network/order_and_distributor_report.rb +++ b/lib/open_food_network/order_and_distributor_report.rb @@ -99,8 +99,8 @@ module OpenFoodNetwork line_item.max_quantity, line_item.price * line_item.quantity, line_item.distribution_fee, - order.payments.first.andand.payment_method.andand.name, - order.distributor.andand.name, + order.payments.first&.payment_method&.name, + order.distributor&.name, order.distributor.address.address1, order.distributor.address.city, order.distributor.address.zipcode, diff --git a/lib/open_food_network/order_cycle_management_report.rb b/lib/open_food_network/order_cycle_management_report.rb index f8753bec67..1fa9b7a462 100644 --- a/lib/open_food_network/order_cycle_management_report.rb +++ b/lib/open_food_network/order_cycle_management_report.rb @@ -87,15 +87,15 @@ module OpenFoodNetwork def payment_method_row(order) ba = order.billing_address - [ba.andand.firstname, - ba.andand.lastname, - order.distributor.andand.name, + [ba&.firstname, + ba&.lastname, + order.distributor&.name, customer_code(order.email), order.email, - ba.andand.phone, - order.shipping_method.andand.name, - order.payments.first.andand.payment_method.andand.name, - order.payments.first.andand.amount, + ba&.phone, + order.shipping_method&.name, + order.payments.first&.payment_method&.name, + order.payments.first&.amount, balance(order)] end @@ -103,14 +103,14 @@ module OpenFoodNetwork sa = order.shipping_address [sa.firstname, sa.lastname, - order.distributor.andand.name, + order.distributor&.name, customer_code(order.email), "#{sa.address1} #{sa.address2} #{sa.city}", sa.zipcode, sa.phone, - order.shipping_method.andand.name, - order.payments.first.andand.payment_method.andand.name, - order.payments.first.andand.amount, + order.shipping_method&.name, + order.payments.first&.payment_method&.name, + order.payments.first&.amount, balance(order), has_temperature_controlled_items?(order), order.special_instructions] @@ -142,7 +142,7 @@ module OpenFoodNetwork def has_temperature_controlled_items?(order) order.line_items.any? { |line_item| - line_item.product.shipping_category.andand.temperature_controlled + line_item.product.shipping_category&.temperature_controlled } end diff --git a/lib/open_food_network/order_cycle_permissions.rb b/lib/open_food_network/order_cycle_permissions.rb index a3423c8c65..a6e0024ed4 100644 --- a/lib/open_food_network/order_cycle_permissions.rb +++ b/lib/open_food_network/order_cycle_permissions.rb @@ -9,7 +9,7 @@ module OpenFoodNetwork def initialize(user, order_cycle) super(user) @order_cycle = order_cycle - @coordinator = order_cycle.andand.coordinator + @coordinator = order_cycle&.coordinator end # List of any enterprises whose exchanges I should be able to see in order_cycle @@ -242,7 +242,7 @@ module OpenFoodNetwork end def active_outgoing_variants(hub) - @active_outgoing_variants ||= @order_cycle.exchanges.outgoing.where(receiver_id: hub).first.andand.variants || [] + @active_outgoing_variants ||= @order_cycle.exchanges.outgoing.where(receiver_id: hub).first&.variants || [] end def user_manages_coordinator_or(enterprise) diff --git a/lib/open_food_network/orders_and_fulfillments_report/customer_totals_report.rb b/lib/open_food_network/orders_and_fulfillments_report/customer_totals_report.rb index ee5c4f4007..256c21c27d 100644 --- a/lib/open_food_network/orders_and_fulfillments_report/customer_totals_report.rb +++ b/lib/open_food_network/orders_and_fulfillments_report/customer_totals_report.rb @@ -86,9 +86,9 @@ module OpenFoodNetwork proc { |line_items| line_items.first.order.special_instructions }, proc { |_line_items| "" }, - proc { |line_items| line_items.first.order.order_cycle.andand.name }, + proc { |line_items| line_items.first.order.order_cycle&.name }, proc { |line_items| - line_items.first.order.payments.first.andand.payment_method.andand.name + line_items.first.order.payments.first&.payment_method&.name }, proc { |_line_items| "" }, proc { |_line_items| "" }, @@ -123,7 +123,7 @@ module OpenFoodNetwork # rubocop:disable Metrics/MethodLength # rubocop:disable Metrics/PerceivedComplexity def columns - rsa = proc { |line_items| shipping_method(line_items).andand.delivery? } + rsa = proc { |line_items| shipping_method(line_items)&.delivery? } [ proc { |line_items| line_items.first.order.distributor.name }, proc { |line_items| @@ -147,23 +147,23 @@ module OpenFoodNetwork line_items.all? { |li| li.order.paid? } ? I18n.t(:yes) : I18n.t(:no) }, - proc { |line_items| shipping_method(line_items).andand.name }, + proc { |line_items| shipping_method(line_items)&.name }, proc { |line_items| rsa.call(line_items) ? I18n.t(:yes) : I18n.t(:no) }, proc { |line_items| - line_items.first.order.ship_address.andand.address1 if rsa.call(line_items) + line_items.first.order.ship_address&.address1 if rsa.call(line_items) }, proc { |line_items| - line_items.first.order.ship_address.andand.address2 if rsa.call(line_items) + line_items.first.order.ship_address&.address2 if rsa.call(line_items) }, proc { |line_items| - line_items.first.order.ship_address.andand.city if rsa.call(line_items) + line_items.first.order.ship_address&.city if rsa.call(line_items) }, proc { |line_items| - line_items.first.order.ship_address.andand.zipcode if rsa.call(line_items) + line_items.first.order.ship_address&.zipcode if rsa.call(line_items) }, proc { |line_items| - line_items.first.order.ship_address.andand.state if rsa.call(line_items) + line_items.first.order.ship_address&.state if rsa.call(line_items) }, proc { |_line_items| "" }, @@ -173,27 +173,27 @@ module OpenFoodNetwork line_item.variant.sku end, - proc { |line_items| line_items.first.order.order_cycle.andand.name }, + proc { |line_items| line_items.first.order.order_cycle&.name }, proc { |line_items| payment = line_items.first.order.payments.first - payment.andand.payment_method.andand.name + payment&.payment_method&.name }, proc { |line_items| distributor = line_items.first.order.distributor user = line_items.first.order.user - user.andand.customer_of(distributor).andand.code + user&.customer_of(distributor)&.code }, proc { |line_items| distributor = line_items.first.order.distributor user = line_items.first.order.user - user.andand.customer_of(distributor).andand.tags.andand.join(', ') + user&.customer_of(distributor)&.tags&.join(', ') }, - proc { |line_items| line_items.first.order.bill_address.andand.address1 }, - proc { |line_items| line_items.first.order.bill_address.andand.address2 }, - proc { |line_items| line_items.first.order.bill_address.andand.city }, - proc { |line_items| line_items.first.order.bill_address.andand.zipcode }, - proc { |line_items| line_items.first.order.bill_address.andand.state }, + proc { |line_items| line_items.first.order.bill_address&.address1 }, + proc { |line_items| line_items.first.order.bill_address&.address2 }, + proc { |line_items| line_items.first.order.bill_address&.city }, + proc { |line_items| line_items.first.order.bill_address&.zipcode }, + proc { |line_items| line_items.first.order.bill_address&.state }, proc { |line_items| line_items.first.order.number }, proc { |line_items| line_items.first.order.completed_at.strftime("%F %T") }, ] @@ -212,8 +212,7 @@ module OpenFoodNetwork private def shipping_method(line_items) - shipping_rates = line_items.first.order.shipments.first. - andand.shipping_rates + shipping_rates = line_items.first.order.shipments.first&.shipping_rates return unless shipping_rates diff --git a/lib/open_food_network/packing_report.rb b/lib/open_food_network/packing_report.rb index ab60c449a5..663eae4385 100644 --- a/lib/open_food_network/packing_report.rb +++ b/lib/open_food_network/packing_report.rb @@ -137,7 +137,7 @@ module OpenFoodNetwork end def is_temperature_controlled?(line_item) - if line_item.product.shipping_category.andand.temperature_controlled + if line_item.product.shipping_category&.temperature_controlled "Yes" else "No" diff --git a/lib/open_food_network/referer_parser.rb b/lib/open_food_network/referer_parser.rb index 5fa3ea5670..36c68c7c47 100644 --- a/lib/open_food_network/referer_parser.rb +++ b/lib/open_food_network/referer_parser.rb @@ -3,7 +3,7 @@ module OpenFoodNetwork class RefererParser def self.path(referer) - parse_uri(referer).andand.path if referer + parse_uri(referer)&.path if referer end def self.parse_uri(string) diff --git a/lib/open_food_network/sales_tax_report.rb b/lib/open_food_network/sales_tax_report.rb index e117b0924c..f5f1adab03 100644 --- a/lib/open_food_network/sales_tax_report.rb +++ b/lib/open_food_network/sales_tax_report.rb @@ -62,7 +62,7 @@ module OpenFoodNetwork [order.number, order.completed_at.strftime("%F %T"), totals[:items], totals[:items_total], totals[:taxable_total], totals[:sales_tax], shipping_cost, order.shipping_tax, order.enterprise_fee_tax, order.total_tax, - order.bill_address.full_name, order.distributor.andand.name] + order.bill_address.full_name, order.distributor&.name] end end end diff --git a/lib/open_food_network/scope_variant_to_hub.rb b/lib/open_food_network/scope_variant_to_hub.rb index 568121a342..17c8517f72 100644 --- a/lib/open_food_network/scope_variant_to_hub.rb +++ b/lib/open_food_network/scope_variant_to_hub.rb @@ -15,7 +15,7 @@ module OpenFoodNetwork module ScopeVariantToHub def price - @variant_override.andand.price || super + @variant_override&.price || super end def price_in(currency) @@ -46,9 +46,9 @@ module OpenFoodNetwork # If it is a variant override with on_demand: # - don't change stock or call super (super would change the variant's stock) def move(quantity, originator = nil) - return if @variant_override.andand.on_demand + return if @variant_override&.on_demand - if @variant_override.andand.stock_overridden? + if @variant_override&.stock_overridden? @variant_override.move_stock! quantity else super @@ -56,11 +56,11 @@ module OpenFoodNetwork end def sku - @variant_override.andand.sku || super + @variant_override&.sku || super end def tag_list - @variant_override.andand.tag_list || [] + @variant_override&.tag_list || [] end end end diff --git a/lib/open_food_network/xero_invoices_report.rb b/lib/open_food_network/xero_invoices_report.rb index 1a6e2b187c..efbb43bb97 100644 --- a/lib/open_food_network/xero_invoices_report.rb +++ b/lib/open_food_network/xero_invoices_report.rb @@ -147,16 +147,16 @@ module OpenFoodNetwork return nil if amount == 0 # rubocop:enable Style/NumericPredicate - [order.bill_address.andand.full_name, + [order.bill_address&.full_name, order.email, - order.bill_address.andand.address1, - order.bill_address.andand.address2, + order.bill_address&.address1, + order.bill_address&.address2, '', '', - order.bill_address.andand.city, - order.bill_address.andand.state, - order.bill_address.andand.zipcode, - order.bill_address.andand.country.andand.name, + order.bill_address&.city, + order.bill_address&.state, + order.bill_address&.zipcode, + order.bill_address&.country&.name, invoice_number, order.number, opts[:invoice_date], diff --git a/lib/spree/localized_number.rb b/lib/spree/localized_number.rb index c0a2226671..88e8373663 100644 --- a/lib/spree/localized_number.rb +++ b/lib/spree/localized_number.rb @@ -36,7 +36,7 @@ module Spree define_method(:validate_localizable_number) do return unless Spree::Config.enable_localized_number? - @invalid_localized_number.andand.each do |error_attribute| + @invalid_localized_number&.each do |error_attribute| errors.add(error_attribute, I18n.t('spree.localized_number.invalid_format')) end end diff --git a/lib/tasks/enterprises.rake b/lib/tasks/enterprises.rake index c062f0d46d..7ce6fbca21 100644 --- a/lib/tasks/enterprises.rake +++ b/lib/tasks/enterprises.rake @@ -36,7 +36,7 @@ namespace :ofn do def enterprise_row(enterprise) [enterprise.name, enterprise.description, enterprise.long_description, - enterprise.is_primary_producer, enterprise.is_distributor, enterprise.contact_name, enterprise.phone, enterprise.email, enterprise.website, enterprise.twitter, enterprise.abn, enterprise.acn, enterprise.pickup_times, enterprise.next_collection_at, enterprise.distributor_info, enterprise.visible, enterprise.facebook, enterprise.instagram, enterprise.linkedin, enterprise.address.address1, enterprise.address.address2, enterprise.address.city, enterprise.address.zipcode, enterprise.address.state_name, enterprise.address.country.andand.name] + enterprise.is_primary_producer, enterprise.is_distributor, enterprise.contact_name, enterprise.phone, enterprise.email, enterprise.website, enterprise.twitter, enterprise.abn, enterprise.acn, enterprise.pickup_times, enterprise.next_collection_at, enterprise.distributor_info, enterprise.visible, enterprise.facebook, enterprise.instagram, enterprise.linkedin, enterprise.address.address1, enterprise.address.address2, enterprise.address.city, enterprise.address.zipcode, enterprise.address.state_name, enterprise.address.country&.name] end end end diff --git a/lib/tasks/missing_payments.rake b/lib/tasks/missing_payments.rake index 67a13e12cc..c822b62ee4 100644 --- a/lib/tasks/missing_payments.rake +++ b/lib/tasks/missing_payments.rake @@ -12,7 +12,7 @@ namespace :ofn do desc 'Find payments that got lost' task :missing_payments, [:days] => :environment do |_task_, args| - days = args[:days].andand.to_i || 7 + days = args[:days]&.to_i || 7 payments_sequence = Spree::Payment.where("created_at > ?", days.days.ago).order(:id).pluck(:id) missing_payment_ids = payments_range(payments_sequence) - payments_sequence puts "Gaps in the payments sequence: #{missing_payment_ids.count}" diff --git a/spec/controllers/spree/orders_controller_spec.rb b/spec/controllers/spree/orders_controller_spec.rb index 7776d02903..1f8ab6b2ef 100644 --- a/spec/controllers/spree/orders_controller_spec.rb +++ b/spec/controllers/spree/orders_controller_spec.rb @@ -601,6 +601,6 @@ describe Spree::OrdersController, type: :controller do private def num_items_in_cart - Spree::Order.last.andand.line_items.andand.count || 0 + Spree::Order.last&.line_items&.count || 0 end end