mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-26 05:55:15 +00:00
Merge branch 'master' of github.com:openfoodfoundation/openfoodnetwork into error-pages
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
angular.module('admin.orderCycles')
|
||||
.controller 'AdminEditOrderCycleCtrl', ($scope, $filter, $location, OrderCycle, Enterprise, EnterpriseFee, StatusMessage) ->
|
||||
.controller 'AdminEditOrderCycleCtrl', ($scope, $filter, $location, $window, OrderCycle, Enterprise, EnterpriseFee, StatusMessage) ->
|
||||
order_cycle_id = $location.absUrl().match(/\/admin\/order_cycles\/(\d+)/)[1]
|
||||
$scope.enterprises = Enterprise.index(order_cycle_id: order_cycle_id)
|
||||
$scope.supplier_enterprises = Enterprise.producer_enterprises
|
||||
@@ -12,6 +12,9 @@ angular.module('admin.orderCycles')
|
||||
|
||||
$scope.StatusMessage = StatusMessage
|
||||
|
||||
$scope.$watch 'order_cycle_form.$dirty', (newValue) ->
|
||||
StatusMessage.display 'notice', 'You have unsaved changes' if newValue
|
||||
|
||||
$scope.loaded = ->
|
||||
Enterprise.loaded && EnterpriseFee.loaded && OrderCycle.loaded
|
||||
|
||||
@@ -60,6 +63,7 @@ angular.module('admin.orderCycles')
|
||||
$scope.removeExchange = ($event, exchange) ->
|
||||
$event.preventDefault()
|
||||
OrderCycle.removeExchange(exchange)
|
||||
$scope.order_cycle_form.$dirty = true
|
||||
|
||||
$scope.addCoordinatorFee = ($event) ->
|
||||
$event.preventDefault()
|
||||
@@ -81,4 +85,9 @@ angular.module('admin.orderCycles')
|
||||
OrderCycle.removeDistributionOfVariant(variant_id)
|
||||
|
||||
$scope.submit = (destination) ->
|
||||
StatusMessage.display 'progress', "Saving..."
|
||||
OrderCycle.update(destination)
|
||||
$scope.order_cycle_form.$setPristine()
|
||||
|
||||
$scope.cancel = (destination) ->
|
||||
$window.location = destination
|
||||
|
||||
@@ -9,6 +9,9 @@ angular.module('admin.orderCycles').controller "AdminSimpleEditOrderCycleCtrl",
|
||||
$scope.order_cycle = OrderCycle.load $scope.orderCycleId(), (order_cycle) =>
|
||||
$scope.init()
|
||||
|
||||
$scope.$watch 'order_cycle_form.$dirty', (newValue) ->
|
||||
StatusMessage.display 'notice', 'You have unsaved changes' if newValue
|
||||
|
||||
$scope.loaded = ->
|
||||
Enterprise.loaded && EnterpriseFee.loaded && OrderCycle.loaded
|
||||
|
||||
@@ -35,5 +38,6 @@ angular.module('admin.orderCycles').controller "AdminSimpleEditOrderCycleCtrl",
|
||||
OrderCycle.removeCoordinatorFee(index)
|
||||
|
||||
$scope.submit = (destination) ->
|
||||
StatusMessage.display 'progress', "Saving..."
|
||||
OrderCycle.mirrorIncomingToOutgoingProducts()
|
||||
OrderCycle.update(destination)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
angular.module("admin.utils").directive "saveBar", (StatusMessage) ->
|
||||
restrict: "E"
|
||||
scope:
|
||||
save: "&"
|
||||
form: "="
|
||||
buttons: "="
|
||||
templateUrl: "admin/save_bar.html"
|
||||
link: (scope, element, attrs) ->
|
||||
scope.StatusMessage = StatusMessage
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#save-bar.animate-show{ ng: { show: 'form.$dirty || StatusMessage.active()' } }
|
||||
.twelve.columns.alpha
|
||||
%h5#status-message{ ng: { style: 'StatusMessage.statusMessage.style' } }
|
||||
{{ StatusMessage.statusMessage.text || " " }}
|
||||
.four.columns.omega.text-right
|
||||
%input.red{type: "button", value: "Save Changes", ng: { disabled: '!form.$dirty', click: "save()" } }
|
||||
.container
|
||||
.eight.columns.alpha
|
||||
%h5#status-message{ ng: { style: 'StatusMessage.statusMessage.style' } }
|
||||
{{ StatusMessage.statusMessage.text || " " }}
|
||||
.eight.columns.omega.text-right
|
||||
%input{"ng-repeat" => "button in buttons", type: "button", value: "{{button.text}}", ng: { class: "button.class", click: "button.action(button.param)" } }
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
#save-bar
|
||||
position: fixed
|
||||
width: 100%
|
||||
bottom: 0px
|
||||
padding: 8px 10px
|
||||
left: 0
|
||||
padding: 8px 8px
|
||||
font-weight: bold
|
||||
background-color: #fff
|
||||
background-color: #eff5fc
|
||||
color: #5498da
|
||||
h5
|
||||
color: #5498da
|
||||
input
|
||||
margin-right: 5px
|
||||
|
||||
@@ -37,6 +37,7 @@ text-angular .ta-editor {
|
||||
|
||||
input.red {
|
||||
background-color: #DA5354;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
input.search {
|
||||
|
||||
@@ -32,6 +32,13 @@
|
||||
.debit
|
||||
color: $clr-brick
|
||||
|
||||
.invalid
|
||||
color: $ofn-grey
|
||||
.credit
|
||||
color: $ofn-grey
|
||||
.debit
|
||||
color: $ofn-grey
|
||||
|
||||
.distributor-balance.paid
|
||||
visibility: hidden
|
||||
|
||||
|
||||
@@ -74,6 +74,9 @@ table.order-summary
|
||||
padding-left: 5px
|
||||
padding-right: 5px
|
||||
|
||||
.text-right
|
||||
text-align: right
|
||||
|
||||
.social .soc-btn
|
||||
padding: 3px 7px
|
||||
font-size: 12px
|
||||
|
||||
@@ -4,19 +4,26 @@ class EnterpriseMailer < Spree::BaseMailer
|
||||
|
||||
def welcome(enterprise)
|
||||
@enterprise = enterprise
|
||||
mail(:to => enterprise.email, :from => from_address,
|
||||
:subject => "#{enterprise.name} is now on #{Spree::Config[:site_name]}")
|
||||
subject = t('enterprise_mailer.welcome.subject',
|
||||
enterprise: @enterprise.name,
|
||||
sitename: Spree::Config[:site_name])
|
||||
mail(:to => enterprise.email,
|
||||
:from => from_address,
|
||||
:subject => subject)
|
||||
end
|
||||
|
||||
def confirmation_instructions(record, token, opts={})
|
||||
def confirmation_instructions(record, token)
|
||||
@token = token
|
||||
find_enterprise(record)
|
||||
mail(subject: "Please confirm your email for #{@enterprise.name}",
|
||||
to: ( @enterprise.unconfirmed_email || @enterprise.email ),
|
||||
from: from_address)
|
||||
subject = t('enterprise_mailer.confirmation_instructions.subject',
|
||||
enterprise: @enterprise.name)
|
||||
mail(to: (@enterprise.unconfirmed_email || @enterprise.email),
|
||||
from: from_address,
|
||||
subject: subject)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_enterprise(enterprise)
|
||||
@enterprise = enterprise.is_a?(Enterprise) ? enterprise : Enterprise.find(enterprise)
|
||||
end
|
||||
|
||||
@@ -6,6 +6,8 @@ class ProducerMailer < Spree::BaseMailer
|
||||
@order_cycle = order_cycle
|
||||
@line_items = aggregated_line_items_from(@order_cycle, @producer)
|
||||
@receival_instructions = @order_cycle.receival_instructions_for @producer
|
||||
@total = total_from_line_items(@line_items)
|
||||
@tax_total = tax_total_from_line_items(@line_items)
|
||||
|
||||
subject = "[#{Spree::Config.site_name}] Order cycle report for #{producer.name}"
|
||||
|
||||
@@ -45,8 +47,15 @@ class ProducerMailer < Spree::BaseMailer
|
||||
else
|
||||
lis[li.variant] = li
|
||||
end
|
||||
|
||||
lis
|
||||
end
|
||||
end
|
||||
|
||||
def total_from_line_items(aggregated_line_items)
|
||||
Spree::Money.new aggregated_line_items.values.map(&:total).sum
|
||||
end
|
||||
|
||||
def tax_total_from_line_items(aggregated_line_items)
|
||||
Spree::Money.new aggregated_line_items.values.map(&:included_tax).sum
|
||||
end
|
||||
end
|
||||
|
||||
@@ -51,11 +51,16 @@ Spree.user_class.class_eval do
|
||||
|
||||
# Returns Enterprise IDs for distributors that the user has shopped at
|
||||
def enterprises_ordered_from
|
||||
orders.where(state: :complete).map(&:distributor_id).uniq
|
||||
enterprise_ids = orders.where(state: :complete).map(&:distributor_id).uniq
|
||||
# Exclude the accounts distributor
|
||||
if Spree::Config.accounts_distributor_id
|
||||
enterprise_ids = enterprise_ids.keep_if { |a| a != Spree::Config.accounts_distributor_id }
|
||||
end
|
||||
enterprise_ids
|
||||
end
|
||||
|
||||
# Returns orders and their associated payments for all distributors that have been ordered from
|
||||
def compelete_orders_by_distributor
|
||||
def complete_orders_by_distributor
|
||||
Enterprise
|
||||
.includes(distributed_orders: { payments: :payment_method })
|
||||
.where(enterprises: { id: enterprises_ordered_from },
|
||||
@@ -65,8 +70,8 @@ Spree.user_class.class_eval do
|
||||
|
||||
def orders_by_distributor
|
||||
# Remove uncompleted payments as these will not be reflected in order balance
|
||||
data_array = compelete_orders_by_distributor.to_a
|
||||
remove_uncompleted_payments(data_array)
|
||||
data_array = complete_orders_by_distributor.to_a
|
||||
remove_payments_in_checkout(data_array)
|
||||
data_array.sort! { |a, b| b.distributed_orders.length <=> a.distributed_orders.length }
|
||||
end
|
||||
|
||||
@@ -78,10 +83,10 @@ Spree.user_class.class_eval do
|
||||
end
|
||||
end
|
||||
|
||||
def remove_uncompleted_payments(enterprises)
|
||||
def remove_payments_in_checkout(enterprises)
|
||||
enterprises.each do |enterprise|
|
||||
enterprise.distributed_orders.each do |order|
|
||||
order.payments.keep_if { |payment| payment.state == "completed" }
|
||||
order.payments.keep_if { |payment| payment.state != "checkout" }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module Api
|
||||
class PaymentSerializer < ActiveModel::Serializer
|
||||
attributes :amount, :updated_at, :payment_method
|
||||
attributes :amount, :updated_at, :payment_method, :state
|
||||
def payment_method
|
||||
object.payment_method.name
|
||||
end
|
||||
|
||||
@@ -52,14 +52,10 @@
|
||||
.actions
|
||||
- if @order_cycle.new_record?
|
||||
= f.submit 'Create', 'ng-click' => "submit('#{main_app.admin_order_cycles_path}')", 'ng-disabled' => '!loaded()'
|
||||
- else
|
||||
= f.submit 'Update', 'ng-click' => "submit(null)", 'ng-disabled' => '!loaded()'
|
||||
= f.submit 'Update and Close', 'ng-click' => "submit('#{main_app.admin_order_cycles_path}')", 'ng-disabled' => '!loaded()'
|
||||
|
||||
%span{'ng-show' => 'loaded()'}
|
||||
or
|
||||
= link_to 'Cancel', main_app.admin_order_cycles_path
|
||||
%span{'ng-hide' => 'loaded()'} Loading...
|
||||
= render 'spree/admin/shared/status_message'
|
||||
|
||||
|
||||
- unless Rails.env.production?
|
||||
|
||||
@@ -23,12 +23,7 @@
|
||||
.actions
|
||||
- if @order_cycle.new_record?
|
||||
= f.submit 'Create', 'ng-click' => "submit('#{main_app.admin_order_cycles_path}')", 'ng-disabled' => '!loaded()'
|
||||
- else
|
||||
= f.submit 'Update', 'ng-click' => "submit(null)", 'ng-disabled' => '!loaded()'
|
||||
= f.submit 'Update and Close', 'ng-click' => "submit('#{main_app.admin_order_cycles_path}')", 'ng-disabled' => '!loaded()'
|
||||
|
||||
%span{'ng-show' => 'loaded()'}
|
||||
or
|
||||
= link_to 'Cancel', main_app.admin_order_cycles_path
|
||||
%span{'ng-hide' => 'loaded()'} Loading...
|
||||
= render 'spree/admin/shared/status_message'
|
||||
|
||||
@@ -27,7 +27,10 @@
|
||||
|
||||
|
||||
- ng_controller = order_cycles_simple_form ? 'AdminSimpleEditOrderCycleCtrl' : 'AdminEditOrderCycleCtrl'
|
||||
= form_for [main_app, :admin, @order_cycle], :url => '', :html => {:class => 'ng order_cycle', 'ng-app' => 'admin.orderCycles', 'ng-controller' => ng_controller} do |f|
|
||||
= form_for [main_app, :admin, @order_cycle], :url => '', :html => {:class => 'ng order_cycle', 'ng-app' => 'admin.orderCycles', 'ng-controller' => ng_controller, name: 'order_cycle_form'} do |f|
|
||||
|
||||
%save-bar{ buttons: "[{ text: 'Update', action: submit, param: null, class: 'red' }, { text: 'Update and Close', action: submit, param: '#{main_app.admin_order_cycles_path}', class: 'red' }, { text: 'Cancel', action: cancel, param: '#{main_app.admin_order_cycles_path}', class: '' }]", form: "order_cycle_form" }
|
||||
|
||||
- if order_cycles_simple_form
|
||||
= render 'simple_form', f: f
|
||||
- else
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
%form{ name: 'variant_overrides_form', ng: { show: "views.inventory.visible" } }
|
||||
%save-bar{ save: "update()", form: "variant_overrides_form" }
|
||||
%save-bar{ form: "variant_overrides_form", buttons: "[{ text: 'Save Changes', action: update, class: 'red' }]" }
|
||||
%table.index.bulk#variant-overrides
|
||||
%col.producer{ width: "20%", ng: { show: 'columns.producer.visible' } }
|
||||
%col.product{ width: "20%", ng: { show: 'columns.product.visible' } }
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
.map-container
|
||||
%map{"ng-if" => "(active(\'\') && (mapShowed = true)) || mapShowed"}
|
||||
%google-map{options: "map.additional_options", center: "map.center", zoom: "map.zoom", styles: "map.styles", draggable: "true"}
|
||||
%map-search
|
||||
%markers{models: "mapMarkers", fit: "true",
|
||||
coords: "'self'", icon: "'icon'", click: "'reveal'"}
|
||||
|
||||
|
||||
62
app/views/producer_mailer/order_cycle_report.html.haml
Normal file
62
app/views/producer_mailer/order_cycle_report.html.haml
Normal file
@@ -0,0 +1,62 @@
|
||||
%p Dear #{@producer.name},
|
||||
%p
|
||||
= t :producer_mail_text_before
|
||||
- if @receival_instructions
|
||||
%p
|
||||
Stock pickup/delivery instructions:
|
||||
= @receival_instructions
|
||||
%p
|
||||
Here is a summary of the orders for your products:
|
||||
%table.order-summary
|
||||
%thead
|
||||
%tr
|
||||
%th
|
||||
= t :sku
|
||||
%th
|
||||
= t :supplier
|
||||
%th
|
||||
= t :product
|
||||
%th.text-right
|
||||
= t :quantity
|
||||
%th.text-right
|
||||
= t :price
|
||||
%th.text-right
|
||||
= t :subtotal
|
||||
%th.text-right
|
||||
= t :included_tax
|
||||
%tbody
|
||||
- @line_items.each_pair do |variant, line_item|
|
||||
%tr
|
||||
%td
|
||||
#{variant.sku}
|
||||
%td
|
||||
#{raw(variant.product.supplier.name)}
|
||||
%td
|
||||
#{raw(variant.product_and_full_name)}
|
||||
%td.text-right
|
||||
#{line_item.quantity}
|
||||
%td.text-right
|
||||
#{line_item.single_money}
|
||||
%td.text-right
|
||||
#{line_item.display_total}
|
||||
%td.text-right
|
||||
#{line_item.display_included_tax}
|
||||
%tr.total_row
|
||||
%td
|
||||
%td
|
||||
%td
|
||||
%td
|
||||
%td
|
||||
%td.text-right
|
||||
#{@total}
|
||||
%td.text-right
|
||||
#{@tax_total}
|
||||
%p
|
||||
= t :producer_mail_text_after
|
||||
%em
|
||||
%p
|
||||
#{@coordinator.name}
|
||||
%p
|
||||
#{@coordinator.address.address1}, #{@coordinator.address.city}, #{@coordinator.address.zipcode}
|
||||
#{@coordinator.phone}
|
||||
#{@coordinator.email}
|
||||
@@ -1,6 +1,6 @@
|
||||
Dear #{@producer.name},
|
||||
\
|
||||
We now have all the consumer orders for the next food drop.
|
||||
= t :producer_mail_text_before
|
||||
\
|
||||
- if @receival_instructions
|
||||
Stock pickup/delivery instructions:
|
||||
@@ -15,7 +15,10 @@ Here is a summary of the orders for your products:
|
||||
- @line_items.each_pair do |variant, line_item|
|
||||
#{variant.sku} - #{raw(variant.product.supplier.name)} - #{raw(variant.product_and_full_name)} (QTY: #{line_item.quantity}) @ #{line_item.single_money} = #{line_item.display_amount}
|
||||
\
|
||||
Thanks and best wishes,
|
||||
\
|
||||
Total: #{@total}
|
||||
\
|
||||
= t :producer_mail_text_after
|
||||
#{@coordinator.name}
|
||||
#{@coordinator.address.address1}, #{@coordinator.address.city}, #{@coordinator.address.zipcode}
|
||||
#{@coordinator.phone}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
= render :partial => 'spree/admin/shared/order_sub_menu'
|
||||
|
||||
%div{ ng: { controller: 'LineItemsCtrl' } }
|
||||
%save-bar{ save: "submit()", form: "bulk_order_form" }
|
||||
%save-bar{ form: "bulk_order_form", buttons: "[{ text: 'Save Changes', action: submit, class: 'red' }]" }
|
||||
.filters{ :class => "sixteen columns alpha" }
|
||||
.date_filter{ :class => "two columns alpha" }
|
||||
%label{ :for => 'start_date_filter' }
|
||||
|
||||
@@ -19,10 +19,12 @@
|
||||
%td.order5.text-right{"ng-class" => "{'credit' : order.total < 0, 'debit' : order.total > 0, 'paid' : order.total == 0}","bo-text" => "order.total | localizeCurrency"}
|
||||
%td.order6.text-right.show-for-large-up{"ng-class" => "{'credit' : order.outstanding_balance < 0, 'debit' : order.outstanding_balance > 0, 'paid' : order.outstanding_balance == 0}", "bo-text" => "order.outstanding_balance | localizeCurrency"}
|
||||
%td.order7.text-right{"ng-class" => "{'credit' : order.running_balance < 0, 'debit' : order.running_balance > 0, 'paid' : order.running_balance == 0}", "bo-text" => "order.running_balance | localizeCurrency"}
|
||||
%tr.payment-row{"ng-repeat" => "payment in order.payments"}
|
||||
%td.order1= t :payment
|
||||
%tr.payment-row{"ng-repeat" => "payment in order.payments", "ng-class" => "{'invalid': payment.state != 'completed'}"}
|
||||
%td.order1{"bo-text" => "payment.payment_method"}
|
||||
%td.order2{"bo-text" => "payment.updated_at"}
|
||||
%td.order3.show-for-large-up{"bo-text" => "payment.payment_method"}
|
||||
%td.order3.show-for-large-up
|
||||
%i{"ng-class" => "{'ofn-i_012-warning': payment.state == 'invalid' || payment.state == 'void' || payment.state == 'failed'}"}
|
||||
%span{"bo-text" => "'spree.payment_states.' + payment.state | t | capitalize"}
|
||||
%td.order4.show-for-large-up
|
||||
%td.order5.text-right{"ng-class" => "{'credit' : payment.amount > 0, 'debit' : payment.amount < 0, 'paid' : payment.amount == 0}","bo-text" => "payment.amount | localizeCurrency"}
|
||||
%td.order6.show-for-large-up
|
||||
|
||||
@@ -1006,7 +1006,6 @@ Please follow the instructions there to make your enterprise visible on the Open
|
||||
validation_msg_product_category_cant_be_blank: "^Product Category cant be blank"
|
||||
validation_msg_tax_category_cant_be_blank: "^Tax Category can't be blank"
|
||||
validation_msg_is_associated_with_an_exising_customer: "is associated with an existing customer"
|
||||
|
||||
spree:
|
||||
shipment_states:
|
||||
backorder: backorder
|
||||
@@ -1024,6 +1023,7 @@ Please follow the instructions there to make your enterprise visible on the Open
|
||||
pending: pending
|
||||
processing: processing
|
||||
void: void
|
||||
invalid: invalid
|
||||
order_state:
|
||||
address: address
|
||||
adjustments: adjustments
|
||||
|
||||
@@ -32,6 +32,11 @@ en:
|
||||
not_confirmed: Your email address could not be confirmed. Perhaps you have already completed this step?
|
||||
confirmation_sent: "Confirmation email sent!"
|
||||
confirmation_not_sent: "Could not send a confirmation email."
|
||||
enterprise_mailer:
|
||||
confirmation_instructions:
|
||||
subject: "Please confirm the email address for %{enterprise}"
|
||||
welcome:
|
||||
subject: "%{enterprise} is now on %{sitename}"
|
||||
home: "OFN"
|
||||
title: Open Food Network
|
||||
welcome_to: 'Welcome to '
|
||||
@@ -405,6 +410,9 @@ See the %{link} to find out more about %{sitename}'s features and to start using
|
||||
If you are a producer or food enterprise, we are excited to have you as a part of the network."
|
||||
email_signup_help_html: "We welcome all your questions and feedback; you can use the <em>Send Feedback</em> button on the site or email us at"
|
||||
|
||||
producer_mail_text_before: "We now have all the consumer orders for the next food drop."
|
||||
producer_mail_text_after: "Thanks and best wishes,"
|
||||
|
||||
shopping_oc_closed: Orders are closed
|
||||
shopping_oc_closed_description: "Please wait until the next cycle opens (or contact us directly to see if we can accept any late orders)"
|
||||
shopping_oc_last_closed: "The last cycle closed %{distance_of_time} ago"
|
||||
@@ -1032,6 +1040,7 @@ Please follow the instructions there to make your enterprise visible on the Open
|
||||
pending: pending
|
||||
processing: processing
|
||||
void: void
|
||||
invalid: invalid
|
||||
order_state:
|
||||
address: address
|
||||
adjustments: adjustments
|
||||
|
||||
@@ -267,6 +267,9 @@ feature %q{
|
||||
|
||||
|
||||
scenario "updating an order cycle", js: true do
|
||||
# Make the page long enough to avoid the save bar overlaying the form
|
||||
page.driver.resize(1280, 3600)
|
||||
|
||||
# Given an order cycle with all the settings
|
||||
oc = create(:order_cycle)
|
||||
initial_variants = oc.variants.sort_by &:id
|
||||
@@ -359,6 +362,8 @@ feature %q{
|
||||
select 'Distributor fee 2', from: 'order_cycle_outgoing_exchange_2_enterprise_fees_0_enterprise_fee_id'
|
||||
|
||||
# And I click Update
|
||||
expect(page).to have_selector "#save-bar"
|
||||
save_screenshot('abc.png')
|
||||
click_button 'Update and Close'
|
||||
|
||||
# Then my order cycle should have been updated
|
||||
@@ -607,10 +612,6 @@ feature %q{
|
||||
page.all('tr.supplier').count.should == 3
|
||||
page.all('tr.distributor').count.should == 3
|
||||
|
||||
# When I save, then those exchanges should remain
|
||||
click_button 'Update'
|
||||
page.should have_content "Your order cycle has been updated."
|
||||
|
||||
oc.reload
|
||||
oc.suppliers.should match_array [supplier_managed, supplier_permitted, supplier_unmanaged]
|
||||
oc.coordinator.should == distributor_managed
|
||||
@@ -618,6 +619,9 @@ feature %q{
|
||||
end
|
||||
|
||||
scenario "editing an order cycle" do
|
||||
# Make the page long enough to avoid the save bar overlaying the form
|
||||
page.driver.resize(1280, 3600)
|
||||
|
||||
oc = create(:simple_order_cycle, { suppliers: [supplier_managed, supplier_permitted, supplier_unmanaged], coordinator: distributor_managed, distributors: [distributor_managed, distributor_permitted, distributor_unmanaged], name: 'Order Cycle 1' } )
|
||||
|
||||
visit edit_admin_order_cycle_path(oc)
|
||||
@@ -627,6 +631,7 @@ feature %q{
|
||||
page.find("tr.supplier-#{supplier_permitted.id} a.remove-exchange").click
|
||||
page.find("tr.distributor-#{distributor_managed.id} a.remove-exchange").click
|
||||
page.find("tr.distributor-#{distributor_permitted.id} a.remove-exchange").click
|
||||
|
||||
click_button 'Update'
|
||||
|
||||
# Then the exchanges should be removed
|
||||
@@ -698,10 +703,6 @@ feature %q{
|
||||
# I should be able to see but not toggle v2, because I don't have permission
|
||||
expect(page).to have_field "order_cycle_outgoing_exchange_0_variants_#{v2.id}", disabled: true
|
||||
|
||||
# When I save, any exchanges that I can't manage remain
|
||||
click_button 'Update'
|
||||
page.should have_content "Your order cycle has been updated."
|
||||
|
||||
oc.reload
|
||||
oc.suppliers.should match_array [supplier_managed, supplier_permitted, supplier_unmanaged]
|
||||
oc.coordinator.should == distributor_managed
|
||||
@@ -751,10 +752,6 @@ feature %q{
|
||||
# I should be able to see but not toggle v2, because I don't have permission
|
||||
expect(page).to have_field "order_cycle_incoming_exchange_0_variants_#{v2.id}", disabled: true
|
||||
|
||||
# When I save, any exchange that I can't manage remains
|
||||
click_button 'Update'
|
||||
page.should have_content "Your order cycle has been updated."
|
||||
|
||||
oc.reload
|
||||
oc.suppliers.should match_array [supplier_managed, supplier_permitted, supplier_unmanaged]
|
||||
oc.coordinator.should == distributor_managed
|
||||
@@ -868,6 +865,9 @@ feature %q{
|
||||
end
|
||||
|
||||
scenario "updating an order cycle" do
|
||||
# Make the page long enough to avoid the save bar overlaying the form
|
||||
page.driver.resize(1280, 3600)
|
||||
|
||||
# Given an order cycle with pickup time and instructions
|
||||
fee1 = create(:enterprise_fee, name: 'my fee', enterprise: enterprise)
|
||||
fee2 = create(:enterprise_fee, name: 'that fee', enterprise: enterprise)
|
||||
@@ -902,6 +902,7 @@ feature %q{
|
||||
# When I update, or update and close, both work
|
||||
click_button 'Update'
|
||||
page.should have_content 'Your order cycle has been updated.'
|
||||
|
||||
click_button 'Update and Close'
|
||||
|
||||
# Then my order cycle should have been updated
|
||||
|
||||
@@ -13,6 +13,8 @@ feature %q{
|
||||
let!(:distributor2) { create(:distributor_enterprise) }
|
||||
let!(:distributor_credit) { create(:distributor_enterprise) }
|
||||
let!(:distributor_without_orders) { create(:distributor_enterprise) }
|
||||
let!(:accounts_distributor) {create :distributor_enterprise}
|
||||
let!(:order_account_invoice) { create(:order, distributor: accounts_distributor, state: 'complete', user: user) }
|
||||
let!(:d1o1) { create(:completed_order_with_totals, distributor_id: distributor1.id, user_id: user.id, total: 10000)}
|
||||
let!(:d1o2) { create(:order_without_full_payment, distributor_id: distributor1.id, user_id: user.id, total: 5000)}
|
||||
let!(:d2o1) { create(:completed_order_with_totals, distributor_id: distributor2.id, user_id: user.id)}
|
||||
@@ -21,19 +23,24 @@ feature %q{
|
||||
|
||||
|
||||
before do
|
||||
Spree::Config.accounts_distributor_id = accounts_distributor.id
|
||||
credit_order.update!
|
||||
login_as user
|
||||
visit "/account"
|
||||
end
|
||||
|
||||
it "shows all hubs that have been ordered from with balance or credit" do
|
||||
# Single test to avoid re-rendering page
|
||||
expect(page).to have_content distributor1.name
|
||||
expect(page).to have_content distributor2.name
|
||||
expect(page).not_to have_content distributor_without_orders.name
|
||||
# Exclude the special Accounts & Billing distributor
|
||||
expect(page).not_to have_content accounts_distributor.name
|
||||
expect(page).to have_content distributor1.name + " " + "Balance due"
|
||||
expect(page).to have_content distributor_credit.name + " Credit"
|
||||
end
|
||||
|
||||
|
||||
it "reveals table of orders for distributors when clicked" do
|
||||
expand_active_table_node distributor1.name
|
||||
expect(page).to have_link "Order " + d1o1.number, href:"/orders/#{d1o1.number}"
|
||||
|
||||
@@ -10,7 +10,8 @@ describe "AdminSimpleEditOrderCycleCtrl", ->
|
||||
outgoing_exchange = {}
|
||||
|
||||
beforeEach ->
|
||||
scope = {}
|
||||
scope =
|
||||
$watch: jasmine.createSpy('$watch')
|
||||
location =
|
||||
absUrl: ->
|
||||
'example.com/admin/order_cycles/27/edit'
|
||||
|
||||
@@ -169,7 +169,9 @@ describe 'OrderCycle controllers', ->
|
||||
EnterpriseFee = null
|
||||
|
||||
beforeEach ->
|
||||
scope = {}
|
||||
scope =
|
||||
order_cycle_form: jasmine.createSpyObj('order_cycle_form', ['$dirty', '$setPristine'])
|
||||
$watch: jasmine.createSpy('$watch')
|
||||
event =
|
||||
preventDefault: jasmine.createSpy('preventDefault')
|
||||
location =
|
||||
@@ -292,6 +294,7 @@ describe 'OrderCycle controllers', ->
|
||||
scope.removeExchange(event, 'exchange')
|
||||
expect(event.preventDefault).toHaveBeenCalled()
|
||||
expect(OrderCycle.removeExchange).toHaveBeenCalledWith('exchange')
|
||||
expect(scope.order_cycle_form.$dirty).toEqual true
|
||||
|
||||
it 'Adds coordinator fees', ->
|
||||
scope.addCoordinatorFee(event)
|
||||
@@ -320,6 +323,7 @@ describe 'OrderCycle controllers', ->
|
||||
it 'Submits the order cycle via OrderCycle update', ->
|
||||
scope.submit('/admin/order_cycles')
|
||||
expect(OrderCycle.update).toHaveBeenCalledWith('/admin/order_cycles')
|
||||
expect(scope.order_cycle_form.$setPristine.calls.length).toEqual 1
|
||||
|
||||
|
||||
describe 'OrderCycle services', ->
|
||||
|
||||
@@ -12,7 +12,7 @@ describe EnterpriseMailer do
|
||||
EnterpriseMailer.confirmation_instructions(enterprise, 'token').deliver
|
||||
ActionMailer::Base.deliveries.count.should == 1
|
||||
mail = ActionMailer::Base.deliveries.first
|
||||
expect(mail.subject).to eq "Please confirm your email for #{enterprise.name}"
|
||||
expect(mail.subject).to eq "Please confirm the email address for #{enterprise.name}"
|
||||
expect(mail.to).to include enterprise.email
|
||||
expect(mail.reply_to).to be_nil
|
||||
end
|
||||
@@ -28,7 +28,7 @@ describe EnterpriseMailer do
|
||||
EnterpriseMailer.confirmation_instructions(enterprise, 'token').deliver
|
||||
ActionMailer::Base.deliveries.count.should == 1
|
||||
mail = ActionMailer::Base.deliveries.first
|
||||
expect(mail.subject).to eq "Please confirm your email for #{enterprise.name}"
|
||||
expect(mail.subject).to eq "Please confirm the email address for #{enterprise.name}"
|
||||
expect(mail.to).to include enterprise.unconfirmed_email
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,21 +10,23 @@ describe ProducerMailer do
|
||||
let(:p1) { create(:product, price: 12.34, supplier: s1) }
|
||||
let(:p2) { create(:product, price: 23.45, supplier: s2) }
|
||||
let(:p3) { create(:product, price: 34.56, supplier: s1) }
|
||||
let(:p4) { create(:product, price: 45.67, supplier: s1) }
|
||||
let(:order_cycle) { create(:simple_order_cycle) }
|
||||
let!(:incoming_exchange) { order_cycle.exchanges.create! sender: s1, receiver: d1, incoming: true, receival_instructions: 'Outside shed.' }
|
||||
|
||||
let!(:order) do
|
||||
order = create(:order, distributor: d1, order_cycle: order_cycle, state: 'complete')
|
||||
order.line_items << create(:line_item, variant: p1.master)
|
||||
order.line_items << create(:line_item, variant: p1.master)
|
||||
order.line_items << create(:line_item, variant: p2.master)
|
||||
order.line_items << create(:line_item, variant: p1.variants.first)
|
||||
order.line_items << create(:line_item, variant: p1.variants.first)
|
||||
order.line_items << create(:line_item, variant: p2.variants.first)
|
||||
order.line_items << create(:line_item, variant: p4.variants.first)
|
||||
order.finalize!
|
||||
order.save
|
||||
order
|
||||
end
|
||||
let!(:order_incomplete) do
|
||||
order = create(:order, distributor: d1, order_cycle: order_cycle, state: 'payment')
|
||||
order.line_items << create(:line_item, variant: p3.master)
|
||||
order.line_items << create(:line_item, variant: p3.variants.first)
|
||||
order.save
|
||||
order
|
||||
end
|
||||
@@ -44,7 +46,7 @@ describe ProducerMailer do
|
||||
end
|
||||
|
||||
it "includes receival instructions" do
|
||||
mail.body.should include 'Outside shed.'
|
||||
mail.body.encoded.should include 'Outside shed.'
|
||||
end
|
||||
|
||||
it "cc's the enterprise" do
|
||||
@@ -59,7 +61,11 @@ describe ProducerMailer do
|
||||
end
|
||||
|
||||
it "does not include incomplete orders" do
|
||||
mail.body.should_not include p3.name
|
||||
mail.body.encoded.should_not include p3.name
|
||||
end
|
||||
|
||||
it "includes the total" do
|
||||
mail.body.encoded.should include 'Total: $30.00'
|
||||
end
|
||||
|
||||
it "sends no mail when the producer has no orders" do
|
||||
|
||||
@@ -90,11 +90,17 @@ describe Spree.user_class do
|
||||
let!(:d1_order_for_u2) { create(:completed_order_with_totals, distributor: distributor1, user_id: u2.id) }
|
||||
let!(:d1o3) { create(:order, state: 'cart', distributor: distributor1, user_id: u1.id) }
|
||||
let!(:d2o1) { create(:completed_order_with_totals, distributor: distributor2, user_id: u2.id) }
|
||||
let!(:accounts_distributor) {create :distributor_enterprise}
|
||||
let!(:order_account_invoice) { create(:order, distributor: accounts_distributor, state: 'complete', user: u1) }
|
||||
|
||||
let!(:completed_payment) { create(:payment, order: d1o1, state: 'completed') }
|
||||
let!(:payment) { create(:payment, order: d1o2, state: 'invalid') }
|
||||
let!(:payment) { create(:payment, order: d1o2, state: 'checkout') }
|
||||
|
||||
it "returns enterprises that the user has ordered from" do
|
||||
before do
|
||||
Spree::Config.accounts_distributor_id = accounts_distributor.id
|
||||
end
|
||||
|
||||
it "returns enterprises that the user has ordered from, excluding accounts distributor" do
|
||||
expect(u1.enterprises_ordered_from).to eq [distributor1.id]
|
||||
end
|
||||
|
||||
@@ -114,8 +120,8 @@ describe Spree.user_class do
|
||||
expect(u1.orders_by_distributor.first.distributed_orders).not_to include d1o3
|
||||
end
|
||||
|
||||
it "doesn't return uncompleted payments" do
|
||||
expect(u1.orders_by_distributor.first.distributed_orders.map(&:payments).flatten).not_to include payment
|
||||
it "doesn't return payments that are still at checkout stage" do
|
||||
expect(u1.orders_by_distributor.first.distributed_orders.map{|o| o.payments}.flatten).not_to include payment
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user