mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-27 06:05:19 +00:00
Adding new route for printing an order to pdf
This commit is contained in:
@@ -49,6 +49,10 @@ Spree::Admin::OrdersController.class_eval do
|
||||
respond_with(@order) { |format| format.html { redirect_to edit_admin_order_path(@order) } }
|
||||
end
|
||||
|
||||
def print
|
||||
render pdf: "invoice-#{@order.number}", encoding: "UTF-8"
|
||||
end
|
||||
|
||||
def update_distribution_charge
|
||||
@order.update_distribution_charge!
|
||||
end
|
||||
|
||||
@@ -142,7 +142,7 @@ class AbilityDecorator
|
||||
def add_order_management_abilities(user)
|
||||
# Enterprise User can only access orders that they are a distributor for
|
||||
can [:index, :create], Spree::Order
|
||||
can [:read, :update, :fire, :resend, :invoice], Spree::Order do |order|
|
||||
can [:read, :update, :fire, :resend, :invoice, :print], Spree::Order do |order|
|
||||
# We allow editing orders with a nil distributor as this state occurs
|
||||
# during the order creation process from the admin backend
|
||||
order.distributor.nil? || user.enterprises.include?(order.distributor)
|
||||
|
||||
19
app/views/spree/admin/orders/print.html.haml
Normal file
19
app/views/spree/admin/orders/print.html.haml
Normal file
@@ -0,0 +1,19 @@
|
||||
= wicked_pdf_stylesheet_link_tag "mail/email"
|
||||
|
||||
|
||||
%table{:width => "100%"}
|
||||
%tbody
|
||||
%tr
|
||||
%td{ :align => "left" }
|
||||
%h4
|
||||
Order confirmation
|
||||
%strong ##{@order.number}
|
||||
%h5
|
||||
#{@order.bill_address.firstname} #{@order.bill_address.lastname}
|
||||
%strong= " <#{@order.email}>" if @order.email
|
||||
= @order.bill_address.phone if @order.bill_address.phone
|
||||
%h5= "Customer Code: #{@order.customer.code}"
|
||||
|
||||
= render 'spree/order_mailer/order_summary'
|
||||
= render 'spree/order_mailer/payment'
|
||||
= render 'spree/order_mailer/shipping'
|
||||
@@ -205,6 +205,7 @@ Spree::Core::Engine.routes.prepend do
|
||||
|
||||
resources :orders do
|
||||
put :invoice, on: :member
|
||||
get :print, on: :member
|
||||
get :managed, on: :collection
|
||||
end
|
||||
end
|
||||
|
||||
@@ -201,4 +201,39 @@ describe Spree::Admin::OrdersController do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#print" do
|
||||
let!(:user) { create(:user) }
|
||||
let!(:enterprise_user) { create(:user) }
|
||||
let!(:order) { create(:order_with_distributor, bill_address: create(:address), ship_address: create(:address)) }
|
||||
let!(:distributor) { order.distributor }
|
||||
let(:params) { { id: order.number } }
|
||||
|
||||
context "as a normal user" do
|
||||
before { controller.stub spree_current_user: user }
|
||||
|
||||
it "should prevent me from sending order invoices" do
|
||||
spree_get :print, params
|
||||
expect(response).to redirect_to spree.unauthorized_path
|
||||
end
|
||||
end
|
||||
|
||||
context "as an enterprise user" do
|
||||
context "which is not a manager of the distributor for an order" do
|
||||
before { controller.stub spree_current_user: user }
|
||||
it "should prevent me from sending order invoices" do
|
||||
spree_get :print, params
|
||||
expect(response).to redirect_to spree.unauthorized_path
|
||||
end
|
||||
end
|
||||
|
||||
context "which is a manager of the distributor for an order" do
|
||||
before { controller.stub spree_current_user: distributor.owner }
|
||||
it "should allow me to send order invoices" do
|
||||
spree_get :print, params
|
||||
expect(response).to render_template :print
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user