mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Merge pull request #7420 from Matt-Yorkley/adjustments-controller
Adjustments controller index
This commit is contained in:
@@ -18,7 +18,12 @@ module Spree
|
||||
end
|
||||
|
||||
def collection
|
||||
parent.all_adjustments.eligible
|
||||
order_adjustments = parent.adjustments.where.not(originator_type: 'EnterpriseFee')
|
||||
admin_adjustments = parent.adjustments.admin
|
||||
payment_fees = parent.all_adjustments.payment_fee.eligible
|
||||
shipping_fees = parent.all_adjustments.shipping
|
||||
|
||||
order_adjustments.or(admin_adjustments) | payment_fees.or(shipping_fees)
|
||||
end
|
||||
|
||||
def find_resource
|
||||
|
||||
@@ -118,6 +118,10 @@ module Spree
|
||||
Spree::Money.new(amount, currency: currency)
|
||||
end
|
||||
|
||||
def admin?
|
||||
originator_type.nil?
|
||||
end
|
||||
|
||||
def immutable?
|
||||
state != "open"
|
||||
end
|
||||
|
||||
@@ -5,18 +5,19 @@
|
||||
= text_field :adjustment, :amount, :class => 'fullwidth'
|
||||
= f.error_message_on :amount
|
||||
|
||||
.four.columns
|
||||
= f.field_container :included_tax do
|
||||
= f.label :included_tax, t(:included_tax)
|
||||
= f.text_field :included_tax, disabled: true, class: 'fullwidth',
|
||||
value: number_with_precision(f.object.included_tax, precision: 2)
|
||||
= f.error_message_on :included_tax
|
||||
- if @adjustment.admin?
|
||||
.four.columns
|
||||
= f.field_container :included_tax do
|
||||
= f.label :included_tax, t(:included_tax)
|
||||
= f.text_field :included_tax, disabled: true, class: 'fullwidth',
|
||||
value: number_with_precision(f.object.included_tax, precision: 2)
|
||||
= f.error_message_on :included_tax
|
||||
|
||||
.omega.four.columns
|
||||
= f.field_container :tax_rate_id do
|
||||
= f.label :tax_rate_id, t(:tax_rate)
|
||||
= select_tag :tax_rate_id, options_from_collection_for_select(Spree::TaxRate.all, :id, :name, @tax_rate_id), prompt: t(:remove_tax), class: 'select2 fullwidth'
|
||||
= f.error_message_on :tax_rate_id
|
||||
.omega.four.columns
|
||||
= f.field_container :tax_rate_id do
|
||||
= f.label :tax_rate_id, t(:tax_rate)
|
||||
= select_tag :tax_rate_id, options_from_collection_for_select(Spree::TaxRate.all, :id, :name, @tax_rate_id), prompt: t(:remove_tax), class: 'select2 fullwidth'
|
||||
= f.error_message_on :tax_rate_id
|
||||
|
||||
.row
|
||||
.alpha.omega.twelve.columns
|
||||
|
||||
@@ -9,20 +9,37 @@ module Spree
|
||||
before { controller_login_as_admin }
|
||||
|
||||
describe "index" do
|
||||
let!(:order) { create(:order) }
|
||||
let!(:order) { create(:completed_order_with_totals) }
|
||||
let!(:adjustment1) {
|
||||
create(:adjustment, originator_type: "Spree::ShippingMethod", order: order)
|
||||
create(:adjustment, originator_type: "Spree::ShippingMethod", order: order,
|
||||
adjustable: order.shipment)
|
||||
}
|
||||
let!(:adjustment2) {
|
||||
create(:adjustment, originator_type: "Spree::PaymentMethod", eligible: true, order: order)
|
||||
}
|
||||
let!(:adjustment3) {
|
||||
create(:adjustment, originator_type: "Spree::PaymentMethod", eligible: false, order: order)
|
||||
}
|
||||
let!(:adjustment3) { create(:adjustment, originator_type: "EnterpriseFee", order: order) }
|
||||
let!(:adjustment4) { create(:adjustment, originator_type: "EnterpriseFee", order: order) }
|
||||
let!(:adjustment5) { create(:adjustment, originator: nil, adjustable: order, order: order) }
|
||||
|
||||
it "loads all eligible adjustments" do
|
||||
it "displays eligible adjustments" do
|
||||
spree_get :index, order_id: order.number
|
||||
|
||||
expect(assigns(:collection)).to include adjustment1, adjustment3
|
||||
expect(assigns(:collection)).to_not include adjustment2
|
||||
expect(assigns(:collection)).to include adjustment1, adjustment2
|
||||
expect(assigns(:collection)).to_not include adjustment3
|
||||
end
|
||||
|
||||
it "displays admin adjustments" do
|
||||
spree_get :index, order_id: order.number
|
||||
|
||||
expect(assigns(:collection)).to include adjustment5
|
||||
end
|
||||
|
||||
it "does not display enterprise fee adjustments" do
|
||||
spree_get :index, order_id: order.number
|
||||
|
||||
expect(assigns(:collection)).to_not include adjustment4
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user