mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-16 19:16:49 +00:00
Compare commits
38 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8ccc8dfaf6 | ||
|
|
55b32c828c | ||
|
|
25dfd8ad40 | ||
|
|
2a5311493f | ||
|
|
57ac28cfbd | ||
|
|
fb02043e6e | ||
|
|
30d7cc89fa | ||
|
|
d14b5eb46b | ||
|
|
933b5f1606 | ||
|
|
4c7b8209b9 | ||
|
|
802ac647e3 | ||
|
|
c83bded763 | ||
|
|
03246d425d | ||
|
|
7585e3d1d6 | ||
|
|
50cdda7c63 | ||
|
|
d0af046e59 | ||
|
|
5811f3ead1 | ||
|
|
d7d3c9ea53 | ||
|
|
a02cc1de34 | ||
|
|
2184c7c06b | ||
|
|
928bf0d9c7 | ||
|
|
0d02b2afcf | ||
|
|
1e76f3f744 | ||
|
|
7c3a0a292f | ||
|
|
c5ca0976a5 | ||
|
|
be7b3d5a12 | ||
|
|
0042ab2f28 | ||
|
|
53a63775fe | ||
|
|
461b1b26f3 | ||
|
|
f13d7d6845 | ||
|
|
7fdaa0f0c7 | ||
|
|
af8369ae1b | ||
|
|
64d83bfc4d | ||
|
|
b528903aa8 | ||
|
|
38215c2a88 | ||
|
|
4c3916a93d | ||
|
|
03fac6f285 | ||
|
|
1eba17f048 |
@@ -211,7 +211,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)
|
||||
@@ -467,7 +467,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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -63,8 +63,6 @@ class EnterprisesController < BaseController
|
||||
end
|
||||
|
||||
def reset_order
|
||||
distributor = Enterprise.is_distributor.find_by_permalink(params[:id]) ||
|
||||
Enterprise.is_distributor.find(params[:id])
|
||||
order = current_order(true)
|
||||
|
||||
reset_distributor(order, distributor)
|
||||
@@ -74,6 +72,14 @@ class EnterprisesController < BaseController
|
||||
reset_order_cycle(order, distributor)
|
||||
|
||||
order.save!
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
flash[:error] = I18n.t(:enterprise_shop_show_error)
|
||||
redirect_to shops_path
|
||||
end
|
||||
|
||||
def distributor
|
||||
@distributor ||= Enterprise.is_distributor.find_by_permalink(params[:id]) ||
|
||||
Enterprise.is_distributor.find(params[:id])
|
||||
end
|
||||
|
||||
def reset_distributor(order, distributor)
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -321,7 +321,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
|
||||
|
||||
@@ -337,7 +337,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
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ class EnterpriseFee < ActiveRecord::Base
|
||||
if user.has_spree_role?('admin')
|
||||
scoped
|
||||
else
|
||||
where('enterprise_id IN (?)', user.enterprises)
|
||||
where('enterprise_id IN (?)', user.enterprises.select(&:id))
|
||||
end
|
||||
}
|
||||
|
||||
|
||||
@@ -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) }
|
||||
|
||||
@@ -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)').
|
||||
|
||||
@@ -122,7 +122,6 @@ module ProductImport
|
||||
|
||||
def save_new_inventory_item(entry)
|
||||
new_item = entry.product_object
|
||||
assign_defaults(new_item, entry)
|
||||
new_item.import_date = @import_time
|
||||
|
||||
if new_item.valid? && new_item.save
|
||||
@@ -136,7 +135,6 @@ module ProductImport
|
||||
|
||||
def save_existing_inventory_item(entry)
|
||||
existing_item = entry.product_object
|
||||
assign_defaults(existing_item, entry)
|
||||
existing_item.import_date = @import_time
|
||||
|
||||
if existing_item.valid? && existing_item.save
|
||||
@@ -164,7 +162,6 @@ module ProductImport
|
||||
product = Spree::Product.new
|
||||
product.assign_attributes(entry.attributes.except('id', 'on_hand', 'on_demand'))
|
||||
product.supplier_id = entry.producer_id
|
||||
assign_defaults(product, entry)
|
||||
|
||||
if product.save
|
||||
ensure_variant_updated(product, entry)
|
||||
@@ -179,7 +176,6 @@ module ProductImport
|
||||
|
||||
def save_variant(entry)
|
||||
variant = entry.product_object
|
||||
assign_defaults(variant, entry)
|
||||
variant.import_date = @import_time
|
||||
|
||||
if variant.valid? && variant.save
|
||||
@@ -199,37 +195,6 @@ module ProductImport
|
||||
)
|
||||
end
|
||||
|
||||
def assign_defaults(object, entry)
|
||||
# Assigns a default value for a specified field e.g. category='Vegetables', setting this value
|
||||
# either for all entries (overwrite_all), or only for those entries where the field was blank
|
||||
# in the spreadsheet (overwrite_empty), depending on selected import settings
|
||||
return unless settings.defaults(entry)
|
||||
|
||||
settings.defaults(entry).each do |attribute, setting|
|
||||
next unless setting['active']
|
||||
|
||||
case setting['mode']
|
||||
when 'overwrite_all'
|
||||
object.assign_attributes(attribute => setting['value'])
|
||||
# In case of new products, some attributes are saved on the variant.
|
||||
# We write them to the entry here to be copied to the variant later.
|
||||
if entry.respond_to? "#{attribute}="
|
||||
entry.public_send("#{attribute}=", setting['value'])
|
||||
end
|
||||
when 'overwrite_empty'
|
||||
if object.public_send(attribute).blank? ||
|
||||
((attribute == 'on_hand') &&
|
||||
entry.on_hand_nil)
|
||||
|
||||
object.assign_attributes(attribute => setting['value'])
|
||||
if entry.respond_to? "#{attribute}="
|
||||
entry.public_send("#{attribute}=", setting['value'])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def display_in_inventory(variant_override, is_new = false)
|
||||
unless is_new
|
||||
existing_item = InventoryItem.where(
|
||||
|
||||
@@ -56,7 +56,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
|
||||
}
|
||||
@@ -65,7 +67,7 @@ Spree::Order.class_eval do
|
||||
if user.has_spree_role?('admin')
|
||||
scoped
|
||||
else
|
||||
where('spree_orders.distributor_id IN (?)', user.enterprises)
|
||||
where('spree_orders.distributor_id IN (?)', user.enterprises.select(&:id))
|
||||
end
|
||||
}
|
||||
|
||||
@@ -75,6 +77,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)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ Spree::PaymentMethod.class_eval do
|
||||
scoped
|
||||
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
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ Spree::ShippingMethod.class_eval do
|
||||
scoped
|
||||
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
|
||||
}
|
||||
|
||||
@@ -49,7 +49,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|
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -19,8 +19,7 @@
|
||||
{{ orderCycle.producers.length }}
|
||||
= t('.suppliers')
|
||||
%span{ ng: { hide: 'orderCycle.producers.length > 3', bind: 'orderCycle.producerNames' } }
|
||||
%td.coordinator{ ng: { show: 'columns.coordinator.visible' } }
|
||||
{{ orderCycle.coordinator.name }}
|
||||
%td.coordinator{ ng: { show: 'columns.coordinator.visible', bind: { html: 'orderCycle.coordinator.name'} } }
|
||||
%td.shops{ ng: { show: 'columns.shops.visible' } }
|
||||
%span{'ofn-with-tip' => '{{ orderCycle.shopNames }}', ng: { show: 'orderCycle.shops.length > 3' } }
|
||||
{{ orderCycle.shops.length }}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
%th.hide=t('admin.variant_overrides.index.hide')
|
||||
%tbody{ ng: { repeat: 'product in filteredProducts | limitTo:productLimit' } }
|
||||
%tr{ id: "v_{{variant.id}}", ng: { repeat: 'variant in product.variants | inventoryVariants:hub_id:views' } }
|
||||
%td.producer{ ng: { bind: '::producersByID[product.producer_id].name'} }
|
||||
%td.producer{ ng: { bind: { html: '::producersByID[product.producer_id].name'} } }
|
||||
%td.product{ ng: { bind: '::product.name'} }
|
||||
%td.variant
|
||||
%span{ ng: { bind: '::variant.display_name || ""'} }
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
%tr.product.even
|
||||
%td.producer{ ng: { show: 'columns.producer.visible', bind: '::producersByID[product.producer_id].name'} }
|
||||
%td.producer{ ng: { show: 'columns.producer.visible', bind: { html: '::producersByID[product.producer_id].name'} } }
|
||||
%td.product{ ng: { show: 'columns.product.visible', bind: '::product.name'} }
|
||||
%td.sku{ ng: { show: 'columns.sku.visible' } }
|
||||
%td.price{ ng: { show: 'columns.price.visible' } }
|
||||
|
||||
@@ -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."
|
||||
|
||||
@@ -2412,6 +2412,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using
|
||||
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.'
|
||||
|
||||
@@ -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.'
|
||||
|
||||
@@ -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.'
|
||||
|
||||
@@ -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.'
|
||||
|
||||
@@ -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.'
|
||||
|
||||
@@ -68,7 +68,7 @@ module OpenFoodNetwork
|
||||
else
|
||||
orders.
|
||||
where('spree_orders.id NOT IN (?)',
|
||||
@permissions.editable_orders)
|
||||
@permissions.editable_orders.select(&:id))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -149,7 +149,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
|
||||
|
||||
@@ -166,7 +166,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
|
||||
|
||||
@@ -184,7 +184,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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -139,4 +139,18 @@ describe EnterprisesController, type: :controller do
|
||||
expect(response.status).to be 409
|
||||
end
|
||||
end
|
||||
|
||||
context "checking access on nonexistent enterprise" do
|
||||
before do
|
||||
spree_get :shop, id: "some_nonexistent_enterprise"
|
||||
end
|
||||
|
||||
it "redirects to shops_path" do
|
||||
expect(response).to redirect_to shops_path
|
||||
end
|
||||
|
||||
it "shows a flash message with the error" do
|
||||
expect(request.flash[:error]).to eq(I18n.t(:enterprise_shop_show_error))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -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
|
||||
@@ -714,66 +714,6 @@ describe ProductImport::ProductImporter do
|
||||
expect(cabbage.count_on_hand).to eq 0 # In enterprise, not in file (reset)
|
||||
expect(lettuce.count_on_hand).to eq 96 # In different enterprise; unchanged
|
||||
end
|
||||
|
||||
it "can overwrite fields with selected defaults when importing to product list" do
|
||||
csv_data = CSV.generate do |csv|
|
||||
csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type", "tax_category_id", "available_on", "shipping_category"]
|
||||
csv << ["Carrots", "User Enterprise", "Vegetables", "5", "3.20", "500", "g", tax_category.id, "", shipping_category.name]
|
||||
csv << ["Potatoes", "User Enterprise", "Vegetables", "6", "6.50", "1", "kg", "", "", shipping_category.name]
|
||||
end
|
||||
settings = { enterprise.id.to_s => {
|
||||
'import_into' => 'product_list',
|
||||
'defaults' => {
|
||||
'on_hand' => {
|
||||
'active' => true,
|
||||
'mode' => 'overwrite_all',
|
||||
'value' => '9000'
|
||||
},
|
||||
'tax_category_id' => {
|
||||
'active' => true,
|
||||
'mode' => 'overwrite_empty',
|
||||
'value' => tax_category2.id
|
||||
},
|
||||
'shipping_category_id' => {
|
||||
'active' => true,
|
||||
'mode' => 'overwrite_all',
|
||||
'value' => shipping_category.id
|
||||
},
|
||||
'available_on' => {
|
||||
'active' => true,
|
||||
'mode' => 'overwrite_all',
|
||||
'value' => '2020-01-01'
|
||||
}
|
||||
}
|
||||
} }
|
||||
|
||||
importer = import_data csv_data, settings: settings
|
||||
|
||||
importer.validate_entries
|
||||
entries = JSON.parse(importer.entries_json)
|
||||
|
||||
expect(filter('valid', entries)).to eq 2
|
||||
expect(filter('invalid', entries)).to eq 0
|
||||
expect(filter('create_product', entries)).to eq 2
|
||||
|
||||
importer.save_entries
|
||||
|
||||
expect(importer.products_created_count).to eq 2
|
||||
expect(importer.updated_ids).to be_a(Array)
|
||||
expect(importer.updated_ids.count).to eq 2
|
||||
|
||||
carrots = Spree::Product.find_by_name('Carrots')
|
||||
expect(carrots.on_hand).to eq 9000
|
||||
expect(carrots.tax_category_id).to eq tax_category.id
|
||||
expect(carrots.shipping_category_id).to eq shipping_category.id
|
||||
expect(carrots.available_on).to be_within(1.day).of(Time.zone.local(2020, 1, 1))
|
||||
|
||||
potatoes = Spree::Product.find_by_name('Potatoes')
|
||||
expect(potatoes.on_hand).to eq 9000
|
||||
expect(potatoes.tax_category_id).to eq tax_category2.id
|
||||
expect(potatoes.shipping_category_id).to eq shipping_category.id
|
||||
expect(potatoes.available_on).to be_within(1.day).of(Time.zone.local(2020, 1, 1))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -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) }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user