mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-30 06:31:16 +00:00
Merge branch 'master' into folklabs-producer-emails
This commit is contained in:
@@ -9,7 +9,7 @@ module Admin
|
||||
|
||||
def move_up
|
||||
EnterpriseGroup.with_isolation_level_serializable do
|
||||
@enterprise_group = EnterpriseGroup.find_by_permalink params[:enterprise_group_id]
|
||||
@enterprise_group = find_resource
|
||||
@enterprise_group.move_higher
|
||||
end
|
||||
redirect_to main_app.admin_enterprise_groups_path
|
||||
@@ -17,7 +17,7 @@ module Admin
|
||||
|
||||
def move_down
|
||||
EnterpriseGroup.with_isolation_level_serializable do
|
||||
@enterprise_group = EnterpriseGroup.find_by_permalink params[:enterprise_group_id]
|
||||
@enterprise_group = find_resource
|
||||
@enterprise_group.move_lower
|
||||
end
|
||||
redirect_to main_app.admin_enterprise_groups_path
|
||||
@@ -34,9 +34,11 @@ module Admin
|
||||
alias_method_chain :build_resource, :address
|
||||
|
||||
# Overriding method on Spree's resource controller,
|
||||
# so that resources are found using permalink
|
||||
# so that resources are found using permalink.
|
||||
# The ! version is important to raise a RecordNotFound error.
|
||||
def find_resource
|
||||
EnterpriseGroup.find_by_permalink(params[:id])
|
||||
permalink = params[:id] || params[:enterprise_group_id]
|
||||
EnterpriseGroup.find_by_permalink!(permalink)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -12,7 +12,7 @@ module Admin
|
||||
end
|
||||
|
||||
def load_enterprise
|
||||
@enterprise = Enterprise.find_by_permalink params[:enterprise_id]
|
||||
@enterprise = Enterprise.find_by_permalink! params[:enterprise_id]
|
||||
end
|
||||
|
||||
def load_properties
|
||||
|
||||
@@ -41,6 +41,18 @@ Spree::Admin::OrdersController.class_eval do
|
||||
respond_with(@order) { |format| format.html { redirect_to :back } }
|
||||
end
|
||||
|
||||
def invoice
|
||||
pdf = render_to_string pdf: "invoice-#{@order.number}.pdf", template: "spree/admin/orders/invoice", formats: [:html], encoding: "UTF-8"
|
||||
Spree::OrderMailer.invoice_email(@order.id, pdf).deliver
|
||||
flash[:success] = t(:invoice_email_sent)
|
||||
|
||||
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
|
||||
|
||||
@@ -21,4 +21,14 @@ Spree::OrderMailer.class_eval do
|
||||
:from => from_address,
|
||||
:subject => subject)
|
||||
end
|
||||
|
||||
def invoice_email(order, pdf)
|
||||
find_order(order) # Finds an order instance from an id
|
||||
attachments["invoice-#{@order.number}.pdf"] = pdf if pdf.present?
|
||||
subject = "#{Spree::Config[:site_name]} #{t(:invoice)} ##{@order.number}"
|
||||
mail(:to => @order.email,
|
||||
:from => from_address,
|
||||
:subject => subject,
|
||||
:reply_to => @order.distributor.email)
|
||||
end
|
||||
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], 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)
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
/ replace_contents "[data-hook='long_description']"
|
||||
%th Profile Info:
|
||||
%td= @enterprise.long_description.andand.html_safe
|
||||
@@ -1,10 +0,0 @@
|
||||
/ replace_contents "[data-hook='distributor-details']"
|
||||
%h2= distributor.name
|
||||
= distributor.distributor_info.andand.html_safe
|
||||
.next-collection-at
|
||||
-# Handle both checkout process and show order page
|
||||
- order_cycle = current_order_cycle || @order.andand.order_cycle
|
||||
- if order_cycle
|
||||
= order_cycle.pickup_time_for(distributor)
|
||||
- else
|
||||
= distributor.next_collection_at
|
||||
@@ -0,0 +1,3 @@
|
||||
/ insert_after "code[erb-loud]:contains('button_link_to t(:resend)')"
|
||||
- if @order.complete?
|
||||
%li= button_link_to t(:invoice), invoice_admin_order_url(@order), :method => :put, :icon => 'icon-email', :data => { :confirm => t(:are_you_sure) }
|
||||
@@ -0,0 +1,3 @@
|
||||
/ insert_after "code[erb-loud]:contains('button_link_to t(:edit)')"
|
||||
- if @order.complete?
|
||||
%li= button_link_to t(:print), print_admin_order_url(@order), :method => :get, :icon => 'icon-print', :target => "_blank"
|
||||
15
app/views/spree/admin/orders/invoice.html.haml
Normal file
15
app/views/spree/admin/orders/invoice.html.haml
Normal file
@@ -0,0 +1,15 @@
|
||||
= wicked_pdf_stylesheet_link_tag "mail/all"
|
||||
|
||||
|
||||
%table{:width => "100%"}
|
||||
%tbody
|
||||
%tr
|
||||
%td{ :align => "left" }
|
||||
= "Order ##{@order.number}"
|
||||
%td{ :align => "right" }
|
||||
- if @order.total_tax > 0
|
||||
= "TAX"
|
||||
= "INVOICE"
|
||||
|
||||
= render 'spree/order_mailer/order_summary'
|
||||
= render 'spree/order_mailer/payment'
|
||||
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/all"
|
||||
|
||||
|
||||
%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'
|
||||
15
app/views/spree/order_mailer/_signoff.html.haml
Normal file
15
app/views/spree/order_mailer/_signoff.html.haml
Normal file
@@ -0,0 +1,15 @@
|
||||
%br
|
||||
%p.callout
|
||||
Kind regards,
|
||||
%br
|
||||
#{@order.distributor.contact}
|
||||
%br
|
||||
%br
|
||||
= @order.distributor.name
|
||||
%br
|
||||
= @order.distributor.phone || ""
|
||||
%br
|
||||
%a{:href => "mailto:#{@order.distributor.email}", :target => "_blank"}
|
||||
= @order.distributor.email
|
||||
%br
|
||||
= @order.distributor.website || ""
|
||||
@@ -4,10 +4,10 @@
|
||||
%table.column{:align => "left"}
|
||||
%tr
|
||||
%td
|
||||
%h3
|
||||
%h3
|
||||
Hi #{@order.bill_address.firstname},
|
||||
%h4
|
||||
Thanks for shopping at
|
||||
Thanks for shopping at
|
||||
%strong= "#{@order.distributor.name}!"
|
||||
%table.column{:align => "left"}
|
||||
%tr
|
||||
@@ -17,31 +17,14 @@
|
||||
|
||||
%p
|
||||
%h4
|
||||
Order confirmation
|
||||
Order confirmation
|
||||
%strong ##{@order.number}
|
||||
%p
|
||||
Here are your order details from
|
||||
%strong= "#{@order.distributor.name}:"
|
||||
%strong= "#{@order.distributor.name}:"
|
||||
|
||||
= render 'order_summary'
|
||||
= render 'payment'
|
||||
= render 'shipping'
|
||||
= render 'special_instructions'
|
||||
|
||||
%br
|
||||
%p.callout
|
||||
Kind regards,
|
||||
%br
|
||||
#{@order.distributor.contact}
|
||||
%br
|
||||
%br
|
||||
= @order.distributor.name
|
||||
%br
|
||||
= @order.distributor.phone || ""
|
||||
%br
|
||||
%a{:href => "mailto:#{@order.distributor.email}", :target => "_blank"}
|
||||
= @order.distributor.email
|
||||
%br
|
||||
= @order.distributor.website || ""
|
||||
|
||||
|
||||
= render 'signoff'
|
||||
|
||||
10
app/views/spree/order_mailer/invoice_email.html.haml
Normal file
10
app/views/spree/order_mailer/invoice_email.html.haml
Normal file
@@ -0,0 +1,10 @@
|
||||
%table.social.white-bg{:width => "100%"}
|
||||
%tr
|
||||
%td
|
||||
%h3
|
||||
Hi #{@order.bill_address.firstname},
|
||||
%h4
|
||||
Please find attached an invoice for your recent order from
|
||||
%strong= "#{@order.distributor.name}"
|
||||
|
||||
= render 'signoff'
|
||||
Reference in New Issue
Block a user