mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-10 23:07:47 +00:00
Merge branch 'master' of https://github.com/openfoodfoundation/openfoodnetwork into issue/1253
This commit is contained in:
@@ -54,7 +54,6 @@ Layout/LineLength:
|
||||
- app/models/concerns/variant_stock.rb
|
||||
- app/models/content_configuration.rb
|
||||
- app/models/customer.rb
|
||||
- app/models/enterprise_fee.rb
|
||||
- app/models/enterprise_group.rb
|
||||
- app/models/enterprise_role.rb
|
||||
- app/models/inventory_item.rb
|
||||
|
||||
@@ -690,7 +690,7 @@ GEM
|
||||
hashdiff (>= 0.4.0, < 2.0.0)
|
||||
whenever (1.0.0)
|
||||
chronic (>= 0.6.3)
|
||||
wicked_pdf (1.4.0)
|
||||
wicked_pdf (2.1.0)
|
||||
activesupport
|
||||
wkhtmltopdf-binary (0.12.5)
|
||||
xml-simple (1.1.5)
|
||||
|
||||
@@ -23,10 +23,13 @@ angular.module("admin.orders").controller "ordersCtrl", ($scope, $timeout, Reque
|
||||
$scope.fetchResults()
|
||||
|
||||
$scope.fetchResults = (page=1) ->
|
||||
startDateWithTime = $scope.appendStringIfNotEmpty($scope['q']['completed_at_gteq'], ' 00:00:00')
|
||||
endDateWithTime = $scope.appendStringIfNotEmpty($scope['q']['completed_at_lteq'], ' 23:59:59')
|
||||
|
||||
$scope.resetSelected()
|
||||
params = {
|
||||
'q[completed_at_lt]': $scope['q']['completed_at_lt'],
|
||||
'q[completed_at_gt]': $scope['q']['completed_at_gt'],
|
||||
'q[completed_at_gteq]': startDateWithTime,
|
||||
'q[completed_at_lteq]': endDateWithTime,
|
||||
'q[state_eq]': $scope['q']['state_eq'],
|
||||
'q[number_cont]': $scope['q']['number_cont'],
|
||||
'q[email_cont]': $scope['q']['email_cont'],
|
||||
@@ -43,6 +46,11 @@ angular.module("admin.orders").controller "ordersCtrl", ($scope, $timeout, Reque
|
||||
}
|
||||
RequestMonitor.load(Orders.index(params).$promise)
|
||||
|
||||
$scope.appendStringIfNotEmpty = (baseString, stringToAppend) ->
|
||||
return baseString unless baseString
|
||||
|
||||
baseString + stringToAppend
|
||||
|
||||
$scope.resetSelected = ->
|
||||
$scope.selected_orders.length = 0
|
||||
$scope.selected = false
|
||||
|
||||
@@ -60,8 +60,8 @@ module Admin
|
||||
|
||||
def permitted_resource_params
|
||||
params.require(:enterprise_group).permit(
|
||||
:name, :description, :long_description, :on_front_page, :owner_id, :permalink,
|
||||
:email, :website, :facebook, :instagram, :linkedin, :twitter,
|
||||
:name, :description, :long_description, :logo, :promo_image, :on_front_page,
|
||||
:owner_id, :permalink, :email, :website, :facebook, :instagram, :linkedin, :twitter,
|
||||
enterprise_ids: [], address_attributes: PermittedAttributes::Address.attributes
|
||||
)
|
||||
end
|
||||
|
||||
93
app/models/calculator/default_tax.rb
Normal file
93
app/models/calculator/default_tax.rb
Normal file
@@ -0,0 +1,93 @@
|
||||
# frozen_string_literal: false
|
||||
|
||||
require_dependency 'spree/calculator'
|
||||
require 'open_food_network/enterprise_fee_calculator'
|
||||
|
||||
module Calculator
|
||||
class DefaultTax < Spree::Calculator
|
||||
def self.description
|
||||
Spree.t(:default_tax)
|
||||
end
|
||||
|
||||
def compute(computable)
|
||||
case computable
|
||||
when Spree::Order
|
||||
compute_order(computable)
|
||||
when Spree::LineItem
|
||||
compute_line_item(computable)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def rate
|
||||
calculable
|
||||
end
|
||||
|
||||
# Enable calculation of tax for enterprise fees with tax rates where included_in_price = false
|
||||
def compute_order(order)
|
||||
calculator = OpenFoodNetwork::EnterpriseFeeCalculator.new(order.distributor,
|
||||
order.order_cycle)
|
||||
|
||||
[
|
||||
line_items_total(order),
|
||||
per_item_fees_total(order, calculator),
|
||||
per_order_fees_total(order, calculator)
|
||||
].sum do |total|
|
||||
round_to_two_places(total * rate.amount)
|
||||
end
|
||||
end
|
||||
|
||||
def line_items_total(order)
|
||||
matched_line_items = order.line_items.select do |line_item|
|
||||
line_item.product.tax_category == rate.tax_category
|
||||
end
|
||||
|
||||
matched_line_items.sum(&:total)
|
||||
end
|
||||
|
||||
# Finds relevant fees for each line_item,
|
||||
# calculates the tax on them, and returns the total tax
|
||||
def per_item_fees_total(order, calculator)
|
||||
order.line_items.sum do |line_item|
|
||||
calculator.per_item_enterprise_fee_applicators_for(line_item.variant)
|
||||
.select { |applicator| applicable_rate?(applicator, line_item) }
|
||||
.sum { |applicator| applicator.enterprise_fee.compute_amount(line_item) }
|
||||
end
|
||||
end
|
||||
|
||||
def applicable_rate?(applicator, line_item)
|
||||
fee = applicator.enterprise_fee
|
||||
(!fee.inherits_tax_category && fee.tax_category == rate.tax_category) ||
|
||||
(fee.inherits_tax_category && line_item.product.tax_category == rate.tax_category)
|
||||
end
|
||||
|
||||
# Finds relevant fees for whole order,
|
||||
# calculates the tax on them, and returns the total tax
|
||||
def per_order_fees_total(order, calculator)
|
||||
calculator.per_order_enterprise_fee_applicators_for(order)
|
||||
.select { |applicator| applicator.enterprise_fee.tax_category == rate.tax_category }
|
||||
.sum { |applicator| applicator.enterprise_fee.compute_amount(order) }
|
||||
end
|
||||
|
||||
def compute_line_item(line_item)
|
||||
if line_item.tax_category == rate.tax_category
|
||||
if rate.included_in_price
|
||||
deduced_total_by_rate(line_item.total, rate)
|
||||
else
|
||||
round_to_two_places(line_item.total * rate.amount)
|
||||
end
|
||||
else
|
||||
0
|
||||
end
|
||||
end
|
||||
|
||||
def round_to_two_places(amount)
|
||||
BigDecimal(amount.to_s).round(2, BigDecimal::ROUND_HALF_UP)
|
||||
end
|
||||
|
||||
def deduced_total_by_rate(total, rate)
|
||||
round_to_two_places(total - ( total / (1 + rate.amount) ) )
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,11 +1,20 @@
|
||||
# frozen_string_literal: false
|
||||
|
||||
require_dependency 'spree/calculator'
|
||||
require 'spree/localized_number'
|
||||
|
||||
module Spree
|
||||
Calculator::FlatPercentItemTotal.class_eval do
|
||||
module Calculator
|
||||
class FlatPercentItemTotal < Spree::Calculator
|
||||
extend Spree::LocalizedNumber
|
||||
|
||||
preference :flat_percent, :decimal, default: 0
|
||||
|
||||
localize_number :preferred_flat_percent
|
||||
|
||||
def self.description
|
||||
Spree.t(:flat_percent)
|
||||
end
|
||||
|
||||
def compute(object)
|
||||
item_total = line_items_for(object).map(&:amount).sum
|
||||
value = item_total * BigDecimal(preferred_flat_percent.to_s) / 100.0
|
||||
23
app/models/calculator/flat_rate.rb
Normal file
23
app/models/calculator/flat_rate.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
# frozen_string_literal: false
|
||||
|
||||
require_dependency 'spree/calculator'
|
||||
require 'spree/localized_number'
|
||||
|
||||
module Calculator
|
||||
class FlatRate < Spree::Calculator
|
||||
extend Spree::LocalizedNumber
|
||||
|
||||
preference :amount, :decimal, default: 0
|
||||
preference :currency, :string, default: Spree::Config[:currency]
|
||||
|
||||
localize_number :preferred_amount
|
||||
|
||||
def self.description
|
||||
I18n.t(:flat_rate_per_order)
|
||||
end
|
||||
|
||||
def compute(_object = nil)
|
||||
preferred_amount
|
||||
end
|
||||
end
|
||||
end
|
||||
46
app/models/calculator/flexi_rate.rb
Normal file
46
app/models/calculator/flexi_rate.rb
Normal file
@@ -0,0 +1,46 @@
|
||||
# frozen_string_literal: false
|
||||
|
||||
require_dependency 'spree/calculator'
|
||||
require 'spree/localized_number'
|
||||
|
||||
module Calculator
|
||||
class FlexiRate < Spree::Calculator
|
||||
extend Spree::LocalizedNumber
|
||||
|
||||
preference :first_item, :decimal, default: 0.0
|
||||
preference :additional_item, :decimal, default: 0.0
|
||||
preference :max_items, :integer, default: 0
|
||||
preference :currency, :string, default: Spree::Config[:currency]
|
||||
|
||||
localize_number :preferred_first_item,
|
||||
:preferred_additional_item
|
||||
|
||||
def self.description
|
||||
I18n.t(:flexible_rate)
|
||||
end
|
||||
|
||||
def self.available?(_object)
|
||||
true
|
||||
end
|
||||
|
||||
def compute(object)
|
||||
max = preferred_max_items.to_i
|
||||
items_count = line_items_for(object).map(&:quantity).sum
|
||||
|
||||
# check max value to avoid divide by 0 errors
|
||||
return 0 if max.zero?
|
||||
|
||||
if items_count > max
|
||||
compute_for(max - 1)
|
||||
elsif items_count <= max
|
||||
compute_for(items_count - 1)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def compute_for(count)
|
||||
count * preferred_additional_item.to_f + preferred_first_item.to_f
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,9 +1,15 @@
|
||||
# frozen_string_literal: false
|
||||
|
||||
require_dependency 'spree/calculator'
|
||||
require 'spree/localized_number'
|
||||
|
||||
module Spree
|
||||
Calculator::PerItem.class_eval do
|
||||
module Calculator
|
||||
class PerItem < Spree::Calculator
|
||||
extend Spree::LocalizedNumber
|
||||
|
||||
preference :amount, :decimal, default: 0
|
||||
preference :currency, :string, default: Spree::Config[:currency]
|
||||
|
||||
localize_number :preferred_amount
|
||||
|
||||
def self.description
|
||||
@@ -14,11 +20,7 @@ module Spree
|
||||
return 0 if object.nil?
|
||||
|
||||
number_of_line_items = line_items_for(object).reduce(0) do |sum, line_item|
|
||||
value_to_add = if matching_products.blank? || matching_products.include?(line_item.product)
|
||||
line_item.quantity
|
||||
else
|
||||
0
|
||||
end
|
||||
value_to_add = line_item.quantity
|
||||
sum + value_to_add
|
||||
end
|
||||
preferred_amount * number_of_line_items
|
||||
@@ -1,9 +1,19 @@
|
||||
# frozen_string_literal: false
|
||||
|
||||
require_dependency 'spree/calculator'
|
||||
# For #to_d method on Ruby 1.8
|
||||
require 'bigdecimal/util'
|
||||
require 'spree/localized_number'
|
||||
|
||||
module Spree
|
||||
Calculator::PriceSack.class_eval do
|
||||
module Calculator
|
||||
class PriceSack < Spree::Calculator
|
||||
extend Spree::LocalizedNumber
|
||||
|
||||
preference :minimal_amount, :decimal, default: 0
|
||||
preference :normal_amount, :decimal, default: 0
|
||||
preference :discount_amount, :decimal, default: 0
|
||||
preference :currency, :string, default: Spree::Config[:currency]
|
||||
|
||||
localize_number :preferred_minimal_amount,
|
||||
:preferred_normal_amount,
|
||||
:preferred_discount_amount
|
||||
@@ -11,7 +11,9 @@ class EnterpriseFee < ActiveRecord::Base
|
||||
has_many :exchanges, through: :exchange_fees
|
||||
|
||||
FEE_TYPES = %w(packing transport admin sales fundraising).freeze
|
||||
PER_ORDER_CALCULATORS = ['Spree::Calculator::FlatRate', 'Spree::Calculator::FlexiRate', 'Spree::Calculator::PriceSack'].freeze
|
||||
PER_ORDER_CALCULATORS = ['Calculator::FlatRate',
|
||||
'Calculator::FlexiRate',
|
||||
'Calculator::PriceSack'].freeze
|
||||
|
||||
validates :fee_type, inclusion: { in: FEE_TYPES }
|
||||
validates :name, presence: true
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
require 'open_food_network/enterprise_fee_calculator'
|
||||
|
||||
Spree::Calculator::DefaultTax.class_eval do
|
||||
private
|
||||
|
||||
# Override this method to enable calculation of tax for
|
||||
# enterprise fees with tax rates where included_in_price = false
|
||||
def compute_order(order)
|
||||
matched_line_items = order.line_items.select do |line_item|
|
||||
line_item.product.tax_category == rate.tax_category
|
||||
end
|
||||
|
||||
line_items_total = matched_line_items.sum(&:total)
|
||||
|
||||
# Added this line
|
||||
calculator = OpenFoodNetwork::EnterpriseFeeCalculator.new(order.distributor, order.order_cycle)
|
||||
|
||||
# Added this block, finds relevant fees for each line_item, calculates the tax on them, and returns the total tax
|
||||
per_item_fees_total = order.line_items.sum do |line_item|
|
||||
calculator.per_item_enterprise_fee_applicators_for(line_item.variant)
|
||||
.select { |applicator|
|
||||
(!applicator.enterprise_fee.inherits_tax_category && applicator.enterprise_fee.tax_category == rate.tax_category) ||
|
||||
(applicator.enterprise_fee.inherits_tax_category && line_item.product.tax_category == rate.tax_category)
|
||||
}
|
||||
.sum { |applicator| applicator.enterprise_fee.compute_amount(line_item) }
|
||||
end
|
||||
|
||||
# Added this block, finds relevant fees for whole order, calculates the tax on them, and returns the total tax
|
||||
per_order_fees_total = calculator.per_order_enterprise_fee_applicators_for(order)
|
||||
.select { |applicator| applicator.enterprise_fee.tax_category == rate.tax_category }
|
||||
.sum { |applicator| applicator.enterprise_fee.compute_amount(order) }
|
||||
|
||||
# round_to_two_places(line_items_total * rate.amount) # Removed this line
|
||||
|
||||
# Added this block
|
||||
[line_items_total, per_item_fees_total, per_order_fees_total].sum do |total|
|
||||
round_to_two_places(total * rate.amount)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,13 +0,0 @@
|
||||
require 'spree/localized_number'
|
||||
|
||||
module Spree
|
||||
Calculator::FlatRate.class_eval do
|
||||
extend Spree::LocalizedNumber
|
||||
|
||||
localize_number :preferred_amount
|
||||
|
||||
def self.description
|
||||
I18n.t(:flat_rate_per_order)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,30 +0,0 @@
|
||||
require 'spree/localized_number'
|
||||
|
||||
module Spree
|
||||
Calculator::FlexiRate.class_eval do
|
||||
extend Spree::LocalizedNumber
|
||||
|
||||
localize_number :preferred_first_item,
|
||||
:preferred_additional_item
|
||||
|
||||
def self.description
|
||||
I18n.t(:flexible_rate)
|
||||
end
|
||||
|
||||
def compute(object)
|
||||
sum = 0
|
||||
max = preferred_max_items.to_i
|
||||
items_count = line_items_for(object).map(&:quantity).sum
|
||||
# check max value to avoid divide by 0 errors
|
||||
unless max == 0
|
||||
if items_count > max
|
||||
sum += (max - 1) * preferred_additional_item.to_f + preferred_first_item.to_f
|
||||
elsif items_count <= max
|
||||
sum += (items_count - 1) * preferred_additional_item.to_f + preferred_first_item.to_f
|
||||
end
|
||||
end
|
||||
|
||||
sum
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -49,7 +49,7 @@ Spree::PaymentMethod.class_eval do
|
||||
self.class.include Spree::Core::CalculatedAdjustments
|
||||
end
|
||||
|
||||
self.calculator ||= Spree::Calculator::FlatRate.new(preferred_amount: 0)
|
||||
self.calculator ||= Calculator::FlatRate.new(preferred_amount: 0)
|
||||
end
|
||||
|
||||
def has_distributor?(distributor)
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
.date-range-filter.field
|
||||
= label_tag nil, t(:date_range)
|
||||
.date-range-fields
|
||||
= text_field_tag "q[completed_at_gt]", nil, class: 'datepicker', datepicker: 'q.completed_at_gt', 'ng-model' => 'q.completed_at_gt', :placeholder => t(:start)
|
||||
= text_field_tag "q[completed_at_gteq]", nil, class: 'datepicker', datepicker: 'q.completed_at_gteq', 'ng-model' => 'q.completed_at_gteq', :placeholder => t(:start)
|
||||
%span.range-divider
|
||||
%i.icon-arrow-right
|
||||
= text_field_tag "q[completed_at_lt]", nil, class: 'datepicker', datepicker: 'q.completed_at_lt', 'ng-model' => 'q.completed_at_lt', :placeholder => t(:stop)
|
||||
= text_field_tag "q[completed_at_lteq]", nil, class: 'datepicker', datepicker: 'q.completed_at_lteq', 'ng-model' => 'q.completed_at_lteq', :placeholder => t(:stop)
|
||||
.field
|
||||
= label_tag nil, t(:status)
|
||||
= select_tag("q[state_eq]",
|
||||
|
||||
@@ -49,30 +49,36 @@ module Openfoodnetwork
|
||||
# Register Spree calculators
|
||||
initializer 'spree.register.calculators' do |app|
|
||||
app.config.spree.calculators.shipping_methods = [
|
||||
Spree::Calculator::FlatPercentItemTotal,
|
||||
Spree::Calculator::FlatRate,
|
||||
Spree::Calculator::FlexiRate,
|
||||
Spree::Calculator::PerItem,
|
||||
Spree::Calculator::PriceSack,
|
||||
Calculator::FlatPercentItemTotal,
|
||||
Calculator::FlatRate,
|
||||
Calculator::FlexiRate,
|
||||
Calculator::PerItem,
|
||||
Calculator::PriceSack,
|
||||
Calculator::Weight
|
||||
]
|
||||
|
||||
app.config.spree.calculators.add_class('enterprise_fees')
|
||||
config.spree.calculators.enterprise_fees = [
|
||||
Calculator::FlatPercentPerItem,
|
||||
Spree::Calculator::FlatRate,
|
||||
Spree::Calculator::FlexiRate,
|
||||
Spree::Calculator::PerItem,
|
||||
Spree::Calculator::PriceSack,
|
||||
Calculator::FlatRate,
|
||||
Calculator::FlexiRate,
|
||||
Calculator::PerItem,
|
||||
Calculator::PriceSack,
|
||||
Calculator::Weight
|
||||
]
|
||||
|
||||
app.config.spree.calculators.add_class('payment_methods')
|
||||
config.spree.calculators.payment_methods = [
|
||||
Spree::Calculator::FlatPercentItemTotal,
|
||||
Spree::Calculator::FlatRate,
|
||||
Spree::Calculator::FlexiRate,
|
||||
Spree::Calculator::PerItem,
|
||||
Spree::Calculator::PriceSack
|
||||
Calculator::FlatPercentItemTotal,
|
||||
Calculator::FlatRate,
|
||||
Calculator::FlexiRate,
|
||||
Calculator::PerItem,
|
||||
Calculator::PriceSack
|
||||
]
|
||||
|
||||
app.config.spree.calculators.add_class('tax_rates')
|
||||
config.spree.calculators.tax_rates = [
|
||||
Calculator::DefaultTax
|
||||
]
|
||||
end
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class MoveAllCalculatorsOutsideTheSpreeNamespace < ActiveRecord::Migration
|
||||
def up
|
||||
convert_calculator("DefaultTax")
|
||||
convert_calculator("FlatPercentItemTotal")
|
||||
convert_calculator("FlatRate")
|
||||
convert_calculator("FlexiRate")
|
||||
convert_calculator("PerItem")
|
||||
convert_calculator("PriceSack")
|
||||
end
|
||||
|
||||
def down
|
||||
revert_calculator("DefaultTax")
|
||||
revert_calculator("FlatPercentItemTotal")
|
||||
revert_calculator("FlatRate")
|
||||
revert_calculator("FlexiRate")
|
||||
revert_calculator("PerItem")
|
||||
revert_calculator("PriceSack")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def convert_calculator(calculator_base_name)
|
||||
update_calculator("Spree::Calculator::" + calculator_base_name,
|
||||
"Calculator::" + calculator_base_name)
|
||||
end
|
||||
|
||||
def revert_calculator(calculator_base_name)
|
||||
update_calculator("Calculator::" + calculator_base_name,
|
||||
"Spree::Calculator::" + calculator_base_name)
|
||||
end
|
||||
|
||||
def update_calculator(from, to)
|
||||
Spree::Calculator.connection.execute(
|
||||
"UPDATE spree_calculators SET type = '" + to + "' WHERE type = '" + from + "'"
|
||||
)
|
||||
end
|
||||
end
|
||||
@@ -99,11 +99,11 @@ module OrderManagement
|
||||
context "using flat rate calculators" do
|
||||
let(:shipping_method) {
|
||||
create(:shipping_method,
|
||||
calculator: Spree::Calculator::FlatRate.new(preferred_amount: 12.34))
|
||||
calculator: Calculator::FlatRate.new(preferred_amount: 12.34))
|
||||
}
|
||||
let(:payment_method) {
|
||||
create(:payment_method,
|
||||
calculator: Spree::Calculator::FlatRate.new(preferred_amount: 9.12))
|
||||
calculator: Calculator::FlatRate.new(preferred_amount: 9.12))
|
||||
}
|
||||
|
||||
it "calculates fees based on the rates provided" do
|
||||
@@ -116,13 +116,13 @@ module OrderManagement
|
||||
context "using flat percent item total calculators" do
|
||||
let(:shipping_method) {
|
||||
create(:shipping_method,
|
||||
calculator: Spree::Calculator::FlatPercentItemTotal.new(
|
||||
calculator: Calculator::FlatPercentItemTotal.new(
|
||||
preferred_flat_percent: 10
|
||||
))
|
||||
}
|
||||
let(:payment_method) {
|
||||
create(:payment_method,
|
||||
calculator: Spree::Calculator::FlatPercentItemTotal.new(
|
||||
calculator: Calculator::FlatPercentItemTotal.new(
|
||||
preferred_flat_percent: 20
|
||||
))
|
||||
}
|
||||
@@ -154,11 +154,11 @@ module OrderManagement
|
||||
context "using per item calculators" do
|
||||
let(:shipping_method) {
|
||||
create(:shipping_method,
|
||||
calculator: Spree::Calculator::PerItem.new(preferred_amount: 1.2))
|
||||
calculator: Calculator::PerItem.new(preferred_amount: 1.2))
|
||||
}
|
||||
let(:payment_method) {
|
||||
create(:payment_method,
|
||||
calculator: Spree::Calculator::PerItem.new(preferred_amount: 0.3))
|
||||
calculator: Calculator::PerItem.new(preferred_amount: 0.3))
|
||||
}
|
||||
|
||||
it "calculates fees based on the number of items and rate provided" do
|
||||
|
||||
@@ -29,7 +29,7 @@ class PaymentMethodFactory
|
||||
enterprise,
|
||||
"Cash on collection",
|
||||
"Pay on collection!",
|
||||
Spree::Calculator::FlatRate.new
|
||||
Calculator::FlatRate.new
|
||||
)
|
||||
end
|
||||
|
||||
@@ -39,7 +39,7 @@ class PaymentMethodFactory
|
||||
enterprise,
|
||||
"Credit card (fake)",
|
||||
"We charge 1%, but won't ask for your details. ;-)",
|
||||
Spree::Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 1)
|
||||
Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 1)
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ class ShippingMethodFactory
|
||||
name: "Home delivery #{enterprise.name}",
|
||||
description: "yummy food delivered at your door",
|
||||
require_ship_address: true,
|
||||
calculator_type: "Spree::Calculator::FlatRate"
|
||||
calculator_type: "Calculator::FlatRate"
|
||||
)
|
||||
delivery.calculator.preferred_amount = 2
|
||||
delivery.calculator.save!
|
||||
|
||||
@@ -192,7 +192,7 @@ describe Admin::EnterprisesController, type: :controller do
|
||||
id: tag_rule,
|
||||
type: "TagRule::DiscountOrder",
|
||||
preferred_customer_tags: "some,new,tags",
|
||||
calculator_type: "Spree::Calculator::FlatPercentItemTotal",
|
||||
calculator_type: "Calculator::FlatPercentItemTotal",
|
||||
calculator_attributes: { id: tag_rule.calculator.id, preferred_flat_percent: "15" }
|
||||
}
|
||||
}
|
||||
@@ -211,7 +211,7 @@ describe Admin::EnterprisesController, type: :controller do
|
||||
id: "",
|
||||
type: "TagRule::DiscountOrder",
|
||||
preferred_customer_tags: "tags,are,awesome",
|
||||
calculator_type: "Spree::Calculator::FlatPercentItemTotal",
|
||||
calculator_type: "Calculator::FlatPercentItemTotal",
|
||||
calculator_attributes: { id: "", preferred_flat_percent: "24" }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ module Spree
|
||||
|
||||
describe "setting included tax" do
|
||||
let(:order) { create(:order) }
|
||||
let(:tax_rate) { create(:tax_rate, amount: 0.1, calculator: Spree::Calculator::DefaultTax.new) }
|
||||
let(:tax_rate) { create(:tax_rate, amount: 0.1, calculator: Calculator::DefaultTax.new) }
|
||||
|
||||
describe "creating an adjustment" do
|
||||
it "sets included tax to zero when no tax rate is specified" do
|
||||
|
||||
@@ -50,7 +50,7 @@ describe Spree::Admin::ShippingMethodsController, type: :controller do
|
||||
end
|
||||
|
||||
it "updates details of a FlexiRate calculator" do
|
||||
shipping_method.calculator = Spree::Calculator::FlexiRate.new(calculable: shipping_method)
|
||||
shipping_method.calculator = Calculator::FlexiRate.new(calculable: shipping_method)
|
||||
params[:shipping_method][:calculator_attributes][:preferred_first_item] = 10
|
||||
params[:shipping_method][:calculator_attributes][:preferred_additional_item] = 20
|
||||
params[:shipping_method][:calculator_attributes][:preferred_max_items] = 30
|
||||
@@ -63,7 +63,7 @@ describe Spree::Admin::ShippingMethodsController, type: :controller do
|
||||
end
|
||||
|
||||
it "updates details of a PriceSack calculator" do
|
||||
shipping_method.calculator = Spree::Calculator::PriceSack.new(calculable: shipping_method)
|
||||
shipping_method.calculator = Calculator::PriceSack.new(calculable: shipping_method)
|
||||
params[:shipping_method][:calculator_attributes][:preferred_minimal_amount] = 10
|
||||
params[:shipping_method][:calculator_attributes][:preferred_normal_amount] = 20
|
||||
params[:shipping_method][:calculator_attributes][:preferred_discount_amount] = 30
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
FactoryBot.define do
|
||||
factory :calculator_flat_rate, class: Spree::Calculator::FlatRate do
|
||||
factory :calculator_flat_rate, class: Calculator::FlatRate do
|
||||
preferred_amount { generate(:calculator_amount) }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
FactoryBot.define do
|
||||
sequence(:calculator_amount)
|
||||
factory :calculator_per_item, class: Spree::Calculator::PerItem do
|
||||
factory :calculator_per_item, class: Calculator::PerItem do
|
||||
preferred_amount { generate(:calculator_amount) }
|
||||
end
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ FactoryBot.define do
|
||||
create(:tax_rate, amount: proxy.tax_rate_amount,
|
||||
tax_category: product.tax_category,
|
||||
included_in_price: true,
|
||||
calculator: Spree::Calculator::DefaultTax.new,
|
||||
calculator: Calculator::DefaultTax.new,
|
||||
zone: proxy.zone,
|
||||
name: proxy.tax_rate_name)
|
||||
end
|
||||
|
||||
@@ -9,13 +9,13 @@ FactoryBot.define do
|
||||
end
|
||||
|
||||
trait :flat_rate do
|
||||
calculator { Spree::Calculator::FlatRate.new(preferred_amount: 50.0) }
|
||||
calculator { Calculator::FlatRate.new(preferred_amount: 50.0) }
|
||||
end
|
||||
|
||||
trait :expensive_name do
|
||||
name { "Shipping" }
|
||||
description { "Expensive" }
|
||||
calculator { Spree::Calculator::FlatRate.new(preferred_amount: 100.55) }
|
||||
calculator { Calculator::FlatRate.new(preferred_amount: 100.55) }
|
||||
end
|
||||
|
||||
trait :distributor do
|
||||
|
||||
@@ -18,7 +18,7 @@ FactoryBot.define do
|
||||
factory :tag_rule, class: TagRule::DiscountOrder do
|
||||
enterprise { FactoryBot.create :distributor_enterprise }
|
||||
before(:create) do |tr|
|
||||
tr.calculator = Spree::Calculator::FlatPercentItemTotal.new(calculable: tr)
|
||||
tr.calculator = Calculator::FlatPercentItemTotal.new(calculable: tr)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -69,7 +69,8 @@ feature '
|
||||
select 'My supplier', from: 'new_supplier_id'
|
||||
click_button 'Add supplier'
|
||||
expect(page).to have_selector("table.exchanges tr.supplier", text: "My supplier")
|
||||
page.all("table.exchanges tr.supplier td.products").each(&:click)
|
||||
|
||||
open_all_exchange_product_tabs
|
||||
|
||||
expect(page).to have_selector "#order_cycle_incoming_exchange_1_variants_#{initial_variants.last.id}", visible: true
|
||||
page.find("#order_cycle_incoming_exchange_1_variants_#{initial_variants.last.id}", visible: true).click # uncheck (with visible:true filter)
|
||||
@@ -87,6 +88,7 @@ feature '
|
||||
select 'Supplier fee 2', from: 'order_cycle_incoming_exchange_2_enterprise_fees_0_enterprise_fee_id'
|
||||
|
||||
click_button 'Save and Next'
|
||||
expect(page).to have_content 'Your order cycle has been updated.'
|
||||
|
||||
# And I add a distributor and some products
|
||||
select 'My distributor', from: 'new_distributor_id'
|
||||
@@ -105,12 +107,7 @@ feature '
|
||||
find(:css, "tags-input .tags input").set "wholesale\n"
|
||||
end
|
||||
|
||||
exchange_rows = page.all("table.exchanges tbody")
|
||||
exchange_rows.each do |exchange_row|
|
||||
exchange_row.find("td.products").click
|
||||
# Wait for the products panel to be visible.
|
||||
expect(exchange_row).to have_selector "tr", count: 2
|
||||
end
|
||||
open_all_exchange_product_tabs
|
||||
|
||||
uncheck "order_cycle_outgoing_exchange_2_variants_#{v1.id}"
|
||||
check "order_cycle_outgoing_exchange_2_variants_#{v2.id}"
|
||||
@@ -165,4 +162,15 @@ feature '
|
||||
def wait_for_edit_form_to_load_order_cycle(order_cycle)
|
||||
expect(page).to have_field "order_cycle_name", with: order_cycle.name
|
||||
end
|
||||
|
||||
def open_all_exchange_product_tabs
|
||||
exchange_rows = page.all("table.exchanges tbody")
|
||||
exchange_rows.each do |exchange_row|
|
||||
exchange_row.find("td.products").click
|
||||
within(exchange_row) do
|
||||
# Wait for the products panel to be visible.
|
||||
expect(page).to have_selector ".exchange-products"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -21,7 +21,7 @@ feature '
|
||||
|
||||
# This calculator doesn't handle a `nil` order well.
|
||||
# That has been useful in finding bugs. ;-)
|
||||
payment_method.calculator = Spree::Calculator::FlatPercentItemTotal.new
|
||||
payment_method.calculator = Calculator::FlatPercentItemTotal.new
|
||||
payment_method.save!
|
||||
end
|
||||
|
||||
|
||||
@@ -170,7 +170,7 @@ feature '
|
||||
let(:user1) { create_enterprise_user enterprises: [distributor1] }
|
||||
let(:user2) { create_enterprise_user enterprises: [distributor2] }
|
||||
let!(:shipping_method) { create(:shipping_method_with, :expensive_name, distributors: [distributor1]) }
|
||||
let(:enterprise_fee) { create(:enterprise_fee, enterprise: user1.enterprises.first, tax_category: product2.tax_category, calculator: Spree::Calculator::FlatRate.new(preferred_amount: 120.0)) }
|
||||
let(:enterprise_fee) { create(:enterprise_fee, enterprise: user1.enterprises.first, tax_category: product2.tax_category, calculator: Calculator::FlatRate.new(preferred_amount: 120.0)) }
|
||||
let(:order_cycle) { create(:simple_order_cycle, coordinator: distributor1, coordinator_fees: [enterprise_fee], distributors: [distributor1], variants: [product1.master]) }
|
||||
|
||||
let!(:zone) { create(:zone_with_member) }
|
||||
@@ -384,8 +384,8 @@ feature '
|
||||
let(:shipping_method) { create(:shipping_method_with, :expensive_name) }
|
||||
let(:shipment) { create(:shipment_with, :shipping_method, shipping_method: shipping_method) }
|
||||
|
||||
let(:enterprise_fee1) { create(:enterprise_fee, enterprise: user1.enterprises.first, tax_category: product2.tax_category, calculator: Spree::Calculator::FlatRate.new(preferred_amount: 10)) }
|
||||
let(:enterprise_fee2) { create(:enterprise_fee, enterprise: user1.enterprises.first, tax_category: product2.tax_category, calculator: Spree::Calculator::FlatRate.new(preferred_amount: 20)) }
|
||||
let(:enterprise_fee1) { create(:enterprise_fee, enterprise: user1.enterprises.first, tax_category: product2.tax_category, calculator: Calculator::FlatRate.new(preferred_amount: 10)) }
|
||||
let(:enterprise_fee2) { create(:enterprise_fee, enterprise: user1.enterprises.first, tax_category: product2.tax_category, calculator: Calculator::FlatRate.new(preferred_amount: 20)) }
|
||||
let(:order_cycle) { create(:simple_order_cycle, coordinator: distributor1, coordinator_fees: [enterprise_fee1, enterprise_fee2], distributors: [distributor1], variants: [product1.master]) }
|
||||
|
||||
let!(:zone) { create(:zone_with_member) }
|
||||
|
||||
@@ -80,7 +80,7 @@ feature "full-page cart", js: true do
|
||||
describe "admin and handling flat fees" do
|
||||
context "when there are fees" do
|
||||
let(:handling_fee) {
|
||||
create(:enterprise_fee, calculator: Spree::Calculator::FlatRate.new(preferred_amount: 1),
|
||||
create(:enterprise_fee, calculator: Calculator::FlatRate.new(preferred_amount: 1),
|
||||
enterprise: order_cycle.coordinator, fee_type: 'admin')
|
||||
}
|
||||
|
||||
|
||||
@@ -26,11 +26,11 @@ feature "As a consumer I want to check out my cart", js: true do
|
||||
end
|
||||
|
||||
describe "with shipping and payment methods" do
|
||||
let(:free_shipping) { create(:shipping_method, require_ship_address: true, name: "Frogs", description: "yellow", calculator: Spree::Calculator::FlatRate.new(preferred_amount: 0.00)) }
|
||||
let(:shipping_with_fee) { create(:shipping_method, require_ship_address: false, name: "Donkeys", description: "blue", calculator: Spree::Calculator::FlatRate.new(preferred_amount: 4.56)) }
|
||||
let(:free_shipping) { create(:shipping_method, require_ship_address: true, name: "Frogs", description: "yellow", calculator: Calculator::FlatRate.new(preferred_amount: 0.00)) }
|
||||
let(:shipping_with_fee) { create(:shipping_method, require_ship_address: false, name: "Donkeys", description: "blue", calculator: Calculator::FlatRate.new(preferred_amount: 4.56)) }
|
||||
let(:tagged_shipping) { create(:shipping_method, require_ship_address: false, name: "Local", tag_list: "local") }
|
||||
let!(:check_without_fee) { create(:payment_method, distributors: [distributor], name: "Roger rabbit", type: "Spree::PaymentMethod::Check") }
|
||||
let!(:check_with_fee) { create(:payment_method, distributors: [distributor], calculator: Spree::Calculator::FlatRate.new(preferred_amount: 5.67)) }
|
||||
let!(:check_with_fee) { create(:payment_method, distributors: [distributor], calculator: Calculator::FlatRate.new(preferred_amount: 5.67)) }
|
||||
let!(:paypal) do
|
||||
Spree::Gateway::PayPalExpress.create!(name: "Paypal", environment: 'test', distributor_ids: [distributor.id]).tap do |pm|
|
||||
pm.preferred_login = 'devnull-facilitator_api1.rohanmitchell.com'
|
||||
|
||||
@@ -63,3 +63,14 @@ describe "ordersCtrl", ->
|
||||
expect(Orders.index).toHaveBeenCalledWith(jasmine.objectContaining({
|
||||
'q[order_cycle_id_in][]': ['4', '5']
|
||||
}))
|
||||
|
||||
it "filters orders on inclusive dates", ->
|
||||
$scope['q']['completed_at_gteq'] = '2020-06-08'
|
||||
$scope['q']['completed_at_lteq'] = '2020-06-09'
|
||||
|
||||
$scope.fetchResults()
|
||||
|
||||
expect(Orders.index).toHaveBeenCalledWith(jasmine.objectContaining({
|
||||
'q[completed_at_gteq]': '2020-06-08 00:00:00'
|
||||
'q[completed_at_lteq]': '2020-06-09 23:59:59'
|
||||
}))
|
||||
|
||||
@@ -16,7 +16,7 @@ module OpenFoodNetwork
|
||||
describe "summing all the per-item fees for the variant in the specified hub + order cycle" do
|
||||
let(:enterprise_fee1) { create(:enterprise_fee, amount: 20) }
|
||||
let(:enterprise_fee2) { create(:enterprise_fee, amount: 3) }
|
||||
let(:enterprise_fee3) { create(:enterprise_fee, calculator: Spree::Calculator::FlatRate.new(preferred_amount: 2)) }
|
||||
let(:enterprise_fee3) { create(:enterprise_fee, calculator: Calculator::FlatRate.new(preferred_amount: 2)) }
|
||||
|
||||
describe "supplier fees" do
|
||||
let!(:exchange1) {
|
||||
@@ -131,7 +131,7 @@ module OpenFoodNetwork
|
||||
let(:order) { create(:order, distributor: distributor, order_cycle: order_cycle) }
|
||||
let!(:line_item) { create(:line_item, order: order, variant: product1.master) }
|
||||
let(:enterprise_fee_line_item) { create(:enterprise_fee) }
|
||||
let(:enterprise_fee_order) { create(:enterprise_fee, calculator: Spree::Calculator::FlatRate.new(preferred_amount: 2)) }
|
||||
let(:enterprise_fee_order) { create(:enterprise_fee, calculator: Calculator::FlatRate.new(preferred_amount: 2)) }
|
||||
let!(:exchange) { create(:exchange, order_cycle: order_cycle, sender: coordinator, receiver: distributor, incoming: false, variants: [product1.master]) }
|
||||
|
||||
before { order.reload }
|
||||
|
||||
@@ -7,7 +7,7 @@ describe ProducerMailer, type: :mailer do
|
||||
before { setup_email }
|
||||
|
||||
let!(:zone) { create(:zone_with_member) }
|
||||
let!(:tax_rate) { create(:tax_rate, included_in_price: true, calculator: Spree::Calculator::DefaultTax.new, zone: zone, amount: 0.1) }
|
||||
let!(:tax_rate) { create(:tax_rate, included_in_price: true, calculator: Calculator::DefaultTax.new, zone: zone, amount: 0.1) }
|
||||
let!(:tax_category) { create(:tax_category, tax_rates: [tax_rate]) }
|
||||
let(:s1) { create(:supplier_enterprise) }
|
||||
let(:s2) { create(:supplier_enterprise) }
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Spree::Calculator::FlatPercentItemTotal do
|
||||
let(:calculator) { Spree::Calculator::FlatPercentItemTotal.new }
|
||||
describe Calculator::FlatPercentItemTotal do
|
||||
let(:calculator) { Calculator::FlatPercentItemTotal.new }
|
||||
let(:line_item) { build(:line_item, price: 10, quantity: 1) }
|
||||
|
||||
before { allow(calculator).to receive_messages preferred_flat_percent: 10 }
|
||||
@@ -1,7 +1,7 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Spree::Calculator::FlatRate do
|
||||
let(:calculator) { Spree::Calculator::FlatRate.new }
|
||||
describe Calculator::FlatRate do
|
||||
let(:calculator) { Calculator::FlatRate.new }
|
||||
|
||||
before { allow(calculator).to receive_messages preferred_amount: 10 }
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Spree::Calculator::FlexiRate do
|
||||
describe Calculator::FlexiRate do
|
||||
let(:line_item) { build(:line_item, quantity: quantity) }
|
||||
let(:calculator) do
|
||||
Spree::Calculator::FlexiRate.new(
|
||||
Calculator::FlexiRate.new(
|
||||
preferred_first_item: 2,
|
||||
preferred_additional_item: 1,
|
||||
preferred_max_items: 3
|
||||
@@ -27,7 +27,7 @@ describe Spree::Calculator::FlexiRate do
|
||||
end
|
||||
|
||||
it "allows creation of new object with all the attributes" do
|
||||
Spree::Calculator::FlexiRate.new(preferred_first_item: 1, preferred_additional_item: 1, preferred_max_items: 1)
|
||||
Calculator::FlexiRate.new(preferred_first_item: 1, preferred_additional_item: 1, preferred_max_items: 1)
|
||||
end
|
||||
|
||||
context "extends LocalizedNumber" do
|
||||
@@ -1,7 +1,7 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Spree::Calculator::PerItem do
|
||||
let(:calculator) { Spree::Calculator::PerItem.new(preferred_amount: 10) }
|
||||
describe Calculator::PerItem do
|
||||
let(:calculator) { Calculator::PerItem.new(preferred_amount: 10) }
|
||||
let(:shipping_calculable) { double(:calculable) }
|
||||
let(:line_item) { build(:line_item, quantity: 5) }
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Spree::Calculator::PriceSack do
|
||||
describe Calculator::PriceSack do
|
||||
let(:calculator) do
|
||||
calculator = Spree::Calculator::PriceSack.new
|
||||
calculator = Calculator::PriceSack.new
|
||||
calculator.preferred_minimal_amount = 5
|
||||
calculator.preferred_normal_amount = 10
|
||||
calculator.preferred_discount_amount = 1
|
||||
@@ -60,17 +60,17 @@ describe EnterpriseFee do
|
||||
describe "scopes" do
|
||||
describe "finding per-item enterprise fees" do
|
||||
it "does not return fees with FlatRate, FlexiRate and PriceSack calculators" do
|
||||
create(:enterprise_fee, calculator: Spree::Calculator::FlatRate.new)
|
||||
create(:enterprise_fee, calculator: Spree::Calculator::FlexiRate.new)
|
||||
create(:enterprise_fee, calculator: Spree::Calculator::PriceSack.new)
|
||||
create(:enterprise_fee, calculator: Calculator::FlatRate.new)
|
||||
create(:enterprise_fee, calculator: Calculator::FlexiRate.new)
|
||||
create(:enterprise_fee, calculator: Calculator::PriceSack.new)
|
||||
|
||||
expect(EnterpriseFee.per_item).to be_empty
|
||||
end
|
||||
|
||||
it "returns fees with any other calculator" do
|
||||
ef1 = create(:enterprise_fee, calculator: Spree::Calculator::DefaultTax.new)
|
||||
ef1 = create(:enterprise_fee, calculator: Calculator::DefaultTax.new)
|
||||
ef2 = create(:enterprise_fee, calculator: Calculator::FlatPercentPerItem.new)
|
||||
ef3 = create(:enterprise_fee, calculator: Spree::Calculator::PerItem.new)
|
||||
ef3 = create(:enterprise_fee, calculator: Calculator::PerItem.new)
|
||||
|
||||
expect(EnterpriseFee.per_item).to match_array [ef1, ef2, ef3]
|
||||
end
|
||||
@@ -78,17 +78,17 @@ describe EnterpriseFee do
|
||||
|
||||
describe "finding per-order enterprise fees" do
|
||||
it "returns fees with FlatRate, FlexiRate and PriceSack calculators" do
|
||||
ef1 = create(:enterprise_fee, calculator: Spree::Calculator::FlatRate.new)
|
||||
ef2 = create(:enterprise_fee, calculator: Spree::Calculator::FlexiRate.new)
|
||||
ef3 = create(:enterprise_fee, calculator: Spree::Calculator::PriceSack.new)
|
||||
ef1 = create(:enterprise_fee, calculator: Calculator::FlatRate.new)
|
||||
ef2 = create(:enterprise_fee, calculator: Calculator::FlexiRate.new)
|
||||
ef3 = create(:enterprise_fee, calculator: Calculator::PriceSack.new)
|
||||
|
||||
expect(EnterpriseFee.per_order).to match_array [ef1, ef2, ef3]
|
||||
end
|
||||
|
||||
it "does not return fees with any other calculator" do
|
||||
ef1 = create(:enterprise_fee, calculator: Spree::Calculator::DefaultTax.new)
|
||||
ef1 = create(:enterprise_fee, calculator: Calculator::DefaultTax.new)
|
||||
ef2 = create(:enterprise_fee, calculator: Calculator::FlatPercentPerItem.new)
|
||||
ef3 = create(:enterprise_fee, calculator: Spree::Calculator::PerItem.new)
|
||||
ef3 = create(:enterprise_fee, calculator: Calculator::PerItem.new)
|
||||
|
||||
expect(EnterpriseFee.per_order).to be_empty
|
||||
end
|
||||
|
||||
@@ -127,7 +127,7 @@ module Spree
|
||||
|
||||
describe "EnterpriseFee adjustments" do
|
||||
let(:zone) { create(:zone_with_member) }
|
||||
let(:fee_tax_rate) { create(:tax_rate, included_in_price: true, calculator: Calculator::DefaultTax.new, zone: zone, amount: 0.1) }
|
||||
let(:fee_tax_rate) { create(:tax_rate, included_in_price: true, calculator: ::Calculator::DefaultTax.new, zone: zone, amount: 0.1) }
|
||||
let(:fee_tax_category) { create(:tax_category, tax_rates: [fee_tax_rate]) }
|
||||
|
||||
let(:coordinator) { create(:distributor_enterprise, charges_sales_tax: true) }
|
||||
@@ -143,7 +143,7 @@ module Spree
|
||||
end
|
||||
|
||||
context "when enterprise fees are taxed per-order" do
|
||||
let(:enterprise_fee) { create(:enterprise_fee, enterprise: coordinator, tax_category: fee_tax_category, calculator: Calculator::FlatRate.new(preferred_amount: 50.0)) }
|
||||
let(:enterprise_fee) { create(:enterprise_fee, enterprise: coordinator, tax_category: fee_tax_category, calculator: ::Calculator::FlatRate.new(preferred_amount: 50.0)) }
|
||||
|
||||
describe "when the tax rate includes the tax in the price" do
|
||||
it "records the tax on the enterprise fee adjustments" do
|
||||
@@ -181,7 +181,7 @@ module Spree
|
||||
end
|
||||
|
||||
context "when enterprise fees are taxed per-item" do
|
||||
let(:enterprise_fee) { create(:enterprise_fee, enterprise: coordinator, tax_category: fee_tax_category, calculator: Calculator::PerItem.new(preferred_amount: 50.0)) }
|
||||
let(:enterprise_fee) { create(:enterprise_fee, enterprise: coordinator, tax_category: fee_tax_category, calculator: ::Calculator::PerItem.new(preferred_amount: 50.0)) }
|
||||
|
||||
describe "when the tax rate includes the tax in the price" do
|
||||
it "records the tax on the enterprise fee adjustments" do
|
||||
@@ -205,7 +205,7 @@ module Spree
|
||||
end
|
||||
|
||||
context "when enterprise fees inherit their tax_category from the product they are applied to" do
|
||||
let(:product_tax_rate) { create(:tax_rate, included_in_price: true, calculator: Calculator::DefaultTax.new, zone: zone, amount: 0.2) }
|
||||
let(:product_tax_rate) { create(:tax_rate, included_in_price: true, calculator: ::Calculator::DefaultTax.new, zone: zone, amount: 0.2) }
|
||||
let(:product_tax_category) { create(:tax_category, tax_rates: [product_tax_rate]) }
|
||||
|
||||
before do
|
||||
@@ -216,7 +216,7 @@ module Spree
|
||||
end
|
||||
|
||||
context "when enterprise fees are taxed per-order" do
|
||||
let(:enterprise_fee) { create(:enterprise_fee, enterprise: coordinator, inherits_tax_category: true, calculator: Calculator::FlatRate.new(preferred_amount: 50.0)) }
|
||||
let(:enterprise_fee) { create(:enterprise_fee, enterprise: coordinator, inherits_tax_category: true, calculator: ::Calculator::FlatRate.new(preferred_amount: 50.0)) }
|
||||
|
||||
describe "when the tax rate includes the tax in the price" do
|
||||
it "records no tax on the enterprise fee adjustments" do
|
||||
@@ -246,7 +246,7 @@ module Spree
|
||||
end
|
||||
|
||||
context "when enterprise fees are taxed per-item" do
|
||||
let(:enterprise_fee) { create(:enterprise_fee, enterprise: coordinator, inherits_tax_category: true, calculator: Calculator::PerItem.new(preferred_amount: 50.0)) }
|
||||
let(:enterprise_fee) { create(:enterprise_fee, enterprise: coordinator, inherits_tax_category: true, calculator: ::Calculator::PerItem.new(preferred_amount: 50.0)) }
|
||||
|
||||
describe "when the tax rate includes the tax in the price" do
|
||||
it "records the tax on the enterprise fee adjustments" do
|
||||
|
||||
@@ -35,7 +35,7 @@ module Spree
|
||||
end
|
||||
|
||||
describe "finding line items with and without tax" do
|
||||
let(:tax_rate) { create(:tax_rate, calculator: Spree::Calculator::DefaultTax.new) }
|
||||
let(:tax_rate) { create(:tax_rate, calculator: Calculator::DefaultTax.new) }
|
||||
let!(:adjustment1) { create(:adjustment, originator: tax_rate, label: "TR", amount: 123, included_tax: 10.00) }
|
||||
|
||||
before do
|
||||
@@ -311,7 +311,7 @@ module Spree
|
||||
describe "tax" do
|
||||
let(:li_no_tax) { create(:line_item) }
|
||||
let(:li_tax) { create(:line_item) }
|
||||
let(:tax_rate) { create(:tax_rate, calculator: Spree::Calculator::DefaultTax.new) }
|
||||
let(:tax_rate) { create(:tax_rate, calculator: Calculator::DefaultTax.new) }
|
||||
let!(:adjustment) { create(:adjustment, adjustable: li_tax, originator: tax_rate, label: "TR", amount: 123, included_tax: 10.00) }
|
||||
|
||||
context "checking if a line item has tax included" do
|
||||
|
||||
@@ -137,7 +137,7 @@ describe Spree::Order do
|
||||
let(:li) { create(:line_item, order: o) }
|
||||
|
||||
it "returns the sum of eligible enterprise fee adjustments" do
|
||||
ef = create(:enterprise_fee, calculator: Spree::Calculator::FlatRate.new )
|
||||
ef = create(:enterprise_fee, calculator: Calculator::FlatRate.new )
|
||||
ef.calculator.set_preference :amount, 123.45
|
||||
a = ef.create_adjustment("adjustment", o, o, true)
|
||||
|
||||
@@ -145,7 +145,7 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
it "does not include ineligible adjustments" do
|
||||
ef = create(:enterprise_fee, calculator: Spree::Calculator::FlatRate.new )
|
||||
ef = create(:enterprise_fee, calculator: Calculator::FlatRate.new )
|
||||
ef.calculator.set_preference :amount, 123.45
|
||||
a = ef.create_adjustment("adjustment", o, o, true)
|
||||
|
||||
@@ -155,7 +155,7 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
it "does not include adjustments that do not originate from enterprise fees" do
|
||||
sm = create(:shipping_method, calculator: Spree::Calculator::FlatRate.new )
|
||||
sm = create(:shipping_method, calculator: Calculator::FlatRate.new )
|
||||
sm.calculator.set_preference :amount, 123.45
|
||||
sm.create_adjustment("adjustment", o, o, true)
|
||||
|
||||
@@ -163,7 +163,7 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
it "does not include adjustments whose source is a line item" do
|
||||
ef = create(:enterprise_fee, calculator: Spree::Calculator::PerItem.new )
|
||||
ef = create(:enterprise_fee, calculator: Calculator::PerItem.new )
|
||||
ef.calculator.set_preference :amount, 123.45
|
||||
ef.create_adjustment("adjustment", li.order, li, true)
|
||||
|
||||
@@ -669,7 +669,7 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
context "changing the shipping method to one without fees" do
|
||||
let(:shipping_method) { create(:shipping_method, calculator: Spree::Calculator::FlatRate.new(preferred_amount: 0)) }
|
||||
let(:shipping_method) { create(:shipping_method, calculator: Calculator::FlatRate.new(preferred_amount: 0)) }
|
||||
|
||||
it "updates shipping fees" do
|
||||
order.shipments = [create(:shipment_with, :shipping_method, shipping_method: shipping_method)]
|
||||
@@ -681,7 +681,7 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
context "changing the payment method to one without fees" do
|
||||
let(:payment_method) { create(:payment_method, calculator: Spree::Calculator::FlatRate.new(preferred_amount: 0)) }
|
||||
let(:payment_method) { create(:payment_method, calculator: Calculator::FlatRate.new(preferred_amount: 0)) }
|
||||
|
||||
it "removes transaction fees" do
|
||||
# Change the payment method
|
||||
|
||||
@@ -136,12 +136,11 @@ module Spree
|
||||
context "when order-based calculator" do
|
||||
let!(:shop) { create(:enterprise) }
|
||||
let!(:payment_method) { create(:payment_method, calculator: calculator) }
|
||||
|
||||
let!(:calculator) do
|
||||
Spree::Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10)
|
||||
::Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10)
|
||||
end
|
||||
|
||||
context "when order complete and inventory tracking enabled" do
|
||||
context "when order complete" do
|
||||
let!(:order) { create(:completed_order_with_totals, distributor: shop) }
|
||||
let!(:variant) { order.line_items.first.variant }
|
||||
let!(:inventory_item) { create(:inventory_item, enterprise: shop, variant: variant) }
|
||||
@@ -159,7 +158,7 @@ module Spree
|
||||
let(:shop) { create(:enterprise) }
|
||||
let(:payment_method) { create(:stripe_payment_method, distributor_ids: [create(:distributor_enterprise).id], preferred_enterprise_id: shop.id) }
|
||||
let(:payment) { create(:payment, order: order, payment_method: payment_method, amount: order.total) }
|
||||
let(:calculator) { Spree::Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10) }
|
||||
let(:calculator) { ::Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10) }
|
||||
|
||||
before do
|
||||
payment_method.calculator = calculator
|
||||
|
||||
@@ -33,7 +33,7 @@ module Spree
|
||||
end
|
||||
|
||||
describe "ensuring that tax rate is marked as tax included_in_price" do
|
||||
let(:tax_rate) { create(:tax_rate, included_in_price: false, calculator: Spree::Calculator::DefaultTax.new) }
|
||||
let(:tax_rate) { create(:tax_rate, included_in_price: false, calculator: Calculator::DefaultTax.new) }
|
||||
|
||||
it "sets included_in_price to true" do
|
||||
tax_rate.send(:with_tax_included_in_price) do
|
||||
|
||||
@@ -73,7 +73,7 @@ describe TagRule::DiscountOrder, type: :model do
|
||||
end
|
||||
|
||||
context "when shipping charges apply" do
|
||||
let!(:shipping_method) { create(:shipping_method, calculator: Spree::Calculator::FlatRate.new( preferred_amount: 25.00 ) ) }
|
||||
let!(:shipping_method) { create(:shipping_method, calculator: Calculator::FlatRate.new( preferred_amount: 25.00 ) ) }
|
||||
before do
|
||||
shipping_method.create_adjustment("Shipping", order, order, true)
|
||||
end
|
||||
|
||||
@@ -33,7 +33,7 @@ describe VariantOverride do
|
||||
expect(VariantOverride.indexed(hub2)).to eq( variant => vo2 )
|
||||
end
|
||||
|
||||
it "does not include overrides for soft-deleted variants" do
|
||||
xit "does not include overrides for soft-deleted variants" do
|
||||
variant.delete
|
||||
expect(VariantOverride.indexed(hub1)).to eq( nil => vo1 )
|
||||
end
|
||||
|
||||
@@ -32,7 +32,7 @@ describe "checking out an order that initially fails", type: :request do
|
||||
end
|
||||
|
||||
context "when shipping and payment fees apply" do
|
||||
let(:calculator) { Spree::Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10) }
|
||||
let(:calculator) { Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10) }
|
||||
|
||||
before do
|
||||
payment_method.calculator = calculator.dup
|
||||
|
||||
@@ -50,7 +50,7 @@ describe "checking out an order with a paypal express payment method", type: :re
|
||||
end
|
||||
|
||||
context "with a flat percent calculator" do
|
||||
let(:calculator) { Spree::Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10) }
|
||||
let(:calculator) { Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10) }
|
||||
|
||||
before do
|
||||
payment_method.calculator = calculator
|
||||
|
||||
@@ -10,7 +10,7 @@ describe "checking out an order with a Stripe Connect payment method", type: :re
|
||||
let!(:shipping_method) do
|
||||
create(
|
||||
:shipping_method,
|
||||
calculator: Spree::Calculator::FlatRate.new(preferred_amount: 0),
|
||||
calculator: Calculator::FlatRate.new(preferred_amount: 0),
|
||||
distributors: [enterprise]
|
||||
)
|
||||
end
|
||||
|
||||
@@ -12,7 +12,7 @@ describe "checking out an order with a Stripe SCA payment method", type: :reques
|
||||
let!(:shipping_method) do
|
||||
create(
|
||||
:shipping_method,
|
||||
calculator: Spree::Calculator::FlatRate.new(preferred_amount: 0),
|
||||
calculator: Calculator::FlatRate.new(preferred_amount: 0),
|
||||
distributors: [enterprise]
|
||||
)
|
||||
end
|
||||
|
||||
@@ -4,24 +4,57 @@ require "spec_helper"
|
||||
|
||||
describe OrderTaxAdjustmentsFetcher do
|
||||
describe "#totals" do
|
||||
let(:zone) { create(:zone_with_member) }
|
||||
let(:coordinator) { create(:distributor_enterprise, charges_sales_tax: true) }
|
||||
let(:zone) { create(:zone_with_member) }
|
||||
let(:coordinator) { create(:distributor_enterprise, charges_sales_tax: true) }
|
||||
|
||||
let(:tax_rate10) { create(:tax_rate, included_in_price: true, calculator: Spree::Calculator::DefaultTax.new, amount: 0.1, zone: zone) }
|
||||
let(:tax_rate15) { create(:tax_rate, included_in_price: true, calculator: Spree::Calculator::DefaultTax.new, amount: 0.15, zone: zone) }
|
||||
let(:tax_rate20) { create(:tax_rate, included_in_price: true, calculator: Spree::Calculator::DefaultTax.new, amount: 0.2, zone: zone) }
|
||||
let(:tax_rate25) { create(:tax_rate, included_in_price: true, calculator: Spree::Calculator::DefaultTax.new, amount: 0.25, zone: zone) }
|
||||
let(:tax_category10) { create(:tax_category, tax_rates: [tax_rate10]) }
|
||||
let(:tax_category15) { create(:tax_category, tax_rates: [tax_rate15]) }
|
||||
let(:tax_category20) { create(:tax_category, tax_rates: [tax_rate20]) }
|
||||
let(:tax_category25) { create(:tax_category, tax_rates: [tax_rate25]) }
|
||||
let(:tax_rate10) do
|
||||
create(:tax_rate, included_in_price: true,
|
||||
calculator: Calculator::DefaultTax.new,
|
||||
amount: 0.1,
|
||||
zone: zone)
|
||||
end
|
||||
let(:tax_rate15) do
|
||||
create(:tax_rate, included_in_price: true,
|
||||
calculator: Calculator::DefaultTax.new,
|
||||
amount: 0.15,
|
||||
zone: zone)
|
||||
end
|
||||
let(:tax_rate20) do
|
||||
create(:tax_rate, included_in_price: true,
|
||||
calculator: Calculator::DefaultTax.new,
|
||||
amount: 0.2,
|
||||
zone: zone)
|
||||
end
|
||||
let(:tax_rate25) do
|
||||
create(:tax_rate, included_in_price: true,
|
||||
calculator: Calculator::DefaultTax.new,
|
||||
amount: 0.25,
|
||||
zone: zone)
|
||||
end
|
||||
let(:tax_category10) { create(:tax_category, tax_rates: [tax_rate10]) }
|
||||
let(:tax_category15) { create(:tax_category, tax_rates: [tax_rate15]) }
|
||||
let(:tax_category20) { create(:tax_category, tax_rates: [tax_rate20]) }
|
||||
let(:tax_category25) { create(:tax_category, tax_rates: [tax_rate25]) }
|
||||
|
||||
let(:variant) { create(:variant, product: create(:product, tax_category: tax_category10)) }
|
||||
let(:enterprise_fee) { create(:enterprise_fee, enterprise: coordinator, tax_category: tax_category20, calculator: Spree::Calculator::FlatRate.new(preferred_amount: 48.0)) }
|
||||
let(:additional_adjustment) { create(:adjustment, amount: 50.0, included_tax: tax_rate25.compute_tax(50.0)) }
|
||||
let(:variant) do
|
||||
create(:variant, product: create(:product, tax_category: tax_category10))
|
||||
end
|
||||
let(:enterprise_fee) do
|
||||
create(:enterprise_fee, enterprise: coordinator,
|
||||
tax_category: tax_category20,
|
||||
calculator: Calculator::FlatRate.new(preferred_amount: 48.0))
|
||||
end
|
||||
let(:additional_adjustment) do
|
||||
create(:adjustment, amount: 50.0, included_tax: tax_rate25.compute_tax(50.0))
|
||||
end
|
||||
|
||||
let(:order_cycle) { create(:simple_order_cycle, coordinator: coordinator, coordinator_fees: [enterprise_fee], distributors: [coordinator], variants: [variant]) }
|
||||
let(:line_item) { create(:line_item, variant: variant, price: 44.0) }
|
||||
let(:order_cycle) do
|
||||
create(:simple_order_cycle, coordinator: coordinator,
|
||||
coordinator_fees: [enterprise_fee],
|
||||
distributors: [coordinator],
|
||||
variants: [variant])
|
||||
end
|
||||
let(:line_item) { create(:line_item, variant: variant, price: 44.0) }
|
||||
let(:order) do
|
||||
create(
|
||||
:order,
|
||||
@@ -38,8 +71,12 @@ describe OrderTaxAdjustmentsFetcher do
|
||||
allow(Spree::Config).to receive(:shipping_tax_rate).and_return(tax_rate15.amount)
|
||||
end
|
||||
|
||||
let(:shipping_method) { create(:shipping_method, calculator: Spree::Calculator::FlatRate.new(preferred_amount: 46.0)) }
|
||||
let!(:shipment) { create(:shipment_with, :shipping_method, shipping_method: shipping_method, order: order) }
|
||||
let(:shipping_method) do
|
||||
create(:shipping_method, calculator: Calculator::FlatRate.new(preferred_amount: 46.0))
|
||||
end
|
||||
let!(:shipment) do
|
||||
create(:shipment_with, :shipping_method, shipping_method: shipping_method, order: order)
|
||||
end
|
||||
|
||||
before do
|
||||
order.create_tax_charge!
|
||||
|
||||
@@ -66,7 +66,7 @@ describe TaxRateFinder do
|
||||
create(
|
||||
:tax_rate,
|
||||
amount: amount,
|
||||
calculator: Spree::Calculator::DefaultTax.new,
|
||||
calculator: Calculator::DefaultTax.new,
|
||||
zone: zone
|
||||
)
|
||||
end
|
||||
|
||||
@@ -46,23 +46,6 @@ module AuthenticationWorkflow
|
||||
# click_button 'Login'
|
||||
end
|
||||
|
||||
def login_to_consumer_section
|
||||
user_role = Spree::Role.find_or_create_by!(name: 'user')
|
||||
user = create_enterprise_user(
|
||||
email: 'someone@ofn.org',
|
||||
password: 'passw0rd',
|
||||
password_confirmation: 'passw0rd',
|
||||
remember_me: false,
|
||||
persistence_token: 'pass',
|
||||
login: 'someone@ofn.org'
|
||||
)
|
||||
|
||||
user.spree_roles << user_role
|
||||
|
||||
visit spree.login_path
|
||||
fill_in_and_submit_login_form user
|
||||
end
|
||||
|
||||
def fill_in_and_submit_login_form(user)
|
||||
fill_in "email", with: user.email
|
||||
fill_in "password", with: user.password
|
||||
|
||||
Reference in New Issue
Block a user