diff --git a/.gitignore b/.gitignore index 21ff15e147..88a12db1be 100644 --- a/.gitignore +++ b/.gitignore @@ -33,7 +33,6 @@ public/images public/spree config/abr.yml config/initializers/feature_toggle.rb -config/initializers/db2fog.rb NERD_tree* coverage libpeerconnection.log diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 262f2a21a2..eeeda4a552 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -20,7 +20,6 @@ Layout/AlignArray: Exclude: - 'lib/open_food_network/bulk_coop_report.rb' - 'lib/open_food_network/customers_report.rb' - - 'lib/open_food_network/order_and_distributor_report.rb' - 'lib/open_food_network/orders_and_fulfillments_report.rb' - 'lib/open_food_network/packing_report.rb' - 'spec/lib/open_food_network/order_grouper_spec.rb' diff --git a/Gemfile b/Gemfile index 844e8f33f4..fe95d3e65e 100644 --- a/Gemfile +++ b/Gemfile @@ -27,7 +27,7 @@ gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-0-stable' # - Pass customer email and phone number to PayPal (merged to upstream master) # - Change type of password from string to password to hide it in the form gem 'spree_paypal_express', github: "openfoodfoundation/better_spree_paypal_express", branch: "2-0-stable" -gem 'stripe', '~> 4.11.0' +gem 'stripe' # We need at least this version to have Digicert's root certificate # which is needed for Pin Payments (and possibly others). diff --git a/Gemfile.lock b/Gemfile.lock index 1f69ab413f..0d86913a2c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -860,7 +860,7 @@ DEPENDENCIES spree_paypal_express! spring (= 1.7.2) spring-commands-rspec - stripe (~> 4.11.0) + stripe therubyracer (= 0.12.0) timecop truncate_html diff --git a/app/models/product_import/entry_validator.rb b/app/models/product_import/entry_validator.rb index 39e3d761f9..50d8879d77 100644 --- a/app/models/product_import/entry_validator.rb +++ b/app/models/product_import/entry_validator.rb @@ -258,6 +258,7 @@ module ProductImport new_product = Spree::Product.new new_product.assign_attributes(entry.attributes.except('id')) new_product.supplier_id = entry.producer_id + entry.on_hand = 0 if entry.on_hand.nil? if new_product.valid? entry.validates_as = 'new_product' unless entry.errors? diff --git a/config/initializers/0_depricated_db2fog.rb b/config/initializers/0_depricated_db2fog.rb deleted file mode 100644 index f2a2e76bc9..0000000000 --- a/config/initializers/0_depricated_db2fog.rb +++ /dev/null @@ -1,15 +0,0 @@ -# Depricated: this initializer contains an invalid bucket name. -# Users of DB2fog should be able to configure DB2fog without changing the code. -# -# Name your configuration file `db2fog.rb`. It will be ignored by git. -# And it will overwrite this depricated configuration. -# -# See: https://github.com/yob/db2fog -# -# TODO: Remove this file in a future release. -DB2Fog.config = { - :aws_access_key_id => Spree::Config[:s3_access_key], - :aws_secret_access_key => Spree::Config[:s3_secret], - :directory => "db-backup_#{Spree::Config[:s3_bucket]}", - :provider => 'AWS' -} diff --git a/config/initializers/db2fog.rb b/config/initializers/db2fog.rb new file mode 100644 index 0000000000..7c7a2d6d39 --- /dev/null +++ b/config/initializers/db2fog.rb @@ -0,0 +1,7 @@ +# See: https://github.com/yob/db2fog +DB2Fog.config = { + :aws_access_key_id => Spree::Config[:s3_access_key], + :aws_secret_access_key => Spree::Config[:s3_secret], + :directory => Spree::Config[:s3_bucket], + :provider => 'AWS' +} diff --git a/config/locales/en.yml b/config/locales/en.yml index efdf88191a..6d54e04df9 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2935,6 +2935,9 @@ See the %{link} to find out more about %{sitename}'s features and to start using title: "Distribution" distributor: "Distributor:" order_cycle: "Order cycle:" + line_item_adjustments: "Line Item Adjustments" + order_adjustments: "Order Adjustments" + order_total: "Order Total" overview: products: active_products: diff --git a/lib/open_food_network/order_and_distributor_report.rb b/lib/open_food_network/order_and_distributor_report.rb index 1663d483a4..29b9772c96 100644 --- a/lib/open_food_network/order_and_distributor_report.rb +++ b/lib/open_food_network/order_and_distributor_report.rb @@ -10,7 +10,8 @@ module OpenFoodNetwork end def header - [I18n.t(:report_header_order_date), + [ + I18n.t(:report_header_order_date), I18n.t(:report_header_order_id), I18n.t(:report_header_customer_name), I18n.t(:report_header_customer_email), @@ -28,7 +29,9 @@ module OpenFoodNetwork I18n.t(:report_header_distributor_address), I18n.t(:report_header_distributor_city), I18n.t(:report_header_distributor_postcode), - I18n.t(:report_header_shipping_instructions)] + I18n.t(:report_header_shipping_method), + I18n.t(:report_header_shipping_instructions) + ] end def search @@ -95,6 +98,7 @@ module OpenFoodNetwork order.distributor.address.address1, order.distributor.address.city, order.distributor.address.zipcode, + order.shipping_method.name, order.special_instructions ] end diff --git a/spec/lib/open_food_network/order_and_distributor_report_spec.rb b/spec/lib/open_food_network/order_and_distributor_report_spec.rb index f943aabdd0..5602b174ae 100644 --- a/spec/lib/open_food_network/order_and_distributor_report_spec.rb +++ b/spec/lib/open_food_network/order_and_distributor_report_spec.rb @@ -11,15 +11,16 @@ module OpenFoodNetwork 'Customer Name', 'Customer Email', 'Customer Phone', 'Customer City', 'SKU', 'Item name', 'Variant', 'Quantity', 'Max Quantity', 'Cost', 'Shipping Cost', 'Payment Method', - 'Distributor', 'Distributor address', 'Distributor city', 'Distributor postcode', 'Shipping instructions']) + 'Distributor', 'Distributor address', 'Distributor city', 'Distributor postcode', 'Shipping Method', 'Shipping instructions']) end context 'with completed order' do let(:bill_address) { create(:address) } let(:distributor) { create(:distributor_enterprise) } let(:product) { create(:product) } + let(:shipping_method) { create(:shipping_method) } let(:shipping_instructions) { 'pick up on thursday please!' } - let(:order) { create(:order, state: 'complete', completed_at: Time.zone.now, distributor: distributor, bill_address: bill_address, special_instructions: shipping_instructions) } + let(:order) { create(:order, state: 'complete', completed_at: Time.zone.now, distributor: distributor, bill_address: bill_address, shipping_method: shipping_method, special_instructions: shipping_instructions) } let(:payment_method) { create(:payment_method, distributors: [distributor]) } let(:payment) { create(:payment, payment_method: payment_method, order: order) } let(:line_item) { create(:line_item_with_shipment, product: product, order: order) } @@ -53,6 +54,7 @@ module OpenFoodNetwork distributor.address.address1, distributor.address.city, distributor.address.zipcode, + shipping_method.name, shipping_instructions ]) end diff --git a/spec/lib/open_food_network/products_and_inventory_report_spec.rb b/spec/lib/open_food_network/products_and_inventory_report_spec.rb index 1235c9e001..b70d542d15 100644 --- a/spec/lib/open_food_network/products_and_inventory_report_spec.rb +++ b/spec/lib/open_food_network/products_and_inventory_report_spec.rb @@ -134,6 +134,32 @@ module OpenFoodNetwork subject.stub(:params).and_return(distributor_id: distributor.id) subject.filter(variants).should == [product2.variants.first] end + + it "ignores variant overrides without filter" do + distributor = create(:distributor_enterprise) + product = create(:simple_product, supplier: supplier, price: 5) + variant = product.variants.first + order_cycle = create(:simple_order_cycle, suppliers: [supplier], distributors: [distributor], variants: [product.variants.first]) + create(:variant_override, hub: distributor, variant: variant, price: 2) + + result = subject.filter(variants) + + expect(result.first.price).to eq 5 + end + + it "considers variant overrides with distributor" do + distributor = create(:distributor_enterprise) + product = create(:simple_product, supplier: supplier, price: 5) + variant = product.variants.first + order_cycle = create(:simple_order_cycle, suppliers: [supplier], distributors: [distributor], variants: [product.variants.first]) + create(:variant_override, hub: distributor, variant: variant, price: 2) + + allow(subject).to receive(:params).and_return(distributor_id: distributor.id) + result = subject.filter(variants) + + expect(result.first.price).to eq 2 + end + it "filters to a specific order cycle" do distributor = create(:distributor_enterprise) product1 = create(:simple_product, supplier: supplier) diff --git a/spec/models/product_importer_spec.rb b/spec/models/product_importer_spec.rb index 470d9d5682..41f6ed865f 100644 --- a/spec/models/product_importer_spec.rb +++ b/spec/models/product_importer_spec.rb @@ -52,7 +52,7 @@ describe ProductImport::ProductImporter do csv << ["Potatoes", "User Enterprise", "Vegetables", "6", "6.50", "2", "kg", "", "", shipping_category_id_str] csv << ["Pea Soup", "User Enterprise", "Vegetables", "8", "5.50", "750", "ml", "", "0", shipping_category_id_str] csv << ["Salad", "User Enterprise", "Vegetables", "7", "4.50", "1", "", "bags", "", shipping_category_id_str] - csv << ["Hot Cross Buns", "User Enterprise", "Cake", "7", "3.50", "1", "", "buns", "1", shipping_category_id_str] + csv << ["Hot Cross Buns", "User Enterprise", "Cake", nil, "3.50", "1", "", "buns", "1", shipping_category_id_str] end File.write('/tmp/test-m.csv', csv_data) file = File.new('/tmp/test-m.csv') @@ -124,7 +124,8 @@ describe ProductImport::ProductImporter do buns = Spree::Product.find_by_name('Hot Cross Buns') expect(buns.supplier).to eq enterprise - # buns.on_hand).to eq Infinity + expect(buns.on_hand).to eq Float::INFINITY + expect(buns.count_on_hand).to eq 0 expect(buns.price).to eq 3.50 expect(buns.unit_value).to eq 1 expect(buns.variant_unit).to eq 'items'