mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-07 03:01:33 +00:00
1
Gemfile
1
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'
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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?
|
||||
|
||||
@@ -17,6 +17,6 @@ module GroupsHelper
|
||||
end
|
||||
|
||||
def strip_url(url)
|
||||
url.andand.sub(%r{^https?://}i, '')
|
||||
url&.sub(%r{^https?://}i, '')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -35,7 +35,7 @@ class Customer < ApplicationRecord
|
||||
private
|
||||
|
||||
def downcase_email
|
||||
email.andand.downcase!
|
||||
email&.downcase!
|
||||
end
|
||||
|
||||
def empty_code
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -86,7 +86,7 @@ module ProductImport
|
||||
end
|
||||
|
||||
def enterprise_products
|
||||
@processor.andand.enterprise_products
|
||||
@processor&.enterprise_products
|
||||
end
|
||||
|
||||
def total_enterprise_products
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -17,7 +17,7 @@ module Api
|
||||
end
|
||||
|
||||
def distributor_name
|
||||
object.distributor.andand.name
|
||||
object.distributor&.name
|
||||
end
|
||||
|
||||
def display_outstanding_balance
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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?
|
||||
|
||||
@@ -110,6 +110,6 @@ class ProductTagRulesFilterer
|
||||
end
|
||||
|
||||
def customer_tag_list
|
||||
customer.andand.tag_list || []
|
||||
customer&.tag_list || []
|
||||
end
|
||||
end
|
||||
|
||||
@@ -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?
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
- distributor = @order.andand.distributor || current_distributor
|
||||
- distributor = @order&.distributor || current_distributor
|
||||
|
||||
%navigation
|
||||
%distributor.details.row
|
||||
|
||||
@@ -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]}"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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" } }
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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/
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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],
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}"
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user