Merge branch 'master' into 3-0-stable-mar6

This commit is contained in:
Luis Ramos
2020-03-12 16:54:09 +00:00
27 changed files with 376 additions and 65 deletions

View File

@@ -166,5 +166,5 @@ group :development do
# greater than 1.0.9, so we just required the latest available version here.
gem 'eventmachine', '>= 1.2.3'
gem 'rack-mini-profiler', '< 2.0.0'
gem 'rack-mini-profiler', '< 3.0.0'
end

View File

@@ -205,7 +205,7 @@ GEM
activerecord (>= 3.2.0, < 5.0)
fog (~> 1.0)
rails (>= 3.2.0, < 5.0)
ddtrace (0.32.0)
ddtrace (0.33.1)
msgpack
debugger-linecache (1.2.0)
deface (1.0.2)
@@ -465,7 +465,7 @@ GEM
railties (>= 3.1)
money (5.1.1)
i18n (~> 0.6.0)
msgpack (1.3.1)
msgpack (1.3.3)
multi_json (1.14.1)
multi_xml (0.6.0)
multipart-post (2.1.1)
@@ -513,7 +513,7 @@ GEM
rabl (0.8.4)
activesupport (>= 2.3.14)
rack (1.5.5)
rack-mini-profiler (1.1.6)
rack-mini-profiler (2.0.0)
rack (>= 1.2.0)
rack-protection (1.5.5)
rack
@@ -571,15 +571,15 @@ GEM
rspec-core (~> 3.9.0)
rspec-expectations (~> 3.9.0)
rspec-mocks (~> 3.9.0)
rspec-core (3.9.0)
rspec-support (~> 3.9.0)
rspec-core (3.9.1)
rspec-support (~> 3.9.1)
rspec-expectations (3.9.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-mocks (3.9.0)
rspec-mocks (3.9.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-rails (3.9.0)
rspec-rails (3.9.1)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
@@ -589,7 +589,7 @@ GEM
rspec-support (~> 3.9.0)
rspec-retry (0.6.2)
rspec-core (> 3.3)
rspec-support (3.9.0)
rspec-support (3.9.2)
rubocop (0.80.1)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
@@ -752,7 +752,7 @@ DEPENDENCIES
pg (~> 0.21.0)
pry-byebug (>= 3.4.3)
rabl
rack-mini-profiler (< 2.0.0)
rack-mini-profiler (< 3.0.0)
rack-rewrite
rack-ssl
rails (~> 4.0.0)

View File

@@ -23,7 +23,6 @@ module Admin
before_filter :setup_property, only: [:edit]
helper 'spree/products'
include ActionView::Helpers::TextHelper
include OrderCyclesHelper
def index
@@ -77,19 +76,12 @@ module Admin
def bulk_update
@enterprise_set = EnterpriseSet.new(collection, params[:enterprise_set])
touched_enterprises = @enterprise_set.collection.select(&:changed?)
if @enterprise_set.save
flash[:success] = I18n.t(:enterprise_bulk_update_success_notice)
# 18-3-2015: It seems that the form for this action sometimes loads bogus values for
# the 'sells' field, and submitting that form results in a bunch of enterprises with
# values that have mysteriously changed. This statement is here to help debug that
# issue, and should be removed (along with its display in index.html.haml) when the
# issue has been resolved.
flash[:action] = "#{I18n.t(:updated)} #{pluralize(touched_enterprises.count, 'enterprise')}: #{touched_enterprises.map(&:name).join(', ')}"
redirect_to main_app.admin_enterprises_path
else
touched_enterprises = @enterprise_set.collection.select(&:changed?)
@enterprise_set.collection.select! { |e| touched_enterprises.include? e }
flash[:error] = I18n.t(:enterprise_bulk_update_error)
render :index

View File

@@ -1,5 +1,5 @@
require 'open_food_network/referer_parser'
require 'spree/authentication_helpers'
require_dependency 'spree/authentication_helpers'
class ApplicationController < ActionController::Base
protect_from_forgery

View File

@@ -217,7 +217,11 @@ module Spree
end
def render_report(header, table, create_csv, csv_file_name)
send_data csv_report(header, table), filename: csv_file_name if create_csv
if create_csv
@csv_report = csv_report(header, table)
send_data @csv_report, filename: csv_file_name
end
@header = header
@table = table
# Rendering HTML is the default.

View File

@@ -70,7 +70,7 @@ class SubscriptionPlacementJob
end
def unavailable_stock_lines_for(order)
order.line_items.where('variant_id NOT IN (?)', available_variants_for(order))
order.line_items.where('variant_id NOT IN (?)', available_variants_for(order).select(&:id))
end
def available_variants_for(order)

View File

@@ -319,7 +319,7 @@ class Enterprise < ActiveRecord::Base
def distributed_taxons
Spree::Taxon.
joins(:products).
where('spree_products.id IN (?)', Spree::Product.in_distributor(self)).
where('spree_products.id IN (?)', Spree::Product.in_distributor(self).select(&:id)).
select('DISTINCT spree_taxons.*')
end
@@ -335,7 +335,7 @@ class Enterprise < ActiveRecord::Base
def supplied_taxons
Spree::Taxon.
joins(:products).
where('spree_products.id IN (?)', Spree::Product.in_supplier(self)).
where('spree_products.id IN (?)', Spree::Product.in_supplier(self).select(&:id)).
select('DISTINCT spree_taxons.*')
end

View File

@@ -25,7 +25,7 @@ class EnterpriseFee < ActiveRecord::Base
if user.has_spree_role?('admin')
where(nil)
else
where('enterprise_id IN (?)', user.enterprises)
where('enterprise_id IN (?)', user.enterprises.select(&:id))
end
}

View File

@@ -22,7 +22,7 @@ class EnterpriseRelationship < ActiveRecord::Base
}
scope :involving_enterprises, ->(enterprises) {
where('parent_id IN (?) OR child_id IN (?)', enterprises, enterprises)
where('parent_id IN (?) OR child_id IN (?)', enterprises.select(&:id), enterprises.select(&:id))
}
scope :permitting, ->(enterprise_ids) { where('child_id IN (?)', enterprise_ids) }

View File

@@ -49,7 +49,7 @@ class Exchange < ActiveRecord::Base
}
scope :with_product, lambda { |product|
joins(:exchange_variants).
where('exchange_variants.variant_id IN (?)', product.variants_including_master)
where('exchange_variants.variant_id IN (?)', product.variants_including_master.select(&:id))
}
scope :by_enterprise_name, -> {
joins('INNER JOIN enterprises AS sender ON (sender.id = exchanges.sender_id)').

View File

@@ -62,7 +62,9 @@ Spree::Order.class_eval do
# Find orders that are distributed by the user or have products supplied by the user
# WARNING: This only filters orders, you'll need to filter line items separately using LineItem.managed_by
with_line_items_variants_and_products_outer.
where('spree_orders.distributor_id IN (?) OR spree_products.supplier_id IN (?)', user.enterprises, user.enterprises).
where('spree_orders.distributor_id IN (?) OR spree_products.supplier_id IN (?)',
user.enterprises.select(&:id),
user.enterprises.select(&:id)).
select('DISTINCT spree_orders.*')
end
}
@@ -71,7 +73,7 @@ Spree::Order.class_eval do
if user.has_spree_role?('admin')
where(nil)
else
where('spree_orders.distributor_id IN (?)', user.enterprises)
where('spree_orders.distributor_id IN (?)', user.enterprises.select(&:id))
end
}
@@ -81,6 +83,10 @@ Spree::Order.class_eval do
joins('LEFT OUTER JOIN spree_products ON (spree_products.id = spree_variants.product_id)')
}
scope :with_line_items_variants_and_products, lambda {
joins(line_items: { variant: :product })
}
scope :not_state, lambda { |state|
where("state != ?", state)
}

View File

@@ -18,7 +18,7 @@ Spree::PaymentMethod.class_eval do
where(nil)
else
joins(:distributors).
where('distributors_payment_methods.distributor_id IN (?)', user.enterprises).
where('distributors_payment_methods.distributor_id IN (?)', user.enterprises.select(&:id)).
select('DISTINCT spree_payment_methods.*')
end
}

View File

@@ -13,7 +13,7 @@ Spree::ShippingMethod.class_eval do
where(nil)
else
joins(:distributors).
where('distributors_shipping_methods.distributor_id IN (?)', user.enterprises).
where('distributors_shipping_methods.distributor_id IN (?)', user.enterprises.select(&:id)).
select('DISTINCT spree_shipping_methods.*')
end
}

View File

@@ -48,7 +48,7 @@ Spree::Variant.class_eval do
}
scope :for_distribution, lambda { |order_cycle, distributor|
where('spree_variants.id IN (?)', order_cycle.variants_distributed_by(distributor))
where('spree_variants.id IN (?)', order_cycle.variants_distributed_by(distributor).select(&:id))
}
scope :visible_for, lambda { |enterprise|

View File

@@ -10,7 +10,7 @@ module Permissions
# Find orders that the user can see
def visible_orders
Spree::Order.
with_line_items_variants_and_products_outer.
with_line_items_variants_and_products.
where(visible_orders_where_values)
end

View File

@@ -1,7 +1,3 @@
-# For purposes of debugging bulk_update. See Admin/Enterprises#bulk_update.
- if flash[:action]
%p= flash[:action]
= form_for @enterprise_set, url: main_app.bulk_update_admin_enterprises_path do |f|
%table#listing_enterprises.index
%colgroup

View File

@@ -1285,6 +1285,7 @@ ca:
saving_credit_card: Desant la targeta de crèdit...
card_has_been_removed: "S'ha eliminat la teva targeta (número: %{number})"
card_could_not_be_removed: Ho sentim, no s'ha pogut eliminar la targeta
invalid_credit_card: "Targeta de crèdit no vàlida"
ie_warning_headline: "El vostre navegador no està actualitzat :-("
ie_warning_text: "Per obtenir la millor experiència a Open Food Network et recomanem que actualitzis el teu navegador:"
ie_warning_chrome: Descarrega Chrome
@@ -2276,6 +2277,7 @@ ca:
enterprise_register_success_notice: "Enhorabona! El registre de %{enterprise} s'ha completat!"
enterprise_bulk_update_success_notice: "Les organitzacions s'han actualitzat correctament"
enterprise_bulk_update_error: 'No s''ha pogut actualitzar'
enterprise_shop_show_error: "La botiga que busqueu no existeix o està inactiva a OFN. Consulteu altres botigues."
order_cycles_create_notice: 'S''ha creat el cicle de comanda.'
order_cycles_update_notice: 'S''ha actualitzat el cicle de comanda.'
order_cycles_bulk_update_notice: 'S''han actualitzat els cicles de comanda.'
@@ -2430,6 +2432,12 @@ ca:
severity: Severitat
description: Descripció
resolve: Resoldre
exchange_products:
load_more_variants: "Carregueu més variants"
load_all_variants: "Carregueu totes les variants"
select_all_variants: "Seleccioneu totes les %{total_number_of_variants} variants"
variants_loaded: "%{num_of_variants_loaded} de %{total_number_of_variants} variants carregades"
loading_variants: "Carregant variants"
tag_rules:
shipping_method_tagged_top: "Els mètodes d'enviament etiquetats"
shipping_method_tagged_bottom: "son:"
@@ -2588,6 +2596,73 @@ ca:
signup_or_login: "Comenceu registrant-vos (o iniciant sessió)"
have_an_account: "Ja tens un compte?"
action_login: "Inicia la sessió ara."
inflections:
each:
one: "cadascun"
other: "cadascun"
bunch:
one: "munt"
other: "grapats"
pack:
one: "paquet"
other: "paquets"
box:
one: "Caixa"
other: "caixes"
bottle:
one: "ampolla"
other: "ampolles"
jar:
one: "gerro"
other: "pots"
head:
one: "cap"
other: "caps"
bag:
one: "bossa"
other: "bosses"
loaf:
one: "pa"
other: "barres"
single:
one: "solter"
other: "únics"
tub:
one: "tina"
other: "cubells"
item:
one: "article"
other: "articles"
dozen:
one: "dotzena"
other: "dotzenes"
unit:
one: "unitat"
other: "unitats"
serve:
one: "servir"
other: "porcions"
tray:
one: "safata"
other: "safates"
piece:
one: "peça"
other: "peces"
pot:
one: "pot"
other: "pots"
bundle:
one: "paquet"
other: "paquets"
flask:
one: "matràs"
other: "ampolleta"
basket:
one: "cistella"
other: "cistelles"
sack:
one: "sac"
other: "sacs"
producers:
signup:
start_free_profile: "Comença amb un perfil gratuït i amplia'l quan estiguis preparada."

View File

@@ -2274,6 +2274,7 @@ en_FR:
enterprise_register_success_notice: "Congratulations! Registration for %{enterprise} is complete!"
enterprise_bulk_update_success_notice: "Enterprises updated successfully"
enterprise_bulk_update_error: 'Update failed'
enterprise_shop_show_error: "The shop you are looking for doesn't exist or is inactive on OFN. Please check other shops."
order_cycles_create_notice: 'Your order cycle has been created.'
order_cycles_update_notice: 'Your order cycle has been updated.'
order_cycles_bulk_update_notice: 'Order cycles have been updated.'

View File

@@ -701,7 +701,7 @@ fr:
enable_subscriptions_tip: "Activer la fonction abonnements?"
enable_subscriptions_false: "Désactivé"
enable_subscriptions_true: "Activé"
shopfront_message: "Message d'accueil boutique ouverte"
shopfront_message: "Message d'accueil"
shopfront_message_placeholder: >
Vous pouvez indiquer ici un message de bienvenue ou un message expliquant
les particularités de votre boutique. Ce message s'affiche dans l'onglet
@@ -2221,7 +2221,7 @@ fr:
no_change_to_save: "Pas de changement à sauvegarder"
user_invited: "%{email}a été invité à gérer cette entreprise"
add_manager: "Ajouter un utilisateur existant"
users: "Utilisateurs"
users: "Gestionnaires"
about: "A propos"
images: "Images"
web: "Web"
@@ -2278,6 +2278,7 @@ fr:
enterprise_register_success_notice: "Bravo ! L'entreprise %{enterprise} est maintenant inscrite sur Open Food France :-)"
enterprise_bulk_update_success_notice: "Entreprises mises à jour avec succès"
enterprise_bulk_update_error: 'Echec dans la mise à jour'
enterprise_shop_show_error: "La boutique que vous recherchez n'existe pas ou est inactive. Veuillez sélectionner une boutique depuis la liste ci-dessous."
order_cycles_create_notice: 'Votre cycle de vente a été créé.'
order_cycles_update_notice: 'Votre cycle de vente a été mis à jour.'
order_cycles_bulk_update_notice: 'Des cycles de vente ont été mis à jour.'

View File

@@ -2274,6 +2274,7 @@ nb:
enterprise_register_success_notice: "Gratulerer! Registrering for %{enterprise} er fullført!"
enterprise_bulk_update_success_notice: "Bedrifter oppdatert"
enterprise_bulk_update_error: 'Oppdatering mislyktes'
enterprise_shop_show_error: "Butikken du leter etter eksisterer ikke eller er inaktiv på OFN. Sjekk gjerne ut andre butikker."
order_cycles_create_notice: 'Din bestillingsrunde er opprettet.'
order_cycles_update_notice: 'Din bestillingsrunde har blitt oppdatert.'
order_cycles_bulk_update_notice: 'Bestillingsrundene er oppdatert.'

View File

@@ -2273,6 +2273,7 @@ pt_BR:
enterprise_register_success_notice: "Parabéns! O registro para %{enterprise} está completo!"
enterprise_bulk_update_success_notice: "Iniciativas atualizadas com sucesso"
enterprise_bulk_update_error: 'Atualização falhou'
enterprise_shop_show_error: "A loja que você está procurando não existe na OFN ou está inativa. Por favor, busque por outras lojas. "
order_cycles_create_notice: 'Seu ciclo de pedidos foi criado.'
order_cycles_update_notice: 'Seu ciclo de pedidos foi atualizado.'
order_cycles_bulk_update_notice: 'Ciclos de pedidos foram atualizados.'

View File

@@ -68,7 +68,7 @@ module OpenFoodNetwork
else
orders.
where('spree_orders.id NOT IN (?)',
@permissions.editable_orders)
@permissions.editable_orders.select(&:id))
end
end

View File

@@ -150,7 +150,7 @@ module OpenFoodNetwork
receiver = @order_cycle.coordinator
exchange = find_exchange(sender.id, receiver.id, true)
requested_ids = attrs[:variants].select{ |_k, v| v }.keys.map(&:to_i) # Only the ids the user has requested
requested_ids = variants_to_a(attrs[:variants]) # Only the ids the user has requested
existing_ids = exchange.present? ? exchange.variants.pluck(:id) : [] # The ids that already exist
editable_ids = editable_variant_ids_for_incoming_exchange_between(sender, receiver) # The ids we are allowed to add/remove
@@ -167,7 +167,7 @@ module OpenFoodNetwork
receiver = Enterprise.find(attrs[:enterprise_id])
exchange = find_exchange(sender.id, receiver.id, false)
requested_ids = attrs[:variants].select{ |_k, v| v }.keys.map(&:to_i) # Only the ids the user has requested
requested_ids = variants_to_a(attrs[:variants]) # Only the ids the user has requested
existing_ids = exchange.present? ? exchange.variants.pluck(:id) : [] # The ids that already exist
editable_ids = editable_variant_ids_for_outgoing_exchange_between(sender, receiver) # The ids we are allowed to add/remove
@@ -185,7 +185,9 @@ module OpenFoodNetwork
end
def variants_to_a(variants)
variants.select { |_k, v| v }.keys.map(&:to_i).sort
return [] unless variants
variants.select { |_k, v| v }.keys.map(&:to_i)
end
end
end

View File

@@ -10,19 +10,6 @@ describe Admin::SchedulesController, type: :controller do
let!(:coordinated_schedule) { create(:schedule, order_cycles: [coordinated_order_cycle] ) }
let!(:uncoordinated_schedule) { create(:schedule, order_cycles: [other_order_cycle] ) }
context "html" do
context "where I manage an order cycle coordinator" do
before do
allow(controller).to receive_messages spree_current_user: managed_coordinator.owner
end
it "returns an empty @collection" do
spree_get :index, format: :html
expect(assigns(:collection)).to eq []
end
end
end
context "json" do
context "where I manage an order cycle coordinator" do
before do

View File

@@ -253,13 +253,9 @@ describe Api::ProductsController, type: :controller do
end
it "filters results by import_date" do
product.variants.first.import_date = 1.day.ago
product2.variants.first.import_date = 2.days.ago
product3.variants.first.import_date = 1.day.ago
product.save
product2.save
product3.save
product.variants.first.update_attribute :import_date, 1.day.ago
product2.variants.first.update_attribute :import_date, 2.days.ago
product3.variants.first.update_attribute :import_date, 1.day.ago
api_get :bulk_products, { page: 1, per_page: 15, import_date: 1.day.ago.to_date.to_s }, format: :json
expect(returned_product_ids).to eq [product3.id, product.id]

View File

@@ -0,0 +1,249 @@
require 'spec_helper'
describe Spree::Admin::ReportsController, type: :controller do
let(:csv) do
<<-CSV.strip_heredoc
Hub,Producer,Product,Variant,Amount,Curr. Cost per Unit,Total Cost,Total Shipping Cost,Shipping Method
Mary's Online Shop,Freddy's Farm Shop,Beef - 5kg Trays,1g,1,12.0,12.0,"",Shipping Method
Mary's Online Shop,Freddy's Farm Shop,Fuji Apple,2g,1,4.0,4.0,"",Shipping Method
Mary's Online Shop,Freddy's Farm Shop,Fuji Apple,5g,5,12.0,60.0,"",Shipping Method
Mary's Online Shop,Freddy's Farm Shop,Fuji Apple,8g,3,15.0,45.0,"",Shipping Method
"",TOTAL,"","","","",121.0,2.0,""
CSV
end
before do
DefaultStockLocation.create!
delivery = marys_online_shop.shipping_methods.new(
name: "Home delivery",
require_ship_address: true,
calculator_type: "Spree::Calculator::FlatRate",
distributor_ids: [marys_online_shop.id]
)
delivery.shipping_categories << DefaultShippingCategory.find_or_create
delivery.calculator.preferred_amount = 2
delivery.save!
end
let(:taxonomy) { Spree::Taxonomy.create!(name: 'Products') }
let(:meat) do
Spree::Taxon.create!(name: 'Meat and Fish', parent_id: taxonomy.root.id, taxonomy_id: taxonomy.id)
end
let(:fruit) do
Spree::Taxon.create!(name: 'Fruit', parent_id: taxonomy.root.id, taxonomy_id: taxonomy.id)
end
let(:calculator) { Calculator::FlatPercentPerItem.new(preferred_flat_percent: 10) }
let(:mary) do
password = Spree::User.friendly_token
Spree::User.create!(
email: 'mary_retailer@example.org',
password: password,
password_confirmation: password,
confirmation_sent_at: Time.zone.now,
confirmed_at: Time.zone.now
)
end
let(:marys_online_shop) do
Enterprise.create!(
name: "Mary's Online Shop",
owner: mary,
is_primary_producer: false,
sells: "any",
address: create(:address)
)
end
before do
fee = marys_online_shop.enterprise_fees.new(
fee_type: "sales", name: "markup", inherits_tax_category: true
)
fee.calculator = calculator
fee.save!
end
let(:freddy) do
password = Spree::User.friendly_token
Spree::User.create!(
email: 'freddy_shop_farmer@example.org',
password: password,
password_confirmation: password,
confirmation_sent_at: Time.zone.now,
confirmed_at: Time.zone.now
)
end
let(:freddys_farm_shop) do
Enterprise.create!(
name: "Freddy's Farm Shop",
owner: freddy,
is_primary_producer: true,
sells: "own",
address: create(:address)
)
end
before do
fee = freddys_farm_shop.enterprise_fees.new(
fee_type: "sales", name: "markup", inherits_tax_category: true,
)
fee.calculator = calculator
fee.save!
end
let!(:beef) do
product = Spree::Product.new(
name: 'Beef - 5kg Trays',
price: 50.00,
supplier_id: freddys_farm_shop.id,
primary_taxon_id: meat.id,
variant_unit: "weight",
variant_unit_scale: 1,
unit_value: 1,
)
product.shipping_category = DefaultShippingCategory.find_or_create
product.save!
product.variants.first.update_attribute(:on_demand, true)
InventoryItem.create!(
enterprise: marys_online_shop,
variant: product.variants.first,
visible: true
)
VariantOverride.create!(
variant: product.variants.first,
hub: marys_online_shop,
price: 12,
on_demand: false,
count_on_hand: 5
)
product
end
let!(:apple) do
product = Spree::Product.new(
name: 'Fuji Apple',
price: 5.00,
supplier_id: freddys_farm_shop.id,
primary_taxon_id: fruit.id,
variant_unit: "weight",
variant_unit_scale: 1,
unit_value: 1,
shipping_category: DefaultShippingCategory.find_or_create
)
product.shipping_category = DefaultShippingCategory.find_or_create
product.save!
product.variants.first.update_attribute :on_demand, true
VariantOverride.create!(
variant: product.variants.first,
hub: marys_online_shop,
price: 12,
on_demand: false,
count_on_hand: 5
)
product
end
let!(:apple_variant_2) do
variant = apple.variants.create!(weight: 0.0, unit_value: 2.0, price: 4.0)
VariantOverride.create!(
variant: variant, hub: marys_online_shop, on_demand: false, count_on_hand: 4
)
variant
end
let!(:apple_variant_5) do
variant = apple.variants.create!(weight: 0.0, unit_value: 5.0, price: 12.0)
VariantOverride.create!(
variant: variant, hub: marys_online_shop, on_demand: false, count_on_hand: 5
)
variant.update_attribute :on_demand, true
variant
end
let!(:apple_variant_8) do
variant = apple.variants.create!(weight: 0.0, unit_value: 8.0, price: 15.0)
VariantOverride.create!(
variant: variant, hub: marys_online_shop, on_demand: false, count_on_hand: 3
)
variant.update_attribute :on_demand, true
variant
end
let!(:beef_variant) do
variant = beef.variants.first
OpenFoodNetwork::ScopeVariantToHub.new(marys_online_shop).scope(variant)
variant
end
let!(:order_cycle) do
cycle = OrderCycle.create!(
name: "Mary's Online Shop OC",
orders_open_at: 1.day.ago,
orders_close_at: 1.month.from_now,
coordinator: marys_online_shop
)
cycle.coordinator_fees << marys_online_shop.enterprise_fees.first
incoming = Exchange.create!(
order_cycle: cycle, sender: freddys_farm_shop, receiver: cycle.coordinator, incoming: true
)
outgoing = Exchange.create!(
order_cycle: cycle, sender: cycle.coordinator, receiver: marys_online_shop, incoming: false
)
freddys_farm_shop.supplied_products.each do |product|
incoming.variants << product.variants.first
outgoing.variants << product.variants.first
end
cycle
end
let(:order) do
create(
:order,
distributor: marys_online_shop,
order_cycle: order_cycle,
ship_address: create(:address)
)
end
before do
order.add_variant(beef_variant, 1, nil, order.currency)
order.add_variant(apple_variant_2, 1, nil, order.currency)
order.add_variant(apple_variant_5, 5, nil, order.currency)
order.add_variant(apple_variant_8, 3, nil, order.currency)
order.create_proposed_shipments
order.finalize!
order.completed_at = Time.zone.parse("2020-02-05 00:00:00 +1100")
order.save
allow(controller).to receive(:spree_current_user).and_return(mary)
end
it 'returns the right CSV' do
spree_post :orders_and_fulfillment, {
q: {
completed_at_gt: "2020-01-11 00:00:00 +1100",
completed_at_lt: "2020-02-12 00:00:00 +1100",
distributor_id_in: [marys_online_shop.id],
order_cycle_id_in: [""]
},
report_type: "order_cycle_distributor_totals_by_supplier",
csv: true
}
csv_report = assigns(:csv_report)
report_lines = csv_report.split("\n")
csv_fixture_lines = csv.split("\n")
expect(report_lines[0]).to eq(csv_fixture_lines[0])
expect(report_lines[1]).to eq(csv_fixture_lines[1])
expect(report_lines[2]).to eq(csv_fixture_lines[2])
expect(report_lines[3]).to eq(csv_fixture_lines[3])
expect(report_lines[4]).to eq(csv_fixture_lines[4])
expect(report_lines[5]).to eq(csv_fixture_lines[5])
end
end

View File

@@ -6,8 +6,8 @@ module Stock
subject(:package) { Package.new(stock_location, order, contents) }
let(:enterprise) { build(:enterprise) }
let(:other_enterprise) { build(:enterprise) }
let(:enterprise) { create(:enterprise) }
let(:other_enterprise) { create(:enterprise) }
let(:order) { build(:order, distributor: enterprise) }