diff --git a/Gemfile b/Gemfile index d6d772203f..9c977995fe 100644 --- a/Gemfile +++ b/Gemfile @@ -78,7 +78,6 @@ group :test do end group :chili do - gem 'enterprises_distributor_info_rich_text_feature', path: 'lib/chili/enterprises_distributor_info_rich_text_feature' gem 'eaterprises_feature', path: 'lib/chili/eaterprises_feature' gem 'local_organics_feature', path: 'lib/chili/local_organics_feature' end diff --git a/Gemfile.lock b/Gemfile.lock index 82921527d5..11c366f984 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -107,13 +107,6 @@ PATH chili (~> 3.1) rails (~> 3.2.11) -PATH - remote: lib/chili/enterprises_distributor_info_rich_text_feature - specs: - enterprises_distributor_info_rich_text_feature (0.0.1) - chili (~> 3.1) - rails (~> 3.2.11) - PATH remote: lib/chili/local_organics_feature specs: @@ -479,7 +472,6 @@ DEPENDENCIES debugger-linecache deface! eaterprises_feature! - enterprises_distributor_info_rich_text_feature! factory_girl_rails faker geocoder diff --git a/app/assets/stylesheets/store/openfoodnetwork.css.scss b/app/assets/stylesheets/store/openfoodnetwork.css.scss index 646edd5510..f98642cc22 100644 --- a/app/assets/stylesheets/store/openfoodnetwork.css.scss +++ b/app/assets/stylesheets/store/openfoodnetwork.css.scss @@ -372,3 +372,10 @@ div#eft-payment-alert { display: none; } + +/* Distributor details */ +.distributor-details .next-collection-at { + font-size: 20px; + font-weight: bold; + color: #de790c; +} diff --git a/app/controllers/admin/order_cycles_controller.rb b/app/controllers/admin/order_cycles_controller.rb index 26627caeed..46273d0eff 100644 --- a/app/controllers/admin/order_cycles_controller.rb +++ b/app/controllers/admin/order_cycles_controller.rb @@ -72,7 +72,8 @@ module Admin def collection ocs = OrderCycle.managed_by(spree_current_user) - ocs.soonest_closing + + ocs.undated + + ocs.soonest_closing + ocs.soonest_opening + ocs.most_recently_closed end diff --git a/app/controllers/spree/admin/reports_controller_decorator.rb b/app/controllers/spree/admin/reports_controller_decorator.rb index bae1f36374..31ea232976 100644 --- a/app/controllers/spree/admin/reports_controller_decorator.rb +++ b/app/controllers/spree/admin/reports_controller_decorator.rb @@ -50,6 +50,8 @@ Spree::Admin::ReportsController.class_eval do @report_types = REPORT_TYPES[:customers] @report_type = params[:report_type] @report = OpenFoodNetwork::CustomersReport.new spree_current_user, params + + render_report(@report.header, @report.table, params[:csv], "customers.csv") end def orders_and_distributors @@ -557,6 +559,7 @@ Spree::Admin::ReportsController.class_eval do @report = OpenFoodNetwork::ProductsAndInventoryReport.new spree_current_user, params #@table = @report.table #@header = @report.header + render_report(@report.header, @report.table, params[:csv], "products_and_inventory.csv") end def render_report (header, table, create_csv, csv_file_name) diff --git a/app/helpers/order_cycles_helper.rb b/app/helpers/order_cycles_helper.rb index af5f16e10c..d20c667da7 100644 --- a/app/helpers/order_cycles_helper.rb +++ b/app/helpers/order_cycles_helper.rb @@ -18,7 +18,9 @@ module OrderCyclesHelper end def order_cycle_status_class(order_cycle) - if order_cycle.upcoming? + if order_cycle.undated? + 'undated' + elsif order_cycle.upcoming? 'upcoming' elsif order_cycle.open? 'open' diff --git a/app/mailers/spree/order_mailer_decorator.rb b/app/mailers/spree/order_mailer_decorator.rb index 1ce563ad56..03f9fcdfaf 100644 --- a/app/mailers/spree/order_mailer_decorator.rb +++ b/app/mailers/spree/order_mailer_decorator.rb @@ -1,3 +1,13 @@ Spree::OrderMailer.class_eval do helper HtmlHelper + helper CheckoutHelper + def confirm_email(order, resend = false) + find_order(order) + subject = (resend ? "[#{t(:resend).upcase}] " : '') + subject += "#{Spree::Config[:site_name]} #{t('order_mailer.confirm_email.subject')} ##{@order.number}" + mail(:to => @order.email, + :from => @order.distributor.email || from_address, + :subject => subject, + :cc => "orders@openfoodnetwork.org") + end end diff --git a/app/models/order_cycle.rb b/app/models/order_cycle.rb index 362f1eb05a..187a93e0ef 100644 --- a/app/models/order_cycle.rb +++ b/app/models/order_cycle.rb @@ -16,6 +16,7 @@ class OrderCycle < ActiveRecord::Base scope :inactive, lambda { where('order_cycles.orders_open_at > ? OR order_cycles.orders_close_at < ?', Time.now, Time.now) } scope :upcoming, lambda { where('order_cycles.orders_open_at > ?', Time.now) } scope :closed, lambda { where('order_cycles.orders_close_at < ?', Time.now) } + scope :undated, where(orders_open_at: nil, orders_close_at: nil) scope :distributing_product, lambda { |product| joins(:exchanges => :variants). @@ -111,16 +112,21 @@ class OrderCycle < ActiveRecord::Base self.variants.include? variant end + def undated? + self.orders_open_at.nil? && self.orders_close_at.nil? + end + def upcoming? - Time.now < self.orders_open_at + self.orders_open_at && Time.now < self.orders_open_at end def open? - Time.now > self.orders_open_at && Time.now < self.orders_close_at + self.orders_open_at && self.orders_close_at && + Time.now > self.orders_open_at && Time.now < self.orders_close_at end def closed? - Time.now > self.orders_close_at + self.orders_close_at && Time.now > self.orders_close_at end def exchange_for_distributor(distributor) @@ -131,6 +137,10 @@ class OrderCycle < ActiveRecord::Base exchange_for_distributor(distributor).andand.pickup_time || distributor.next_collection_at end + def pickup_instructions_for(distributor) + exchange_for_distributor(distributor).andand.pickup_instructions + end + # -- Fees def create_adjustments_for(line_item) diff --git a/app/models/spree/ability_decorator.rb b/app/models/spree/ability_decorator.rb index ed018c4fee..c6407c1f98 100644 --- a/app/models/spree/ability_decorator.rb +++ b/app/models/spree/ability_decorator.rb @@ -14,7 +14,7 @@ class AbilityDecorator user.enterprises.include? product.supplier end - can [:admin, :index, :read, :create, :edit, :update, :search], Spree::Variant + can [:admin, :index, :read, :create, :edit, :update, :search, :destroy], Spree::Variant can [:admin, :index, :read, :create, :edit], Spree::ProductProperty can [:admin, :index, :read, :create, :edit], Spree::Image diff --git a/app/overrides/add_bulk_edit_tab_to_products_admin_sub_menu.rb b/app/overrides/add_bulk_edit_tab_to_products_admin_sub_menu.rb index f6b6f94e9f..42d0120538 100644 --- a/app/overrides/add_bulk_edit_tab_to_products_admin_sub_menu.rb +++ b/app/overrides/add_bulk_edit_tab_to_products_admin_sub_menu.rb @@ -1,4 +1,4 @@ Deface::Override.new(:virtual_path => "spree/admin/shared/_product_sub_menu", :name => "add_bulk_edit_tab_to_products_admin_sub_menu", :insert_bottom => "[data-hook='admin_product_sub_tabs']", - :text => "<%= tab :bulk_product_edit, :url => bulk_edit_admin_products_path %>") \ No newline at end of file + :text => "<%= tab :bulk_product_edit, :url => bulk_edit_admin_products_path %>") diff --git a/lib/chili/enterprises_distributor_info_rich_text_feature/app/overrides/admin/enterprises/_form/add_distributor_info.html.haml.deface b/app/overrides/admin/enterprises/_form/add_distributor_info.html.haml.deface similarity index 100% rename from lib/chili/enterprises_distributor_info_rich_text_feature/app/overrides/admin/enterprises/_form/add_distributor_info.html.haml.deface rename to app/overrides/admin/enterprises/_form/add_distributor_info.html.haml.deface diff --git a/lib/chili/enterprises_distributor_info_rich_text_feature/app/overrides/admin/enterprises/_form/rename_extended_description.html.haml.deface b/app/overrides/admin/enterprises/_form/rename_extended_description.html.haml.deface similarity index 100% rename from lib/chili/enterprises_distributor_info_rich_text_feature/app/overrides/admin/enterprises/_form/rename_extended_description.html.haml.deface rename to app/overrides/admin/enterprises/_form/rename_extended_description.html.haml.deface diff --git a/lib/chili/enterprises_distributor_info_rich_text_feature/app/overrides/admin/enterprises/show/add_distributor_info.html.haml.deface b/app/overrides/admin/enterprises/show/add_distributor_info.html.haml.deface similarity index 100% rename from lib/chili/enterprises_distributor_info_rich_text_feature/app/overrides/admin/enterprises/show/add_distributor_info.html.haml.deface rename to app/overrides/admin/enterprises/show/add_distributor_info.html.haml.deface diff --git a/lib/chili/enterprises_distributor_info_rich_text_feature/app/overrides/admin/enterprises/show/rename_extended_description.html.haml.deface b/app/overrides/admin/enterprises/show/rename_extended_description.html.haml.deface similarity index 100% rename from lib/chili/enterprises_distributor_info_rich_text_feature/app/overrides/admin/enterprises/show/rename_extended_description.html.haml.deface rename to app/overrides/admin/enterprises/show/rename_extended_description.html.haml.deface diff --git a/lib/chili/enterprises_distributor_info_rich_text_feature/app/overrides/enterprises/_distributor_details/rich_text.html.haml.deface b/app/overrides/enterprises/_distributor_details/rich_text.html.haml.deface similarity index 100% rename from lib/chili/enterprises_distributor_info_rich_text_feature/app/overrides/enterprises/_distributor_details/rich_text.html.haml.deface rename to app/overrides/enterprises/_distributor_details/rich_text.html.haml.deface diff --git a/app/views/layouts/_bugherd_script.html.haml b/app/views/layouts/_bugherd_script.html.haml index f66f865137..326c48da00 100644 --- a/app/views/layouts/_bugherd_script.html.haml +++ b/app/views/layouts/_bugherd_script.html.haml @@ -1,4 +1,4 @@ -- if Rails.env.staging? or Rails.env.production? +- if Rails.env.staging? :javascript (function (d, t) { var bh = d.createElement(t), s = d.getElementsByTagName(t)[0]; @@ -6,3 +6,12 @@ bh.src = '//www.bugherd.com/sidebarv2.js?apikey=4ftxjbgwx7y6ssykayr04w'; s.parentNode.insertBefore(bh, s); })(document, 'script'); + +- elsif Rails.env.production? + :javascript + (function (d, t) { + var bh = d.createElement(t), s = d.getElementsByTagName(t)[0]; + bh.type = 'text/javascript'; + bh.src = '//www.bugherd.com/sidebarv2.js?apikey=xro3uv55objies58o2wrua'; + s.parentNode.insertBefore(bh, s); + })(document, 'script'); diff --git a/app/views/spree/admin/reports/products_and_inventory.html.haml b/app/views/spree/admin/reports/products_and_inventory.html.haml index 23228ffb71..93859d0c58 100644 --- a/app/views/spree/admin/reports/products_and_inventory.html.haml +++ b/app/views/spree/admin/reports/products_and_inventory.html.haml @@ -20,7 +20,7 @@ %br = label_tag nil, "Report Type: " - = select_tag(:report_type, options_for_select(@report_types, @report_type)) + = select_tag(:report_type, options_for_select(@report_types, params[:report_type])) %br %br diff --git a/app/views/spree/admin/shared/_tabs.html.erb b/app/views/spree/admin/shared/_tabs.html.erb index fef894389f..ab66dbf1de 100644 --- a/app/views/spree/admin/shared/_tabs.html.erb +++ b/app/views/spree/admin/shared/_tabs.html.erb @@ -1,5 +1,5 @@ <%= tab :overview, :route => :admin, :icon => 'icon-dashboard' %> <%= tab :orders, :payments, :creditcard_payments, :shipments, :credit_cards, :return_authorizations, :url => admin_orders_path('q[s]' => 'completed_at desc'), :icon => 'icon-shopping-cart' %> -<%= tab :products , :option_types, :properties, :prototypes, :variants, :product_properties, :taxons, :icon => 'icon-th-large' %> +<%= tab :products , :option_types, :properties, :prototypes, :variants, :product_properties, :taxons, :url => bulk_edit_admin_products_path, :icon => 'icon-th-large' %> <%= tab :reports, :icon => 'icon-file' %> <%= tab :configurations, :general_settings, :mail_methods, :tax_categories, :zones, :states, :payment_methods, :inventory_settings, :taxonomies, :shipping_methods, :trackers, :label => 'configuration', :icon => 'icon-wrench', :url => edit_admin_general_settings_path %> diff --git a/app/views/spree/order_mailer/confirm_email.text.erb b/app/views/spree/order_mailer/confirm_email.text.erb index 3277ccaf00..e72fe48433 100644 --- a/app/views/spree/order_mailer/confirm_email.text.erb +++ b/app/views/spree/order_mailer/confirm_email.text.erb @@ -5,37 +5,40 @@ Please review and retain the following order information for your records. ============================================================ Order Summary ============================================================ -Order for: <%= @order.bill_address.full_name %> +Order for: <%= @order.bill_address.full_name %> <% @order.line_items.each do |item| %> - <%= item.variant.sku %> <%= raw(item.variant.product.name) %> <%= raw(item.variant.options_text) -%> (<%=item.quantity%>) @ <%= item.single_money %> = <%= item.display_amount %> + <%= item.variant.sku %> <%= raw(item.variant.product.supplier.name) %> <%= raw(item.variant.product.name) %> <%= raw(item.variant.options_text) -%> (<%=item.quantity%>) @ <%= item.single_money %> = <%= item.display_amount %> <% end %> ============================================================ Subtotal: <%= @order.display_item_total %> -<% @order.adjustments.each do |adjustment| %> +<% checkout_adjustments_for_summary(@order).each do |adjustment| %> <%= raw(adjustment.label) %> <%= adjustment.display_amount %> <% end %> Order Total: <%= @order.display_total %> -<% if @order.payments.first.payment_method.name.include? "EFT" %> +<% if @order.payments.first.andand.payment_method.andand.name.andand.include? "EFT" %> ============================================================ Payment Details ============================================================ -<%= @order.payments.first.payment_method.description.html_safe %> +<%= @order.payments.first.andand.payment_method.andand.description.andand.html_safe %> <% end %> ============================================================ Collection / Delivery Details ============================================================ -Address: - <%= @order.distributor.name %> - <% address = @order.distributor.address %> - <%= address.address1 %> <%= ",\n #{address.address2}" unless address.address2.blank? %> - <%= [address.city, address.state_text, address.zipcode, address.country.name].compact.join ', ' %> -Collection time: - <%= @order.distributor.next_collection_at %> -Contact: - <%= @order.distributor.contact %> - <%= "Phone: #{@order.distributor.phone}" %> - <%= "Email: #{@order.distributor.email}" %> +<%= raw strip_html @order.distributor.distributor_info %> -Thank you for your business. +<% if @order.order_cycle %> +<%= @order.order_cycle.pickup_time_for(@order.distributor) %> +<%= @order.order_cycle.pickup_instructions_for(@order.distributor) %> +<% else %> +<%= @order.distributor.next_collection_at %> +<% end %> + +Thanks for your support. + +<%= @order.distributor.contact %>, +<%= @order.distributor.name %> +<%= @order.distributor.phone %> +<%= @order.distributor.email %> +<%= @order.distributor.website %> diff --git a/config/initializers/spree.rb b/config/initializers/spree.rb index bd106caf5a..0460865c7e 100644 --- a/config/initializers/spree.rb +++ b/config/initializers/spree.rb @@ -22,6 +22,7 @@ Spree.config do |config| # -- spree_paypal_express # Auto-capture payments. Without this option, payments must be manually captured in the paypal interface. config.auto_capture = true + #config.override_actionmailer_config = false end diff --git a/lib/chili/enterprises_distributor_info_rich_text_feature/.gitignore b/lib/chili/enterprises_distributor_info_rich_text_feature/.gitignore deleted file mode 100644 index 8619e09c5a..0000000000 --- a/lib/chili/enterprises_distributor_info_rich_text_feature/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -.bundle/ -log/*.log -pkg/ diff --git a/lib/chili/enterprises_distributor_info_rich_text_feature/README.rdoc b/lib/chili/enterprises_distributor_info_rich_text_feature/README.rdoc deleted file mode 100644 index fd60a25911..0000000000 --- a/lib/chili/enterprises_distributor_info_rich_text_feature/README.rdoc +++ /dev/null @@ -1,3 +0,0 @@ -= EnterprisesDistributorInfoRichTextFeature - -This project rocks and uses MIT-LICENSE. \ No newline at end of file diff --git a/lib/chili/enterprises_distributor_info_rich_text_feature/app/assets/images/enterprises_distributor_info_rich_text_feature/.gitkeep b/lib/chili/enterprises_distributor_info_rich_text_feature/app/assets/images/enterprises_distributor_info_rich_text_feature/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/chili/enterprises_distributor_info_rich_text_feature/app/assets/javascripts/enterprises_distributor_info_rich_text_feature/application.js b/lib/chili/enterprises_distributor_info_rich_text_feature/app/assets/javascripts/enterprises_distributor_info_rich_text_feature/application.js deleted file mode 100644 index 15ebed9422..0000000000 --- a/lib/chili/enterprises_distributor_info_rich_text_feature/app/assets/javascripts/enterprises_distributor_info_rich_text_feature/application.js +++ /dev/null @@ -1,13 +0,0 @@ -// This is a manifest file that'll be compiled into application.js, which will include all the files -// listed below. -// -// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, -// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. -// -// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the -// the compiled file. -// -// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD -// GO AFTER THE REQUIRES BELOW. -// -//= require_tree . diff --git a/lib/chili/enterprises_distributor_info_rich_text_feature/app/assets/stylesheets/enterprises_distributor_info_rich_text_feature/application.css b/lib/chili/enterprises_distributor_info_rich_text_feature/app/assets/stylesheets/enterprises_distributor_info_rich_text_feature/application.css deleted file mode 100644 index 3192ec897b..0000000000 --- a/lib/chili/enterprises_distributor_info_rich_text_feature/app/assets/stylesheets/enterprises_distributor_info_rich_text_feature/application.css +++ /dev/null @@ -1,13 +0,0 @@ -/* - * This is a manifest file that'll be compiled into application.css, which will include all the files - * listed below. - * - * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, - * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. - * - * You're free to add application-wide styles to this file and they'll appear at the top of the - * compiled file, but it's generally better to create a new file per style scope. - * - *= require_self - *= require_tree . - */ diff --git a/lib/chili/enterprises_distributor_info_rich_text_feature/app/assets/stylesheets/enterprises_distributor_info_rich_text_feature/feature.css b/lib/chili/enterprises_distributor_info_rich_text_feature/app/assets/stylesheets/enterprises_distributor_info_rich_text_feature/feature.css deleted file mode 100644 index e8eab603e8..0000000000 --- a/lib/chili/enterprises_distributor_info_rich_text_feature/app/assets/stylesheets/enterprises_distributor_info_rich_text_feature/feature.css +++ /dev/null @@ -1,5 +0,0 @@ -.distributor-details .next-collection-at { - font-size: 20px; - font-weight: bold; - color: #de790c; -} diff --git a/lib/chili/enterprises_distributor_info_rich_text_feature/app/overrides/spree/layouts/spree_application/assets.html.erb.deface b/lib/chili/enterprises_distributor_info_rich_text_feature/app/overrides/spree/layouts/spree_application/assets.html.erb.deface deleted file mode 100644 index 7a43bc4978..0000000000 --- a/lib/chili/enterprises_distributor_info_rich_text_feature/app/overrides/spree/layouts/spree_application/assets.html.erb.deface +++ /dev/null @@ -1,2 +0,0 @@ - -<%= stylesheet_link_tag 'enterprises_distributor_info_rich_text_feature/application' %> diff --git a/lib/chili/enterprises_distributor_info_rich_text_feature/app/views/spree/order_mailer/confirm_email_with_distributor_info.text.erb b/lib/chili/enterprises_distributor_info_rich_text_feature/app/views/spree/order_mailer/confirm_email_with_distributor_info.text.erb deleted file mode 100644 index c47cdd7b7b..0000000000 --- a/lib/chili/enterprises_distributor_info_rich_text_feature/app/views/spree/order_mailer/confirm_email_with_distributor_info.text.erb +++ /dev/null @@ -1,40 +0,0 @@ -Dear <%= @order.bill_address.firstname %>, - -Please review and retain the following order information for your records. - -============================================================ -Order Summary -============================================================ -Order for: <%= @order.bill_address.full_name %> -<% @order.line_items.each do |item| %> - <%= item.variant.sku %> <%= raw(item.variant.product.name) %> <%= raw(item.variant.options_text) -%> (<%=item.quantity%>) @ <%= item.single_money %> = <%= item.display_amount %> -<% end %> -============================================================ -Subtotal: <%= @order.display_item_total %> -<% checkout_adjustments_for_summary(@order).each do |adjustment| %> - <%= raw(adjustment.label) %> <%= adjustment.display_amount %> -<% end %> -Order Total: <%= @order.display_total %> - -<% if @order.payments.first.payment_method.name.include? "EFT" %> -============================================================ -Payment Details -============================================================ -<%= @order.payments.first.payment_method.description.html_safe %> - -<% end %> -============================================================ -Collection / Delivery Details -============================================================ -<%= raw strip_html @order.distributor.distributor_info %> -<% if @order.order_cycle %> -<%= @order.order_cycle.pickup_time_for(@order.distributor) %> -<% else %> -<%= @order.distributor.next_collection_at %> -<% end %> - - -Thanks for your support. - -<%= @order.distributor.contact %>, -<%= @order.distributor.name %> diff --git a/lib/chili/enterprises_distributor_info_rich_text_feature/config/routes.rb b/lib/chili/enterprises_distributor_info_rich_text_feature/config/routes.rb deleted file mode 100644 index 910ef99eca..0000000000 --- a/lib/chili/enterprises_distributor_info_rich_text_feature/config/routes.rb +++ /dev/null @@ -1,3 +0,0 @@ -EnterprisesDistributorInfoRichTextFeature::Engine.automount! -EnterprisesDistributorInfoRichTextFeature::Engine.routes.draw do -end diff --git a/lib/chili/enterprises_distributor_info_rich_text_feature/db/migrate/20130426022945_add_distributor_info_to_enterprises.rb b/lib/chili/enterprises_distributor_info_rich_text_feature/db/migrate/20130426022945_add_distributor_info_to_enterprises.rb deleted file mode 100644 index 7342726a92..0000000000 --- a/lib/chili/enterprises_distributor_info_rich_text_feature/db/migrate/20130426022945_add_distributor_info_to_enterprises.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddDistributorInfoToEnterprises < ActiveRecord::Migration - def change - add_column :enterprises, :distributor_info, :text - end -end diff --git a/lib/chili/enterprises_distributor_info_rich_text_feature/enterprises_distributor_info_rich_text_feature.gemspec b/lib/chili/enterprises_distributor_info_rich_text_feature/enterprises_distributor_info_rich_text_feature.gemspec deleted file mode 100644 index 1e230928b9..0000000000 --- a/lib/chili/enterprises_distributor_info_rich_text_feature/enterprises_distributor_info_rich_text_feature.gemspec +++ /dev/null @@ -1,22 +0,0 @@ -$:.push File.expand_path("../lib", __FILE__) - -# Maintain your gem's version: -require "enterprises_distributor_info_rich_text_feature/version" - -# Describe your gem and declare its dependencies: -Gem::Specification.new do |s| - s.name = "enterprises_distributor_info_rich_text_feature" - s.version = EnterprisesDistributorInfoRichTextFeature::VERSION - s.authors = ["Rohan Mitchell"] - s.email = ["rohan@rohanmitchell.com"] - s.homepage = "" - s.summary = "Summary of EnterprisesDistributorInfoRichTextFeature." - s.description = "Description of EnterprisesDistributorInfoRichTextFeature." - - s.files = Dir["{app,config,db,lib}/**/*"] + ["README.rdoc"] - - s.add_dependency "rails", "~> 3.2.11" - s.add_dependency 'chili', '~> 3.1' - - s.add_development_dependency "sqlite3" -end diff --git a/lib/chili/enterprises_distributor_info_rich_text_feature/lib/enterprises_distributor_info_rich_text_feature.rb b/lib/chili/enterprises_distributor_info_rich_text_feature/lib/enterprises_distributor_info_rich_text_feature.rb deleted file mode 100644 index c8cc1e8333..0000000000 --- a/lib/chili/enterprises_distributor_info_rich_text_feature/lib/enterprises_distributor_info_rich_text_feature.rb +++ /dev/null @@ -1,7 +0,0 @@ -require "chili" -require "enterprises_distributor_info_rich_text_feature/engine" - -module EnterprisesDistributorInfoRichTextFeature - extend Chili::Base - active_if { OpenFoodNetwork::FeatureToggle.enabled? :enterprises_distributor_info_rich_text } -end diff --git a/lib/chili/enterprises_distributor_info_rich_text_feature/lib/enterprises_distributor_info_rich_text_feature/engine.rb b/lib/chili/enterprises_distributor_info_rich_text_feature/lib/enterprises_distributor_info_rich_text_feature/engine.rb deleted file mode 100644 index 807aee52d0..0000000000 --- a/lib/chili/enterprises_distributor_info_rich_text_feature/lib/enterprises_distributor_info_rich_text_feature/engine.rb +++ /dev/null @@ -1,23 +0,0 @@ -require_relative '../../../../open_food_network/feature_toggle' - -module EnterprisesDistributorInfoRichTextFeature - class Engine < ::Rails::Engine - isolate_namespace EnterprisesDistributorInfoRichTextFeature - - initializer 'enterprises_distributor_info_rich_text_feature.mailer', :after => :load_config_initializers do |app| - if OpenFoodNetwork::FeatureToggle.enabled? :enterprises_distributor_info_rich_text - ::Spree::OrderMailer.class_eval do - helper CheckoutHelper - - def confirm_email(order, resend = false) - find_order(order) - subject = (resend ? "[#{t(:resend).upcase}] " : '') - subject += "#{Spree::Config[:site_name]} #{t('order_mailer.confirm_email.subject')} ##{@order.number}" - mail(:to => @order.email, :from => from_address, :subject => subject, - :template_name => 'confirm_email_with_distributor_info') - end - end - end - end - end -end diff --git a/lib/chili/enterprises_distributor_info_rich_text_feature/lib/enterprises_distributor_info_rich_text_feature/version.rb b/lib/chili/enterprises_distributor_info_rich_text_feature/lib/enterprises_distributor_info_rich_text_feature/version.rb deleted file mode 100644 index f413fbd728..0000000000 --- a/lib/chili/enterprises_distributor_info_rich_text_feature/lib/enterprises_distributor_info_rich_text_feature/version.rb +++ /dev/null @@ -1,3 +0,0 @@ -module EnterprisesDistributorInfoRichTextFeature - VERSION = "0.0.1" -end diff --git a/lib/chili/enterprises_distributor_info_rich_text_feature/lib/generators/enterprises_distributor_info_rich_text_feature_generator.rb b/lib/chili/enterprises_distributor_info_rich_text_feature/lib/generators/enterprises_distributor_info_rich_text_feature_generator.rb deleted file mode 100644 index 9124250abe..0000000000 --- a/lib/chili/enterprises_distributor_info_rich_text_feature/lib/generators/enterprises_distributor_info_rich_text_feature_generator.rb +++ /dev/null @@ -1,3 +0,0 @@ -class EnterprisesDistributorInfoRichTextFeatureGenerator < Rails::Generators::Base - include Chili::GeneratorProxy -end diff --git a/lib/open_food_network/products_and_inventory_report.rb b/lib/open_food_network/products_and_inventory_report.rb index 1dfc874906..2e6260f82f 100644 --- a/lib/open_food_network/products_and_inventory_report.rb +++ b/lib/open_food_network/products_and_inventory_report.rb @@ -8,17 +8,29 @@ module OpenFoodNetwork end def header - ["Supplier", "Product", "SKU", "Variant", "On Hand", "Price"] + [ + "Supplier", + "Producer Suburb", + "Product", + "Product Properties", + "Variant Value", + "Price", + "Group Buy Unit Quantity", + "Amount" + ] end def table variants.map do |variant| [variant.product.supplier.name, - variant.product.name, - variant.sku, - variant.options_text, - variant.count_on_hand, - variant.price] + variant.product.supplier.address.city, + variant.product.name, + variant.product.properties.map(&:name).join(", "), + variant.options_text, + variant.price, + variant.product.group_buy_unit_size, + "" + ] end end diff --git a/spec/controllers/spree/admin/reports_controller_spec.rb b/spec/controllers/spree/admin/reports_controller_spec.rb index af4268a8e0..64b4e27e2b 100644 --- a/spec/controllers/spree/admin/reports_controller_spec.rb +++ b/spec/controllers/spree/admin/reports_controller_spec.rb @@ -190,6 +190,8 @@ describe Spree::Admin::ReportsController do OpenFoodNetwork::ProductsAndInventoryReport.should_receive(:new) .with(user, {"test"=>"foo", "controller"=>"spree/admin/reports", "action"=>"products_and_inventory"}) .and_return(report = double(:report)) + report.stub(:header).and_return [] + report.stub(:table).and_return [] spree_get :products_and_inventory, :test => "foo" assigns(:report).should == report end @@ -236,6 +238,8 @@ describe Spree::Admin::ReportsController do OpenFoodNetwork::CustomersReport.should_receive(:new) .with(user, {"test"=>"foo", "controller"=>"spree/admin/reports", "action"=>"customers"}) .and_return(report = double(:report)) + report.stub(:header).and_return [] + report.stub(:table).and_return [] spree_get :customers, :test => "foo" assigns(:report).should == report end diff --git a/spec/features/admin/order_cycles_spec.rb b/spec/features/admin/order_cycles_spec.rb index 34a8e72c85..4e6564756c 100644 --- a/spec/features/admin/order_cycles_spec.rb +++ b/spec/features/admin/order_cycles_spec.rb @@ -29,6 +29,8 @@ feature %q{ oc5 = create(:simple_order_cycle, name: '5', orders_open_at: 1.month.ago, orders_close_at: 2.weeks.ago) oc1 = create(:order_cycle, name: '1') + oc0 = create(:simple_order_cycle, name: '0', + orders_open_at: nil, orders_close_at: nil) # When I go to the admin order cycles page login_to_admin_section @@ -36,9 +38,10 @@ feature %q{ # Then the order cycles should be ordered correctly page.all('#listing_order_cycles tr td:first-child').map(&:text).should == - ['1', '2', '3', '4', '5', '6'] + ['0', '1', '2', '3', '4', '5', '6'] # And the rows should have the correct classes + page.should have_selector "#listing_order_cycles tr.order-cycle-#{oc0.id}.undated" page.should have_selector "#listing_order_cycles tr.order-cycle-#{oc1.id}.open" page.should have_selector "#listing_order_cycles tr.order-cycle-#{oc2.id}.open" page.should have_selector "#listing_order_cycles tr.order-cycle-#{oc3.id}.upcoming" @@ -47,7 +50,8 @@ feature %q{ page.should have_selector "#listing_order_cycles tr.order-cycle-#{oc6.id}.closed" # And I should see all the details for an order cycle - within('table#listing_order_cycles tbody tr:first-child') do + # (the table includes a hidden field between each row, making this nth-child(3) instead of 2) + within('table#listing_order_cycles tbody tr:nth-child(3)') do # Then I should see the basic fields page.should have_selector 'a', text: oc1.name diff --git a/spec/features/admin/products_spec.rb b/spec/features/admin/products_spec.rb index 646ed70346..e472311223 100644 --- a/spec/features/admin/products_spec.rb +++ b/spec/features/admin/products_spec.rb @@ -104,6 +104,7 @@ feature %q{ product = create(:simple_product, supplier: @supplier2) click_link 'Products' + within('#sub_nav') { click_link 'Products' } click_link product.name within('#sidebar') { click_link 'Product Distributions' } diff --git a/spec/features/admin/reports_spec.rb b/spec/features/admin/reports_spec.rb index 1b3a2055e9..8f59e40d00 100644 --- a/spec/features/admin/reports_spec.rb +++ b/spec/features/admin/reports_spec.rb @@ -143,13 +143,12 @@ feature %q{ table = rows.map { |r| r.all("th,td").map { |c| c.text.strip } } table.sort.should == [ - ["Supplier", "Product", "SKU", "Variant", "On Hand", "Price"], - [product_1.supplier.name, "Product Name", variant_1.sku, "Size: Test", "10", "100.0"], - [product_1.supplier.name, "Product Name", variant_2.sku, "Size: S", "20", "80.0"], - [product_2.supplier.name, "Product 2", product_2.master.sku, "", "9", "99.0"] + ["Supplier", "Producer Suburb", "Product", "Product Properties", "Variant Value", "Price", "Group Buy Unit Quantity", "Amount"], + [product_1.supplier.name, product_1.supplier.address.city, "Product Name", product_1.properties.join(", "), "Size: Test", "100.0", product_1.group_buy_unit_size.to_s, ""], + [product_1.supplier.name, product_1.supplier.address.city, "Product Name", product_1.properties.join(", "), "Size: S", "80.0", product_1.group_buy_unit_size.to_s, ""], + [product_2.supplier.name, product_1.supplier.address.city, "Product 2", product_1.properties.join(", "), "", "99.0", product_1.group_buy_unit_size.to_s, ""] ].sort end end - end diff --git a/spec/features/chili/enterprises_distributor_info_rich_text_feature_spec.rb b/spec/features/chili/enterprises_distributor_info_rich_text_feature_spec.rb index b0c985d423..a8c6c6c541 100644 --- a/spec/features/chili/enterprises_distributor_info_rich_text_feature_spec.rb +++ b/spec/features/chili/enterprises_distributor_info_rich_text_feature_spec.rb @@ -10,9 +10,16 @@ feature "enterprises distributor info as rich text" do enterprises_distributor_info_rich_text: true}) + ActionMailer::Base.delivery_method = :test + ActionMailer::Base.perform_deliveries = true + ActionMailer::Base.deliveries = [] # The deployment is not set to local_organics on Rails init, so these + # # initializers won't run. Re-call them now that the deployment is set. - EnterprisesDistributorInfoRichTextFeature::Engine.initializers.each &:run + end + + after do + ActionMailer::Base.deliveries.clear end diff --git a/spec/features/consumer/checkout_spec.rb b/spec/features/consumer/checkout_spec.rb index 3585ff6864..98cafcfdac 100644 --- a/spec/features/consumer/checkout_spec.rb +++ b/spec/features/consumer/checkout_spec.rb @@ -348,7 +348,7 @@ feature %q{ # -- Checkout: Email email = ActionMailer::Base.deliveries.last - email.body.should =~ /Distribution \$12.00/ + email.body.should =~ /Distribution[\s+]\$12.00/ end scenario "buying a product from an order cycle", :js => true do @@ -414,7 +414,8 @@ feature %q{ # -- Checkout: Email email = ActionMailer::Base.deliveries.last - email.body.should =~ /Distribution \$54.00/ + email.from.include?(@distributor_oc.email).should == true + email.body.should =~ /Distribution[\s+]\$54.00/ end scenario "when I have past orders, it fills in my address", :js => true do @@ -497,7 +498,7 @@ feature %q{ # -- Checkout: Email email = ActionMailer::Base.deliveries.last - email.body.should =~ /Distribution \$54.00/ + email.body.should =~ /Distribution[\s+]\$54.00/ end diff --git a/spec/helpers/order_cycles_helper_spec.rb b/spec/helpers/order_cycles_helper_spec.rb index df5c11982d..45eab95396 100644 --- a/spec/helpers/order_cycles_helper_spec.rb +++ b/spec/helpers/order_cycles_helper_spec.rb @@ -32,4 +32,5 @@ describe OrderCyclesHelper do helper.stub!(:current_distributor).and_return d helper.pickup_time.should == "turtles" end + end diff --git a/spec/lib/open_food_network/products_and_inventory_report_spec.rb b/spec/lib/open_food_network/products_and_inventory_report_spec.rb index 514dfd0ac1..c65d7bcae0 100644 --- a/spec/lib/open_food_network/products_and_inventory_report_spec.rb +++ b/spec/lib/open_food_network/products_and_inventory_report_spec.rb @@ -13,24 +13,40 @@ module OpenFoodNetwork end it "Should return headers" do - subject.header.should == ["Supplier", "Product", "SKU", "Variant", "On Hand", "Price"] + subject.header.should == [ + "Supplier", + "Producer Suburb", + "Product", + "Product Properties", + "Variant Value", + "Price", + "Group Buy Unit Quantity", + "Amount" + ] end it "should build a table from a list of variants" do variant = double(:variant, sku: "sku", - options_text: "Variant Name", - count_on_hand: 10, - price: 100) + options_text: "Variant Name", + count_on_hand: 10, + price: 100) variant.stub_chain(:product, :supplier, :name).and_return("Supplier") + variant.stub_chain(:product, :supplier, :address, :city).and_return("A city") variant.stub_chain(:product, :name).and_return("Product Name") + variant.stub_chain(:product, :properties).and_return [double(name: "test"), double(name: "foo")] + variant.stub_chain(:product, :group_buy_unit_size).and_return(21) subject.stub(:variants).and_return [variant] + subject.table.should == [[ "Supplier", + "A city", "Product Name", - "sku", + "test, foo", "Variant Name", - 10, - 100]] + 100, + 21, + "" + ]] end it "fetches variants for some params" do diff --git a/spec/mailers/order_mailer_spec.rb b/spec/mailers/order_mailer_spec.rb new file mode 100644 index 0000000000..3a8659cc0f --- /dev/null +++ b/spec/mailers/order_mailer_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper' + +describe Spree::OrderMailer do + after do + ActionMailer::Base.deliveries.clear + end + + before do + ActionMailer::Base.delivery_method = :test + ActionMailer::Base.perform_deliveries = true + ActionMailer::Base.deliveries = [] + + @bill_address = create(:address) + @distributor_address = create(:address, :address1 => "distributor address", :city => 'The Shire', :zipcode => "1234") + @distributor = create(:distributor_enterprise, :address => @distributor_address) + product = create(:product) + product_distribution = create(:product_distribution, :product => product, :distributor => @distributor) + @shipping_instructions = "pick up on thursday please!" + @order1 = create(:order, :distributor => @distributor, :bill_address => @bill_address, :special_instructions => @shipping_instructions) + end + + it "should send an email when given an order" do + Spree::OrderMailer.confirm_email(@order1.id).deliver + ActionMailer::Base.deliveries.count.should == 1 + end + + it "should send the email from the enterprise email" do + Spree::OrderMailer.confirm_email(@order1.id).deliver + ActionMailer::Base.deliveries.first.from.should == [@distributor.email] + end + + it "should cc orders" do + Spree::OrderMailer.confirm_email(@order1.id).deliver + ActionMailer::Base.deliveries.first.cc.should == ["orders@openfoodnetwork.org"] + end +end diff --git a/spec/models/exchange_spec.rb b/spec/models/exchange_spec.rb index 05141cbcf6..f4ebfc2d8a 100644 --- a/spec/models/exchange_spec.rb +++ b/spec/models/exchange_spec.rb @@ -81,12 +81,12 @@ describe Exchange do it "finds exchanges going to any of a number of enterprises" do Exchange.to_enterprises([coordinator]).should == [incoming_exchange] - Exchange.to_enterprises([coordinator, distributor]).should == [incoming_exchange, outgoing_exchange] + Exchange.to_enterprises([coordinator, distributor]).sort.should == [incoming_exchange, outgoing_exchange].sort end it "finds exchanges coming from any of a number of enterprises" do Exchange.from_enterprises([coordinator]).should == [outgoing_exchange] - Exchange.from_enterprises([supplier, coordinator]).should == [incoming_exchange, outgoing_exchange] + Exchange.from_enterprises([supplier, coordinator]).sort.should == [incoming_exchange, outgoing_exchange].sort end it "finds exchanges with a particular variant" do diff --git a/spec/models/order_cycle_spec.rb b/spec/models/order_cycle_spec.rb index 1f3f4a0ad2..9b024b058e 100644 --- a/spec/models/order_cycle_spec.rb +++ b/spec/models/order_cycle_spec.rb @@ -34,11 +34,13 @@ describe OrderCycle do oc_active = create(:simple_order_cycle, orders_open_at: 1.week.ago, orders_close_at: 1.week.from_now) oc_not_yet_open = create(:simple_order_cycle, orders_open_at: 1.week.from_now, orders_close_at: 2.weeks.from_now) oc_already_closed = create(:simple_order_cycle, orders_open_at: 2.weeks.ago, orders_close_at: 1.week.ago) + oc_undated = create(:simple_order_cycle, orders_open_at: nil, orders_close_at: nil) OrderCycle.active.should == [oc_active] OrderCycle.inactive.sort.should == [oc_not_yet_open, oc_already_closed].sort OrderCycle.upcoming.should == [oc_not_yet_open] OrderCycle.closed.should == [oc_already_closed] + OrderCycle.undated.should == [oc_undated] end it "finds order cycles accessible by a user" do @@ -223,7 +225,7 @@ describe OrderCycle do @d2 = create(:enterprise, next_collection_at: '2-8pm Friday') @e0 = create(:exchange, order_cycle: @oc, sender: create(:enterprise), receiver: @oc.coordinator) - @e1 = create(:exchange, order_cycle: @oc, sender: @oc.coordinator, receiver: @d1, pickup_time: '5pm Tuesday') + @e1 = create(:exchange, order_cycle: @oc, sender: @oc.coordinator, receiver: @d1, pickup_time: '5pm Tuesday', pickup_instructions: "Come get it!") @e2 = create(:exchange, order_cycle: @oc, sender: @oc.coordinator, receiver: @d2, pickup_time: nil) end @@ -241,6 +243,12 @@ describe OrderCycle do @oc.pickup_time_for(@d2).should == '2-8pm Friday' end end + + describe "finding pickup instructions for a distributor" do + it "returns the pickup instructions" do + @oc.pickup_instructions_for(@d1).should == "Come get it!" + end + end end describe "checking status" do @@ -248,6 +256,7 @@ describe OrderCycle do it "reports status when an order cycle is upcoming" do Timecop.freeze(oc.orders_open_at - 1.second) do + oc.should_not be_undated oc.should be_upcoming oc.should_not be_open oc.should_not be_closed @@ -255,6 +264,7 @@ describe OrderCycle do end it "reports status when an order cycle is open" do + oc.should_not be_undated oc.should_not be_upcoming oc.should be_open oc.should_not be_closed @@ -262,11 +272,21 @@ describe OrderCycle do it "reports status when an order cycle has closed" do Timecop.freeze(oc.orders_close_at + 1.second) do + oc.should_not be_undated oc.should_not be_upcoming oc.should_not be_open oc.should be_closed end end + + it "reports status when an order cycle is undated" do + oc.update_attributes!(orders_open_at: nil, orders_close_at: nil) + + oc.should be_undated + oc.should_not be_upcoming + oc.should_not be_open + oc.should_not be_closed + end end it "clones itself" do diff --git a/spec/models/spree/ability_spec.rb b/spec/models/spree/ability_spec.rb index c7d96c32c5..35020aede5 100644 --- a/spec/models/spree/ability_spec.rb +++ b/spec/models/spree/ability_spec.rb @@ -44,7 +44,7 @@ module Spree end it "should be able to read/write their enterprises' product variants" do - should have_ability([:admin, :index, :read, :create, :edit, :search, :update], for: Spree::Variant) + should have_ability([:admin, :index, :read, :create, :edit, :search, :update, :destroy], for: Spree::Variant) end it "should be able to read/write their enterprises' product properties" do