Compare commits

..

131 Commits

Author SHA1 Message Date
Matt-Yorkley
1a756cbc6b Merge pull request #4387 from openfoodfoundation/transifex
Transifex
2019-10-23 21:17:20 +01:00
Matt-Yorkley
00e869f40c Merge pull request #4393 from mkllnk/4392-rescue-network-fails
Avoid asking the cloud if an image exists
2019-10-23 16:55:49 +01:00
Transifex-Openfoodnetwork
e849c4867b Updating translations for config/locales/nb.yml 2019-10-23 18:58:07 +11:00
Maikel Linke
ada34d27ca Avoid asking the cloud if an image exists
https://github.com/openfoodfoundation/openfoodnetwork/issues/4392

Amazon's DNS is failing at the moment and some users can't access the
admin panel because of this error.

While `exists?` asks the storage server if the file is actually there,
`file?` just checks if we have the file name stored in the database
and the file should be there. It's much faster and less error prone.
2019-10-23 11:36:20 +11:00
Transifex-Openfoodnetwork
0288dfc992 Updating translations for config/locales/ar.yml 2019-10-23 07:18:46 +11:00
Luis Ramos
02c0b89fa0 Merge pull request #4345 from Matt-Yorkley/shopfront_pagination
Shopfront pagination
2019-10-21 16:02:12 +01:00
Luis Ramos
c9e23154d8 Merge pull request #4352 from tkusuki/fix-translation-in-enterprise-welcome-email
Add missing translation in non English enterprise welcome email
2019-10-21 11:41:53 +01:00
Rachel Arnould
279b633513 Add welcome board to the contributing page 2019-10-21 12:19:01 +02:00
Transifex-Openfoodnetwork
9d0ac79983 Updating translations for config/locales/pt_BR.yml 2019-10-21 11:29:14 +11:00
Matt-Yorkley
7b0c55e15a Ensure producer properties are included in properties results 2019-10-18 21:15:13 +01:00
Matt-Yorkley
cbe2477d04 Fix property filters and improve test coverage 2019-10-18 21:15:13 +01:00
Matt-Yorkley
c730958fe4 Restrict search params passed to ProductsRenderer 2019-10-18 21:15:13 +01:00
Matt-Yorkley
37e5e1923c Improve filter buttons UX 2019-10-18 21:15:13 +01:00
Matt-Yorkley
542c1bf684 #slice :params in controller and rename to :args in service context 2019-10-18 21:15:13 +01:00
Matt-Yorkley
06c896b93b Add spec for Api::ProductSerializer 2019-10-18 21:15:13 +01:00
Matt-Yorkley
6433d69d02 Add comments on scoping ProductsRenderer results 2019-10-18 21:15:13 +01:00
Matt-Yorkley
bf8c632fce Refactor ProductsCtrl request params 2019-10-18 21:15:13 +01:00
Matt-Yorkley
b3c89a9d6c Move OpenFoodNetwork::ProductsRenderer (lib) to ProductsRenderer (service) and refactor 2019-10-18 21:15:13 +01:00
Matt-Yorkley
d45403f1d4 Add specs for Api::OrderCyclesController 2019-10-18 21:15:13 +01:00
Matt-Yorkley
f2affe80cd Reduce assignment branching and complexity for ProductsRenderer#products 2019-10-18 21:15:13 +01:00
Matt-Yorkley
573a69477f Fix filters not updating on OC change 2019-10-18 21:15:13 +01:00
Matt-Yorkley
c6ce516129 Fix prices not updating with new exchange fees when changing OC 2019-10-18 21:15:13 +01:00
Matt-Yorkley
2539b84b33 Fix product.meta_keywords not searchable 2019-10-18 21:15:13 +01:00
Matt-Yorkley
dd6d0d25da Fix problematic feature specs 2019-10-18 21:15:13 +01:00
Matt-Yorkley
c54cff10d4 Adjust API endpoint params 2019-10-18 21:15:13 +01:00
Matt-Yorkley
ab330e882e Remove product cache 2019-10-18 21:15:11 +01:00
Maikel Linke
20cabe6f12 Update from Transifex 2019-10-17 17:11:10 +11:00
Maikel
fe849b8dfd Merge pull request #4367 from openfoodfoundation/transifex
Transifex
2019-10-17 17:07:23 +11:00
Luis Ramos
167b44c30f Merge pull request #4365 from kristinalim/fix/4308-eager_load_associations_in_orders_and_fulfillment_reports
4308 Eager-load associations in Orders and Fulfillment reports
2019-10-16 21:39:30 +01:00
Luis Ramos
ad247e2116 Merge pull request #4268 from luisramos0/add_order_endpoint
Add api/orders/{order_number} API endpoint
2019-10-16 21:22:27 +01:00
Luis Ramos
e46875376e Merge pull request #4168 from mkllnk/4160-product-report-filters
4160 Fix product report filters
2019-10-16 14:47:55 +01:00
Luis Ramos
d7223c508a Merge pull request #4289 from luisramos0/spree_be_config_general
Move general_settings, mail_methods and image_settings from spree_backend to OFN
2019-10-16 12:08:36 +01:00
Kristina Lim
a91a23aa39 Eager-load associations for Orders and Fulfillment report subtypes 2019-10-16 19:06:35 +08:00
Luis Ramos
370f66e36b Merge pull request #4364 from kristinalim/refactor/4308-refactor_orders_and_fulfillment_report_types
4308 Refactor Orders and Fulfillment report subtypes
2019-10-16 10:30:24 +01:00
Luis Ramos
f7cdcf02e0 Merge pull request #4343 from openfoodfoundation/dependabot/bundler/oauth2-1.4.2
Bump oauth2 from 1.4.1 to 1.4.2
2019-10-16 10:29:25 +01:00
Pau Pérez Fabregat
1ee43fb495 Merge pull request #4358 from openfoodfoundation/dependabot/bundler/rspec-rails-3.9.0
Bump rspec-rails from 3.8.2 to 3.9.0
2019-10-15 10:25:23 +02:00
Transifex-Openfoodnetwork
e139d24639 Updating translations for config/locales/en_CA.yml 2019-10-15 12:06:18 +11:00
Luis Ramos
0dfe749496 Merge pull request #4356 from kristinalim/fix/4256-set_dalli_value_max_size
4256 Configure dalli store value max bytes from env variable
2019-10-14 18:41:00 +01:00
Luis Ramos
d6eade6fa3 Merge pull request #4363 from jonleighton/fix-docker-setup
Fix error during first run of docker-compose
2019-10-14 13:38:04 +01:00
Luis Ramos
109aed684e Merge pull request #4344 from openfoodfoundation/dependabot/bundler/ddtrace-0.28.0
Bump ddtrace from 0.27.0 to 0.28.0
2019-10-14 12:39:52 +01:00
Luis Ramos
35d76ac991 Merge pull request #4298 from luisramos0/variant_edit
Make unit description visible in the variant edit page even for products which variant_unit is items
2019-10-13 19:54:41 +01:00
Luis Ramos
1ab9e9d7a5 Merge pull request #4299 from luisramos0/drop_order_ship_method_id
Remove unused field orders.shipping_method_id
2019-10-13 19:54:13 +01:00
Luis Ramos
e5e716e150 Merge pull request #4336 from openfoodfoundation/dependabot/bundler/rubyzip-1.3.0
[Security] Bump rubyzip from 1.2.2 to 1.3.0
2019-10-13 19:53:48 +01:00
Luis Ramos
b6510c3ab6 Merge pull request #4262 from daningenthron/daningenthron/default-shipping-category
Prefill shipping category forms with default values
2019-10-13 19:52:43 +01:00
Transifex-Openfoodnetwork
a158a986c6 Updating translations for config/locales/en_US.yml 2019-10-11 13:06:17 +11:00
Kristina Lim
c7643db66f Remove unnecessary Orders and Fulfillment lines in .rubocop_manual_todo.yml 2019-10-10 21:05:06 +08:00
Kristina Lim
eb8c22aa06 Disable violated cops in Order and Fulfillment report subtypes 2019-10-10 21:01:46 +08:00
Kristina Lim
d0656485d7 Make report_klass in OrdersAndFulfillmentsReport compact 2019-10-10 21:01:46 +08:00
Kristina Lim
640cc1b6d3 Address Metrics/LineLength in Orders and Fulfillments reports 2019-10-10 21:01:45 +08:00
Kristina Lim
d65d17a9f3 Freeze report type string in Order and Fulfillment reports 2019-10-10 21:01:45 +08:00
Kristina Lim
bbea00e431 Delegate methods in Orders and Fulfillment report to report object 2019-10-10 21:01:45 +08:00
Kristina Lim
3cecba70e8 Refactor and memoize report object in Orders and Fulfillment report 2019-10-10 21:01:44 +08:00
Kristina Lim
8bbff09066 Refactor report class in Orders and Fulfillment report 2019-10-10 21:01:44 +08:00
Kristina Lim
a7a89d7ccb Add attr reader for report type in Orders and Fulfillment report 2019-10-10 21:01:44 +08:00
Kristina Lim
3ccf76ff5f Add smoke test for Customer Totals report 2019-10-10 21:01:34 +08:00
Kristina Lim
6004208496 Move specific logic for Customer Totals report to class 2019-10-10 20:05:35 +08:00
Kristina Lim
3ce9c712cf Add smoke test for Distributor Totals by Supplier report 2019-10-10 20:05:35 +08:00
Kristina Lim
bfb0032fd2 Move specific logic for Distributor Totals by Supplier report to class 2019-10-10 20:05:29 +08:00
Kristina Lim
fe37516ead Add smoke test for Supplier Totals by Distributor report 2019-10-10 19:58:49 +08:00
Kristina Lim
289b75e143 Move specific logic for Supplier Totals by Distributor report to class 2019-10-10 19:57:41 +08:00
Kristina Lim
09f0f8c33f Move "order_cycle_supplier_totals" report type to constant 2019-10-10 19:54:29 +08:00
Kristina Lim
8bc1718978 Add smoke test for Supplier Totals report 2019-10-10 19:50:28 +08:00
Kristina Lim
cbfce69a6d Move specific logic for Supplier Totals report to class 2019-10-10 19:48:59 +08:00
Kristina Lim
4e0ecdd44c Rename params in OrdersAndFulfillmentsReport to options 2019-10-10 15:57:51 +08:00
Jon Leighton
23ab9a4bed Fix error during first run of docker-compose
Prior to this commit, the db container would create a database named
“ofn” (the same as $POSTGRES_USER).

Then, when the web container started, it would run `rake db:reset`. This
would load the Rails environment, which ends up requiring some model
files, which eventually end up trying to connect to the
“open_food_network_dev” database, which doesn’t exist. Therefore setting
up the database fails, and it’s impossible to boot the web container.

As a side note, I’m not convinced that bootstrapping the database as
part of the container’s command is the best strategy (if for no other
reason that this will wipe my database every time I run `docker-compose
up`). But this commit doesn’t change that.

What it does is add the $POSTGRES_DB environment variable so that the db
container creates the “open_food_network_dev” database (which is blank).
Then, when `rake db:reset` runs, it’ll successfully connect to this
(empty) database while loading the environment, before deleting and recreating it.

Note that I had to manually delete the `openfoodnetwork_postgres` volume
in order to reset my local state, after making this change.
2019-10-10 12:17:22 +11:00
Maikel Linke
f623446e3e Avoid additional query in inventory reports 2019-10-10 11:11:14 +11:00
Maikel Linke
6944fe1e46 Make order cycle filter chainable with other filters 2019-10-10 10:06:36 +11:00
Maikel Linke
7c9e3d7f06 Spec combination of all variant filters 2019-10-10 10:06:36 +11:00
Matt-Yorkley
da7456e6e0 Remove old shop/products route, action, and spec 2019-10-09 17:27:00 +01:00
Matt-Yorkley
f134cd9473 Extract tag_rule filtering into separate service 2019-10-09 17:26:58 +01:00
Dan Ingenthron
bdcadf9fc6 Update changes to reflect new non-Spree shipping method controller 2019-10-08 18:37:16 -05:00
Dan Ingenthron
9b7139fd45 Add default shipping category during object creation; revert forms 2019-10-08 18:37:16 -05:00
Dan Ingenthron
543e275d2e Add custom shipping category to pass package spec 2019-10-08 18:37:16 -05:00
Dan Ingenthron
560fa6b949 Update shipping category factory with default 2019-10-08 18:37:16 -05:00
Dan Ingenthron
dbf34da87b Rubocop fixes 2019-10-08 18:37:16 -05:00
Dan Ingenthron
d6022062e1 Use default for create product spec; auto-fill field 2019-10-08 18:37:16 -05:00
Dan Ingenthron
b082d3301b Add prechecked category to shipping method spec 2019-10-08 18:37:16 -05:00
Dan Ingenthron
48cd542138 Service spec 2019-10-08 18:37:15 -05:00
Dan Ingenthron
e2d341c9c2 Add default category to seeds 2019-10-08 18:37:15 -05:00
Dan Ingenthron
89873a2640 Add and auto-check default category in shipping method create 2019-10-08 18:37:15 -05:00
Dan Ingenthron
b4be2cc2d4 Add default shipping category service and update create product form 2019-10-08 18:37:15 -05:00
Dan Ingenthron
35f89a9750 Update spec to prefill shipping category in Create form 2019-10-08 18:37:15 -05:00
Dan Ingenthron
592a53b6f5 Remove blank option from shipping category dropdown 2019-10-08 18:37:15 -05:00
dependabot-preview[bot]
eab9d42eb0 Bump rspec-rails from 3.8.2 to 3.9.0
Bumps [rspec-rails](https://github.com/rspec/rspec-rails) from 3.8.2 to 3.9.0.
- [Release notes](https://github.com/rspec/rspec-rails/releases)
- [Changelog](https://github.com/rspec/rspec-rails/blob/master/Changelog.md)
- [Commits](https://github.com/rspec/rspec-rails/compare/v3.8.2...v3.9.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-10-08 20:56:10 +00:00
Kristina Lim
cf05369ca9 Configure dalli store value max bytes from env variable 2019-10-08 17:58:43 +08:00
Matt-Yorkley
e96252f2ed Add tag_rules logic to main query before pagination 2019-10-08 10:11:24 +01:00
Matt-Yorkley
06e1f56ae9 Extract filter list fetching into a separate endpoint 2019-10-08 10:11:24 +01:00
Matt-Yorkley
fe0de98821 Add pagination in Angular and views 2019-10-08 10:11:22 +01:00
luisramos0
a2bc61cb4d Remove unused field orders.shipping_method_id 2019-10-08 09:09:19 +01:00
Thais Kusuki
d997b8f5ee Change translations from enterprise_mailer to lazy lookup 2019-10-07 23:29:11 -03:00
Thais Kusuki
797a3ad091 Add missing translation in non English enterprise welcome email 2019-10-05 12:50:12 -03:00
Matt-Yorkley
01d1e8243c Add pagination to ProductsRenderer 2019-10-04 10:38:43 +01:00
Matt-Yorkley
a1a5c3b7fe Add new Angular OrderCycleResource 2019-10-04 10:38:41 +01:00
Matt-Yorkley
bc826f73a1 Add temporary placeholder for API endpoint 2019-10-03 18:11:40 +01:00
luisramos0
c5a17bcde0 Fix rubocop issues in feature specs related to configuration 2019-10-02 21:26:10 +01:00
luisramos0
b712ec7f13 Transpec feature specs brought from spre_backend 2019-10-02 21:26:09 +01:00
luisramos0
32a7f13dd2 Bring feature specs for configuration pages from spree_backend 2019-10-02 21:26:09 +01:00
luisramos0
713769b497 Fix rubocop issues in mail_methods_controller_spec 2019-10-02 21:26:09 +01:00
luisramos0
495de37620 Fix more rubocop issues in image_settings_controller_spec 2019-10-02 21:26:09 +01:00
luisramos0
05d24cf11a Transpec image_setting_controller_spec 2019-10-02 21:26:09 +01:00
luisramos0
edd84530af Fix simle rubocopo issues in image_settings ctrl spec 2019-10-02 21:26:09 +01:00
luisramos0
6677543de0 bring 2 specs from spree_backend to cover image_settings page and mail_methods page 2019-10-02 21:26:09 +01:00
luisramos0
30aa31252b Fix simple rubocop issues in helpers 2019-10-02 21:26:09 +01:00
luisramos0
b83d74a609 Bring general_settings_helper from spree_backend 2019-10-02 21:26:09 +01:00
luisramos0
d31b50be3d Bring spree/admin configuration routes to ofn 2019-10-02 21:26:09 +01:00
luisramos0
42e3f2f2f4 Convert spree/admin/mail_methods from erb to haml 2019-10-02 21:25:23 +01:00
luisramos0
96737da128 Add spree_backend mail methods views that are missing in ofn 2019-10-02 21:25:23 +01:00
luisramos0
7f9f0d840c Merge decorators into controllers and remove decorators 2019-10-02 21:25:23 +01:00
luisramos0
686840e262 Fix basic rubocop issues in recently added controllers from spree_backend 2019-10-02 21:25:23 +01:00
luisramos0
2377b833ee Bring general settings and image settings controllers that are overrides in ofn to ofn so we can merge them with their decorators in a second step 2019-10-02 21:25:23 +01:00
luisramos0
3f3c33bce6 Fix basic rubocop issues in newly added controller 2019-10-02 21:25:23 +01:00
luisramos0
e35eff95bb Add mail_methods controller from spree_backend related to config 2019-10-02 21:25:23 +01:00
dependabot-preview[bot]
de9476a8a5 Bump ddtrace from 0.27.0 to 0.28.0
Bumps [ddtrace](https://github.com/DataDog/dd-trace-rb) from 0.27.0 to 0.28.0.
- [Release notes](https://github.com/DataDog/dd-trace-rb/releases)
- [Changelog](https://github.com/DataDog/dd-trace-rb/blob/master/CHANGELOG.md)
- [Commits](https://github.com/DataDog/dd-trace-rb/compare/v0.27.0...v0.28.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-10-01 21:12:18 +00:00
dependabot-preview[bot]
bce41a2247 Bump oauth2 from 1.4.1 to 1.4.2
Bumps [oauth2](https://github.com/oauth-xx/oauth2) from 1.4.1 to 1.4.2.
- [Release notes](https://github.com/oauth-xx/oauth2/releases)
- [Changelog](https://github.com/oauth-xx/oauth2/blob/master/CHANGELOG.md)
- [Commits](https://github.com/oauth-xx/oauth2/compare/v1.4.1...v1.4.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-10-01 21:04:45 +00:00
dependabot-preview[bot]
36883bc051 [Security] Bump rubyzip from 1.2.2 to 1.3.0
Bumps [rubyzip](https://github.com/rubyzip/rubyzip) from 1.2.2 to 1.3.0. **This update includes a security fix.**
- [Release notes](https://github.com/rubyzip/rubyzip/releases)
- [Changelog](https://github.com/rubyzip/rubyzip/blob/master/Changelog.md)
- [Commits](https://github.com/rubyzip/rubyzip/compare/v1.2.2...v1.3.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-10-01 09:55:53 +00:00
luisramos0
50731e929e Remove some attributes from test as they are already verified subsequently 2019-09-25 09:54:33 +01:00
luisramos0
baa09b88f7 Fix issue with nil current_order where shipping_method serializer requires a current_order to calculate the shipping fees 2019-09-25 09:52:10 +01:00
luisramos0
2f60a85593 Improve spec/controllers/api/orders_controller_spec, make it more readable 2019-09-23 23:50:42 +01:00
luisramos0
78cf35807a Improve preloading of order query to avoid N+1 queries 2019-09-23 23:50:39 +01:00
luisramos0
eb85dccac1 Remove single letter variable names 2019-09-22 21:07:32 +01:00
luisramos0
f32454b404 Add feature spec to validate unit_description is editable for products with unit items, regression for #3649 2019-09-22 21:02:32 +01:00
luisramos0
591efecde6 Make unit description field visible in the variant edit page even for products which variant_unit is items 2019-09-22 16:42:03 +01:00
luisramos0
24afa21885 Revert "Change products controller to clear variants unit description if variant_unit is items"
This reverts commit 1a4e83d633.
2019-09-22 16:31:26 +01:00
luisramos0
bdb3dd5aaf Fix long lines in app/serializers 2019-09-19 16:32:09 +01:00
luisramos0
25fbab2e37 Use memoized order method 2019-09-19 16:32:09 +01:00
luisramos0
4d37aaac64 Use have_http_status and remove check for error message, that's something for the base_controller test to test 2019-09-19 16:32:09 +01:00
luisramos0
19e28cb14a Make spec/controllers/api/orders_controller_spec more simple assuming adjustments will always come in the same order 2019-09-19 16:32:09 +01:00
luisramos0
a44a251d96 Remove duplicated attributes tag from all serializers to create consistency 2019-09-19 16:32:09 +01:00
luisramos0
2921ee19e1 Add api/order/{order_number} ednpoint and its new order detailed serializer 2019-09-19 16:32:09 +01:00
luisramos0
6796d91a07 Add some basic attributes to address and order serializers that will be used in the order show api endpoint 2019-09-19 16:32:09 +01:00
luisramos0
69afcf7510 Improve readability in order permissions 2019-09-19 16:32:09 +01:00
172 changed files with 5745 additions and 3039 deletions

View File

@@ -110,18 +110,6 @@ Metrics/LineLength:
- app/models/variant_override.rb
- app/models/variant_override_set.rb
- app/overrides/add_enterprise_fees_to_admin_configurations_menu.rb
- app/serializers/api/admin/basic_enterprise_serializer.rb
- app/serializers/api/admin/enterprise_fee_serializer.rb
- app/serializers/api/admin/enterprise_serializer.rb
- app/serializers/api/admin/exchange_serializer.rb
- app/serializers/api/admin/for_order_cycle/enterprise_serializer.rb
- app/serializers/api/admin/index_enterprise_serializer.rb
- app/serializers/api/admin/index_order_cycle_serializer.rb
- app/serializers/api/admin/line_item_serializer.rb
- app/serializers/api/admin/order_cycle_serializer.rb
- app/serializers/api/admin/subscription_serializer.rb
- app/serializers/api/admin/tag_rule_serializer.rb
- app/serializers/api/admin/variant_override_serializer.rb
- app/services/cart_service.rb
- app/services/default_stock_location.rb
- app/services/embedded_page_service.rb
@@ -148,11 +136,9 @@ Metrics/LineLength:
- lib/open_food_network/order_cycle_form_applicator.rb
- lib/open_food_network/order_cycle_management_report.rb
- lib/open_food_network/order_grouper.rb
- lib/open_food_network/orders_and_fulfillments_report.rb
- lib/open_food_network/payments_report.rb
- lib/open_food_network/permalink_generator.rb
- lib/open_food_network/products_cache.rb
- lib/open_food_network/products_renderer.rb
- lib/open_food_network/reports/bulk_coop_allocation_report.rb
- lib/open_food_network/reports/line_items.rb
- lib/open_food_network/sales_tax_report.rb
@@ -262,13 +248,10 @@ Metrics/LineLength:
- spec/helpers/order_cycles_helper_spec.rb
- spec/helpers/spree/admin/base_helper_spec.rb
- spec/jobs/confirm_order_job_spec.rb
- spec/jobs/products_cache_integrity_checker_job_spec.rb
- spec/jobs/refresh_products_cache_job_spec.rb
- spec/jobs/subscription_confirm_job_spec.rb
- spec/jobs/subscription_placement_job_spec.rb
- spec/lib/open_food_network/address_finder_spec.rb
- spec/lib/open_food_network/bulk_coop_report_spec.rb
- spec/lib/open_food_network/cached_products_renderer_spec.rb
- spec/lib/open_food_network/customers_report_spec.rb
- spec/lib/open_food_network/enterprise_fee_applicator_spec.rb
- spec/lib/open_food_network/enterprise_fee_calculator_spec.rb
@@ -285,7 +268,6 @@ Metrics/LineLength:
- spec/lib/open_food_network/permissions_spec.rb
- spec/lib/open_food_network/products_and_inventory_report_spec.rb
- spec/lib/open_food_network/products_cache_spec.rb
- spec/lib/open_food_network/products_renderer_spec.rb
- spec/lib/open_food_network/proxy_order_syncer_spec.rb
- spec/lib/open_food_network/scope_variant_to_hub_spec.rb
- spec/lib/open_food_network/subscription_payment_updater_spec.rb
@@ -454,7 +436,6 @@ Metrics/AbcSize:
- lib/open_food_network/order_cycle_form_applicator.rb
- lib/open_food_network/order_cycle_management_report.rb
- lib/open_food_network/order_cycle_permissions.rb
- lib/open_food_network/orders_and_fulfillments_report.rb
- lib/open_food_network/packing_report.rb
- lib/open_food_network/payments_report.rb
- lib/open_food_network/permissions.rb
@@ -532,7 +513,6 @@ Metrics/CyclomaticComplexity:
- lib/discourse/single_sign_on.rb
- lib/open_food_network/bulk_coop_report.rb
- lib/open_food_network/enterprise_issue_validator.rb
- lib/open_food_network/orders_and_fulfillments_report.rb
- lib/spree/core/controller_helpers/order_decorator.rb
- lib/spree/core/controller_helpers/respond_with_decorator.rb
- lib/spree/localized_number.rb
@@ -557,7 +537,6 @@ Metrics/PerceivedComplexity:
- lib/discourse/single_sign_on.rb
- lib/open_food_network/bulk_coop_report.rb
- lib/open_food_network/enterprise_issue_validator.rb
- lib/open_food_network/orders_and_fulfillments_report.rb
- lib/spree/core/controller_helpers/order_decorator.rb
- lib/spree/core/controller_helpers/respond_with_decorator.rb
- lib/spree/localized_number.rb
@@ -627,12 +606,10 @@ Metrics/MethodLength:
- lib/open_food_network/order_cycle_management_report.rb
- lib/open_food_network/order_cycle_permissions.rb
- lib/open_food_network/order_grouper.rb
- lib/open_food_network/orders_and_fulfillments_report.rb
- lib/open_food_network/packing_report.rb
- lib/open_food_network/payments_report.rb
- lib/open_food_network/permissions.rb
- lib/open_food_network/products_and_inventory_report.rb
- lib/open_food_network/products_renderer.rb
- lib/open_food_network/rack_request_blocker.rb
- lib/open_food_network/reports/bulk_coop_allocation_report.rb
- lib/open_food_network/reports/bulk_coop_supplier_report.rb
@@ -671,7 +648,6 @@ Metrics/ClassLength:
- lib/open_food_network/order_cycle_form_applicator.rb
- lib/open_food_network/order_cycle_management_report.rb
- lib/open_food_network/order_cycle_permissions.rb
- lib/open_food_network/orders_and_fulfillments_report.rb
- lib/open_food_network/packing_report.rb
- lib/open_food_network/payments_report.rb
- lib/open_food_network/permissions.rb
@@ -688,7 +664,6 @@ Metrics/ModuleLength:
- spec/controllers/api/orders_controller_spec.rb
- spec/controllers/spree/api/products_controller_spec.rb
- spec/lib/open_food_network/address_finder_spec.rb
- spec/lib/open_food_network/cached_products_renderer_spec.rb
- spec/lib/open_food_network/customers_report_spec.rb
- spec/lib/open_food_network/enterprise_fee_calculator_spec.rb
- spec/lib/open_food_network/option_value_namer_spec.rb

View File

@@ -19,6 +19,10 @@ If you want to run the whole test suite, we recommend using a free CI service to
bundle exec rspec spec
## Which issue to pick first?
We have curated all issues interesting for new members of the community within the [Welcome New Developers project board][welcome-dev]. Have a look and pick the one you would prefer working on!
## Internationalisation (i18n)
The locale `en` is maintained in the source code, but other locales are managed at [Transifex][ofn-transifex]. Read more about [internationalisation][i18n] in the developer wiki.
@@ -62,3 +66,4 @@ From here, your pull request will progress through the [Review, Test, Merge & De
[slack-dev]: https://openfoodnetwork.slack.com/messages/C2GQ45KNU
[ofn-transifex]: https://www.transifex.com/open-food-foundation/open-food-network/
[i18n]: https://github.com/openfoodfoundation/openfoodnetwork/wiki/i18n
[welcome-dev]: https://github.com/openfoodfoundation/openfoodnetwork/projects/27

View File

@@ -39,7 +39,7 @@ gem 'activemerchant', '~> 1.78'
gem 'devise', '~> 2.2.5'
gem 'devise-encryptable', '0.2.0'
gem 'jwt', '~> 2.2'
gem 'oauth2', '~> 1.4.1' # Used for Stripe Connect
gem 'oauth2', '~> 1.4.2' # Used for Stripe Connect
gem 'daemons'
gem 'delayed_job_active_record'

View File

@@ -223,7 +223,7 @@ GEM
activerecord (>= 3.2.0, < 5.0)
fog (~> 1.0)
rails (>= 3.2.0, < 5.0)
ddtrace (0.27.0)
ddtrace (0.28.0)
msgpack
debugger-linecache (1.2.0)
deface (1.0.2)
@@ -491,8 +491,8 @@ GEM
newrelic_rpm (3.18.1.330)
nokogiri (1.6.8.1)
mini_portile2 (~> 2.1.0)
oauth2 (1.4.1)
faraday (>= 0.8, < 0.16.0)
oauth2 (1.4.2)
faraday (>= 0.8, < 2.0)
jwt (>= 1.0, < 3.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
@@ -596,29 +596,29 @@ GEM
nokogiri
roo (>= 2.0.0beta1, < 3)
spreadsheet (> 0.9.0)
rspec (3.8.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.8.0)
rspec-core (3.8.0)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.2)
rspec (3.9.0)
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-expectations (3.9.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-mocks (3.8.0)
rspec-support (~> 3.9.0)
rspec-mocks (3.9.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-rails (3.8.2)
rspec-support (~> 3.9.0)
rspec-rails (3.9.0)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.8.0)
rspec-support (~> 3.8.0)
rspec-core (~> 3.9.0)
rspec-expectations (~> 3.9.0)
rspec-mocks (~> 3.9.0)
rspec-support (~> 3.9.0)
rspec-retry (0.6.1)
rspec-core (> 3.3)
rspec-support (3.8.0)
rspec-support (3.9.0)
rubocop (0.57.2)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
@@ -630,7 +630,7 @@ GEM
ruby-ole (1.2.12.1)
ruby-progressbar (1.10.1)
ruby-rc4 (0.1.5)
rubyzip (1.2.2)
rubyzip (1.3.0)
safe_yaml (1.0.5)
sass (3.3.14)
sass-rails (3.2.6)
@@ -777,7 +777,7 @@ DEPENDENCIES
momentjs-rails
newrelic_rpm (~> 3.0)
nokogiri (>= 1.6.7.1)
oauth2 (~> 1.4.1)
oauth2 (~> 1.4.2)
ofn-qz!
oj
order_management!

View File

@@ -1,4 +1,4 @@
Darkswarm.controller "OrderCycleCtrl", ($scope, $timeout, OrderCycle) ->
Darkswarm.controller "OrderCycleCtrl", ($scope, $rootScope, $timeout, OrderCycle) ->
$scope.order_cycle = OrderCycle.order_cycle
$scope.OrderCycle = OrderCycle
@@ -6,11 +6,12 @@ Darkswarm.controller "OrderCycleCtrl", ($scope, $timeout, OrderCycle) ->
# This is a hack. We should probably write our own "popover" directive
# That takes an expression instead of a trigger, and binds to that
$timeout =>
$rootScope.$broadcast 'orderCycleSelected'
if !$scope.OrderCycle.selected()
$("#order_cycle_id").trigger("openTrigger")
Darkswarm.controller "OrderCycleChangeCtrl", ($scope, $timeout, OrderCycle, Products, Variants, Cart, ChangeableOrdersAlert) ->
Darkswarm.controller "OrderCycleChangeCtrl", ($scope, $rootScope, $timeout, OrderCycle, Products, Variants, Cart, ChangeableOrdersAlert) ->
# Track previous order cycle id for use with revertOrderCycle()
$scope.previous_order_cycle_id = OrderCycle.order_cycle.order_cycle_id
$scope.$watch 'order_cycle.order_cycle_id', (newValue, oldValue)->
@@ -32,3 +33,4 @@ Darkswarm.controller "OrderCycleChangeCtrl", ($scope, $timeout, OrderCycle, Prod
Products.update()
Cart.reloadFinalisedLineItems()
ChangeableOrdersAlert.reload()
$rootScope.$broadcast 'orderCycleSelected'

View File

@@ -1,41 +1,65 @@
Darkswarm.controller "ProductsCtrl", ($scope, $filter, $rootScope, Products, OrderCycle, FilterSelectorsService, Cart, Taxons, Properties) ->
Darkswarm.controller "ProductsCtrl", ($scope, $filter, $rootScope, Products, OrderCycle, OrderCycleResource, FilterSelectorsService, Cart, Dereferencer, Taxons, Properties, currentHub, $timeout) ->
$scope.Products = Products
$scope.Cart = Cart
$scope.query = ""
$scope.taxonSelectors = FilterSelectorsService.createSelectors()
$scope.propertySelectors = FilterSelectorsService.createSelectors()
$scope.filtersActive = true
$scope.limit = 10
$scope.page = 1
$scope.per_page = 10
$scope.order_cycle = OrderCycle.order_cycle
# $scope.infiniteDisabled = true
$scope.supplied_taxons = null
$scope.supplied_properties = null
# All of this logic basically just replicates the functionality filtering an ng-repeat
# except that it allows us to filter a separate list before rendering, meaning that
# we can get much better performance when applying filters by resetting the limit on the
# number of products being rendered each time a filter is changed.
$rootScope.$on "orderCycleSelected", ->
$scope.update_filters()
$scope.clearAll()
$scope.$watch "Products.loading", (newValue, oldValue) ->
$scope.updateFilteredProducts()
$scope.$broadcast("loadFilterSelectors") if !newValue
$scope.update_filters = ->
order_cycle_id = OrderCycle.order_cycle.order_cycle_id
$scope.incrementLimit = ->
if $scope.limit < Products.products.length
$scope.limit += 10
$scope.updateVisibleProducts()
return unless order_cycle_id
$scope.$watch 'query', -> $scope.updateFilteredProducts()
$scope.$watchCollection 'activeTaxons', -> $scope.updateFilteredProducts()
$scope.$watchCollection 'activeProperties', -> $scope.updateFilteredProducts()
params = {
id: order_cycle_id,
distributor: currentHub.id
}
OrderCycleResource.taxons params, (data)=>
$scope.supplied_taxons = {}
data.map( (taxon) ->
$scope.supplied_taxons[taxon.id] = Taxons.taxons_by_id[taxon.id]
)
OrderCycleResource.properties params, (data)=>
$scope.supplied_properties = {}
data.map( (property) ->
$scope.supplied_properties[property.id] = Properties.properties_by_id[property.id]
)
$scope.updateFilteredProducts = ->
$scope.limit = 10
f1 = $filter('products')(Products.products, $scope.query)
f2 = $filter('taxons')(f1, $scope.activeTaxons)
$scope.filteredProducts = $filter('properties')(f2, $scope.activeProperties)
$scope.updateVisibleProducts()
$scope.loadMore = ->
if ($scope.page * $scope.per_page) <= Products.products.length
$scope.loadMoreProducts()
$scope.updateVisibleProducts = ->
$scope.visibleProducts = $filter('limitTo')($scope.filteredProducts, $scope.limit)
$scope.$watch 'query', (newValue, oldValue) -> $scope.loadProducts() if newValue != oldValue
$scope.$watchCollection 'activeTaxons', (newValue, oldValue) -> $scope.loadProducts() if newValue != oldValue
$scope.$watchCollection 'activeProperties', (newValue, oldValue) -> $scope.loadProducts() if newValue != oldValue
$scope.loadProducts = ->
$scope.page = 1
Products.update($scope.queryParams())
$scope.loadMoreProducts = ->
Products.update($scope.queryParams($scope.page + 1), true)
$scope.page += 1
$scope.queryParams = (page = null) ->
{
id: $scope.order_cycle.order_cycle_id,
page: page || $scope.page,
per_page: $scope.per_page,
'q[name_or_meta_keywords_or_supplier_name_cont]': $scope.query,
'q[properties_id_or_supplier_properties_id_in_any][]': $scope.activeProperties,
'q[primary_taxon_id_in_any][]': $scope.activeTaxons
}
$scope.searchKeypress = (e)->
code = e.keyCode || e.which

View File

@@ -0,0 +1,21 @@
Darkswarm.factory 'OrderCycleResource', ($resource) ->
$resource('/api/order_cycles/:id', {}, {
'products':
method: 'GET'
isArray: true
url: '/api/order_cycles/:id/products'
params:
id: '@id'
'taxons':
method: 'GET'
isArray: true
url: '/api/order_cycles/:id/taxons'
params:
id: '@id'
'properties':
method: 'GET'
isArray: true
url: '/api/order_cycles/:id/properties'
params:
id: '@id'
})

View File

@@ -1,26 +1,34 @@
Darkswarm.factory 'Products', ($resource, Shopfront, Dereferencer, Taxons, Properties, Cart, Variants) ->
Darkswarm.factory 'Products', (OrderCycleResource, OrderCycle, Shopfront, currentHub, Dereferencer, Taxons, Properties, Cart, Variants) ->
new class Products
constructor: ->
@update()
# TODO: don't need to scope this into object
# Already on object as far as controller scope is concerned
products: null
products: []
fetched_products: []
loading: true
update: =>
update: (params = {}, load_more = false) =>
@loading = true
@products = []
$resource("/shop/products").query (products)=>
@products = products
order_cycle_id = OrderCycle.order_cycle.order_cycle_id
if order_cycle_id == undefined
@loading = false
return
params['id'] = order_cycle_id
params['distributor'] = currentHub.id
OrderCycleResource.products params, (data)=>
@products = [] unless load_more
@fetched_products = data
@extend()
@dereference()
@registerVariants()
@products = @products.concat(@fetched_products)
@loading = false
extend: ->
for product in @products
for product in @fetched_products
if product.variants?.length > 0
prices = (v.price for v in product.variants)
product.price = Math.min.apply(null, prices)
@@ -30,7 +38,7 @@ Darkswarm.factory 'Products', ($resource, Shopfront, Dereferencer, Taxons, Prope
product.largeImage = product.images[0]?.large_url if product.images
dereference: ->
for product in @products
for product in @fetched_products
product.supplier = Shopfront.producers_by_id[product.supplier.id]
Dereferencer.dereference product.taxons, Taxons.taxons_by_id
@@ -40,7 +48,7 @@ Darkswarm.factory 'Products', ($resource, Shopfront, Dereferencer, Taxons, Prope
# May return different objects! If the variant has already been registered
# by another service, we fetch those
registerVariants: ->
for product in @products
for product in @fetched_products
if product.variants
product.variant_names = ""
product.variants = for variant in product.variants

View File

@@ -17,7 +17,7 @@
.small-4.medium-2.large-2.columns.variant-price
.table-cell.price
%i.ofn-i_009-close
{{ ::variant.price_with_fees | localizeCurrency }}
{{ variant.price_with_fees | localizeCurrency }}
-# Now in a template in app/assets/javascripts/templates !
%price-breakdown{"price-breakdown" => "_", variant: "variant",

View File

@@ -1,27 +0,0 @@
require 'open_food_network/products_cache_integrity_checker'
module Admin
class CacheSettingsController < Spree::Admin::BaseController
def edit
@results = Exchange.cachable.map do |exchange|
checker = OpenFoodNetwork::ProductsCacheIntegrityChecker
.new(exchange.receiver, exchange.order_cycle)
{
distributor: exchange.receiver,
order_cycle: exchange.order_cycle,
status: checker.ok?,
diff: checker.diff
}
end
end
def update
Spree::Config.set(params[:preferences])
respond_to do |format|
format.html { redirect_to main_app.edit_admin_cache_settings_path }
end
end
end
end

View File

@@ -0,0 +1,88 @@
module Api
class OrderCyclesController < BaseController
include EnterprisesHelper
respond_to :json
skip_authorization_check
def products
products = ProductsRenderer.new(
distributor,
order_cycle,
customer,
search_params
).products_json
render json: products
rescue ProductsRenderer::NoProducts
render status: :not_found, json: ''
end
def taxons
taxons = Spree::Taxon.
joins(:products).
where(spree_products: { id: distributed_products }).
select('DISTINCT spree_taxons.*')
render json: ActiveModel::ArraySerializer.new(taxons, each_serializer: Api::TaxonSerializer)
end
def properties
render json: ActiveModel::ArraySerializer.new(
product_properties | producer_properties, each_serializer: Api::PropertySerializer
)
end
private
def product_properties
Spree::Property.
joins(:products).
where(spree_products: { id: distributed_products }).
select('DISTINCT spree_properties.*')
end
def producer_properties
producers = Enterprise.
joins(:supplied_products).
where(spree_products: { id: distributed_products })
Spree::Property.
joins(:producer_properties).
where(producer_properties: { producer_id: producers }).
select('DISTINCT spree_properties.*')
end
def search_params
permitted_search_params = params.slice :q, :page, :per_page
if permitted_search_params.key? :q
permitted_search_params[:q].slice!(*permitted_ransack_params)
end
permitted_search_params
end
def permitted_ransack_params
[:name_or_meta_keywords_or_supplier_name_cont,
:properties_id_or_supplier_properties_id_in_any,
:primary_taxon_id_in_any]
end
def distributor
Enterprise.find_by_id(params[:distributor])
end
def order_cycle
OrderCycle.find_by_id(params[:id])
end
def customer
@current_api_user.andand.customer_of(distributor) || nil
end
def distributed_products
OrderCycleDistributedProducts.new(distributor, order_cycle, customer).products_relation
end
end
end

View File

@@ -1,5 +1,10 @@
module Api
class OrdersController < BaseController
def show
authorize! :read, order
render json: order, serializer: Api::OrderDetailedSerializer, current_order: order
end
def index
authorize! :admin, Spree::Order
@@ -19,5 +24,12 @@ module Api
each_serializer: Api::Admin::OrderSerializer
)
end
def order
@order ||= Spree::Order.
where(number: params[:id]).
includes(line_items: { variant: [:product, :stock_items, :default_price] }).
first!
end
end
end

View File

@@ -1,5 +1,3 @@
require 'open_food_network/cached_products_renderer'
class ShopController < BaseController
layout "darkswarm"
before_filter :require_distributor_chosen, :set_order_cycles, except: :changeable_orders_alert
@@ -9,19 +7,6 @@ class ShopController < BaseController
redirect_to main_app.enterprise_shop_path(current_distributor)
end
def products
renderer = OpenFoodNetwork::CachedProductsRenderer.new(current_distributor,
current_order_cycle)
# If we add any more filtering logic, we should probably
# move it all to a lib class like 'CachedProductsFilterer'
products_json = filter(renderer.products_json)
render json: products_json
rescue OpenFoodNetwork::CachedProductsRenderer::NoProducts
render status: :not_found, json: ''
end
def order_cycle
if request.post?
if oc = OrderCycle.with_distributor(@distributor).active.find_by_id(params[:order_cycle_id])
@@ -39,27 +24,4 @@ class ShopController < BaseController
def changeable_orders_alert
render layout: false
end
private
def filtered_json(products_json)
if applicator.rules.any?
filter(products_json)
else
products_json
end
end
def filter(products_json)
products_hash = JSON.parse(products_json)
applicator.filter!(products_hash)
JSON.unparse(products_hash)
end
def applicator
return @applicator unless @applicator.nil?
@applicator = OpenFoodNetwork::TagRuleApplicator.new(current_distributor,
"FilterProducts",
current_customer.andand.tag_list)
end
end

View File

@@ -0,0 +1,35 @@
module Spree
module Admin
class GeneralSettingsController < Spree::Admin::BaseController
def edit
@preferences_general = [:site_name, :default_seo_title, :default_meta_keywords,
:default_meta_description, :site_url, :bugherd_api_key]
@preferences_security = [:allow_ssl_in_production,
:allow_ssl_in_staging, :allow_ssl_in_development_and_test,
:check_for_spree_alerts]
@preferences_currency = [:display_currency, :hide_cents]
end
def update
params.each do |name, value|
next unless Spree::Config.has_preference? name
Spree::Config[name] = value
end
flash[:success] = Spree.t(:successfully_updated, resource: Spree.t(:general_settings))
redirect_to edit_admin_general_settings_path
end
def dismiss_alert
return unless request.xhr? && params[:alert_id]
dismissed = Spree::Config[:dismissed_spree_alerts] || ''
Spree::Config.set(dismissed_spree_alerts: dismissed.
split(',').
push(params[:alert_id]).
join(','))
filter_dismissed_alerts
render nothing: true
end
end
end
end

View File

@@ -1,14 +0,0 @@
module Spree
module Admin
GeneralSettingsController.class_eval do
end
module GeneralSettingsEditPreferences
def edit
super
@preferences_general << :bugherd_api_key
end
end
GeneralSettingsController.prepend(GeneralSettingsEditPreferences)
end
end

View File

@@ -0,0 +1,79 @@
module Spree
module Admin
class ImageSettingsController < Spree::Admin::BaseController
def edit
@styles = ActiveSupport::JSON.decode(Spree::Config[:attachment_styles])
@headers = ActiveSupport::JSON.decode(Spree::Config[:s3_headers])
end
def update
update_styles(params)
update_headers(params) if Spree::Config[:use_s3]
Spree::Config.set(params[:preferences])
update_paperclip_settings
respond_to do |format|
format.html {
flash[:success] = Spree.t(:image_settings_updated)
redirect_to spree.edit_admin_image_settings_path
}
end
end
private
def update_styles(params)
if params[:new_attachment_styles].present?
params[:new_attachment_styles].each do |_index, style|
params[:attachment_styles][style[:name]] = style[:value] unless style[:value].empty?
end
end
styles = params[:attachment_styles]
Spree::Config[:attachment_styles] = ActiveSupport::JSON.encode(styles) unless styles.nil?
end
def update_headers(params)
if params[:new_s3_headers].present?
params[:new_s3_headers].each do |_index, header|
params[:s3_headers][header[:name]] = header[:value] unless header[:value].empty?
end
end
headers = params[:s3_headers]
Spree::Config[:s3_headers] = ActiveSupport::JSON.encode(headers) unless headers.nil?
end
def update_paperclip_settings
if Spree::Config[:use_s3]
s3_creds = { access_key_id: Spree::Config[:s3_access_key],
secret_access_key: Spree::Config[:s3_secret],
bucket: Spree::Config[:s3_bucket] }
Spree::Image.attachment_definitions[:attachment][:storage] = :s3
Spree::Image.attachment_definitions[:attachment][:s3_credentials] = s3_creds
Spree::Image.attachment_definitions[:attachment][:s3_headers] =
ActiveSupport::JSON.decode(Spree::Config[:s3_headers])
Spree::Image.attachment_definitions[:attachment][:bucket] = Spree::Config[:s3_bucket]
else
Spree::Image.attachment_definitions[:attachment].delete :storage
end
Spree::Image.attachment_definitions[:attachment][:styles] =
ActiveSupport::JSON.decode(Spree::Config[:attachment_styles]).symbolize_keys!
Spree::Image.attachment_definitions[:attachment][:path] = Spree::Config[:attachment_path]
Spree::Image.attachment_definitions[:attachment][:default_url] =
Spree::Config[:attachment_default_url]
Spree::Image.attachment_definitions[:attachment][:default_style] =
Spree::Config[:attachment_default_style]
# Spree stores attachent definitions in JSON. This converts the style name and format to
# strings. However, when paperclip encounters these, it doesn't recognise the format.
# Here we solve that problem by converting format and style name to symbols.
Spree::Image.reformat_styles
end
end
end
end

View File

@@ -1,11 +0,0 @@
Spree::Admin::ImageSettingsController.class_eval do
# Spree stores attachent definitions in JSON. This converts the style name and format to
# strings. However, when paperclip encounters these, it doesn't recognise the format.
# Here we solve that problem by converting format and style name to symbols.
def update_paperclip_settings_with_format_styles
update_paperclip_settings_without_format_styles
Spree::Image.reformat_styles
end
alias_method_chain :update_paperclip_settings, :format_styles
end

View File

@@ -0,0 +1,39 @@
module Spree
module Admin
class MailMethodsController < Spree::Admin::BaseController
after_filter :initialize_mail_settings
def update
if params[:smtp_password].blank?
params.delete(:smtp_password)
end
params.each do |name, value|
next unless Spree::Config.has_preference? name
Spree::Config[name] = value
end
flash[:success] = Spree.t(:successfully_updated, resource: Spree.t(:mail_methods))
render :edit
end
def testmail
if TestMailer.test_email(try_spree_current_user).deliver
flash[:success] = Spree.t('admin.mail_methods.testmail.delivery_success')
else
flash[:error] = Spree.t('admin.mail_methods.testmail.delivery_error')
end
rescue StandardError => e
flash[:error] = Spree.t('admin.mail_methods.testmail.error') % { e: e }
ensure
redirect_to edit_admin_mail_method_url
end
private
def initialize_mail_settings
Spree::Core::MailSettings.init
end
end
end
end

View File

@@ -30,6 +30,11 @@ Spree::Admin::ProductsController.class_eval do
@show_latest_import = params[:latest_import] || false
end
def new
@object.shipping_category = DefaultShippingCategory.find_or_create
super
end
def create
delete_stock_params_and_set_after do
super
@@ -44,8 +49,6 @@ Spree::Admin::ProductsController.class_eval do
delete_stock_params_and_set_after do
super
end
clear_variants_unit_description if @object.variant_unit == 'items'
end
def bulk_update
@@ -190,10 +193,4 @@ Spree::Admin::ProductsController.class_eval do
def set_product_master_variant_price_to_zero
@product.price = 0 if @product.price.nil?
end
def clear_variants_unit_description
@object.variants.each do |variant|
variant.update_attribute :unit_description, ''
end
end
end

View File

@@ -19,6 +19,11 @@ module Spree
collection
end
def new
@object.shipping_categories = [DefaultShippingCategory.find_or_create]
super
end
def destroy
# Our reports are not adapted to soft deleted shipping_methods so here we prevent
# the deletion (even soft) of shipping_methods that are referenced in orders

View File

@@ -0,0 +1,13 @@
module Spree
module Admin
module GeneralSettingsHelper
def currency_options
currencies = ::Money::Currency.table.map do |_code, details|
iso = details[:iso_code]
[iso, "#{details[:name]} (#{iso})"]
end
options_from_collection_for_select(currencies, :first, :last, Spree::Config[:currency])
end
end
end
end

View File

@@ -1,30 +0,0 @@
require 'open_food_network/products_cache_integrity_checker'
ProductsCacheIntegrityCheckerJob = Struct.new(:distributor_id, :order_cycle_id) do
def perform
unless checker.ok?
exception = RuntimeError.new(
"Products JSON differs from cached version for distributor: #{distributor_id}, " \
"order cycle: #{order_cycle_id}"
)
Bugsnag.notify(exception) do |report|
report.add_tab(:products_cache, diff: checker.diff.to_s(:text))
end
end
end
private
def checker
OpenFoodNetwork::ProductsCacheIntegrityChecker.new(distributor, order_cycle)
end
def distributor
Enterprise.find distributor_id
end
def order_cycle
OrderCycle.find order_cycle_id
end
end

View File

@@ -1,21 +0,0 @@
require 'open_food_network/products_renderer'
RefreshProductsCacheJob = Struct.new(:distributor_id, :order_cycle_id) do
def perform
Rails.cache.write(key, products_json)
rescue ActiveRecord::RecordNotFound
true
end
private
def key
"products-json-#{distributor_id}-#{order_cycle_id}"
end
def products_json
distributor = Enterprise.find distributor_id
order_cycle = OrderCycle.find order_cycle_id
OpenFoodNetwork::ProductsRenderer.new(distributor, order_cycle).products_json
end
end

View File

@@ -1,13 +1,4 @@
class CoordinatorFee < ActiveRecord::Base
belongs_to :order_cycle
belongs_to :enterprise_fee
after_save :refresh_products_cache
after_destroy :refresh_products_cache
private
def refresh_products_cache
order_cycle.refresh_products_cache
end
end

View File

@@ -10,10 +10,6 @@ class EnterpriseFee < ActiveRecord::Base
has_many :exchange_fees, dependent: :destroy
has_many :exchanges, through: :exchange_fees
after_save :refresh_products_cache
# After destroy, the products cache is refreshed via the after_destroy hook for
# coordinator_fees and exchange_fees
attr_accessible :enterprise_id, :fee_type, :name, :tax_category_id, :calculator_type, :inherits_tax_category
FEE_TYPES = %w(packing transport admin sales fundraising).freeze
@@ -59,8 +55,4 @@ class EnterpriseFee < ActiveRecord::Base
end
true
end
def refresh_products_cache
OpenFoodNetwork::ProductsCache.enterprise_fee_changed self
end
end

View File

@@ -23,9 +23,6 @@ class Exchange < ActiveRecord::Base
validates :order_cycle, :sender, :receiver, presence: true
validates :sender_id, uniqueness: { scope: [:order_cycle_id, :receiver_id, :incoming] }
after_save :refresh_products_cache
after_destroy :refresh_products_cache_from_destroy
accepts_nested_attributes_for :variants
scope :in_order_cycle, lambda { |order_cycle| where(order_cycle_id: order_cycle) }
@@ -98,12 +95,4 @@ class Exchange < ActiveRecord::Base
def participant
incoming? ? sender : receiver
end
def refresh_products_cache
OpenFoodNetwork::ProductsCache.exchange_changed self
end
def refresh_products_cache_from_destroy
OpenFoodNetwork::ProductsCache.exchange_destroyed self
end
end

View File

@@ -1,13 +1,4 @@
class ExchangeFee < ActiveRecord::Base
belongs_to :exchange
belongs_to :enterprise_fee
after_save :refresh_products_cache
after_destroy :refresh_products_cache
private
def refresh_products_cache
exchange.refresh_products_cache
end
end

View File

@@ -1,5 +1,3 @@
require 'open_food_network/products_cache'
class InventoryItem < ActiveRecord::Base
attr_accessible :enterprise, :enterprise_id, :variant, :variant_id, :visible
@@ -13,12 +11,4 @@ class InventoryItem < ActiveRecord::Base
scope :visible, -> { where(visible: true) }
scope :hidden, -> { where(visible: false) }
after_save :refresh_products_cache
private
def refresh_products_cache
OpenFoodNetwork::ProductsCache.inventory_item_changed self
end
end

View File

@@ -23,8 +23,6 @@ class OrderCycle < ActiveRecord::Base
validates :name, :coordinator_id, presence: true
validate :orders_close_at_after_orders_open_at?
after_save :refresh_products_cache
preference :product_selection_from_coordinator_inventory_only, :boolean, default: false
scope :active, lambda {
@@ -247,10 +245,6 @@ class OrderCycle < ActiveRecord::Base
coordinator.users.include? user
end
def refresh_products_cache
OpenFoodNetwork::ProductsCache.order_cycle_changed self
end
def items_bought_by_user(user, distributor)
# The Spree::Order.complete scope only checks for completed_at date
# it does not ensure state is "complete"

View File

@@ -4,9 +4,6 @@ class ProducerProperty < ActiveRecord::Base
default_scope order("#{table_name}.position")
after_save :refresh_products_cache
after_destroy :refresh_products_cache_from_destroy
scope :ever_sold_by, ->(shop) {
joins(producer: { supplied_products: { variants: { exchanges: :order_cycle } } }).
merge(Exchange.outgoing).
@@ -29,14 +26,4 @@ class ProducerProperty < ActiveRecord::Base
Spree::Property.create(name: name, presentation: name)
end
end
private
def refresh_products_cache
OpenFoodNetwork::ProductsCache.producer_property_changed self
end
def refresh_products_cache_from_destroy
OpenFoodNetwork::ProductsCache.producer_property_destroyed self
end
end

View File

@@ -207,12 +207,15 @@ class AbilityDecorator
end
def add_order_management_abilities(user)
# Enterprise User can only access orders that they are a distributor for
can [:index, :create], Spree::Order
can [:read, :update, :fire, :resend, :invoice, :print, :print_ticket], Spree::Order do |order|
# We allow editing orders with a nil distributor as this state occurs
# during the order creation process from the admin backend
order.distributor.nil? || user.enterprises.include?(order.distributor) || order.order_cycle.andand.coordinated_by?(user)
order.distributor.nil? ||
# Enterprise User can access orders that they are a distributor for
user.enterprises.include?(order.distributor) ||
# Enterprise User can access orders that are placed inside a OC they coordinate
order.order_cycle.andand.coordinated_by?(user)
end
can [:admin, :bulk_management, :managed], Spree::Order do
user.admin? || user.enterprises.any?(&:is_distributor)

View File

@@ -2,16 +2,9 @@ Spree::Classification.class_eval do
belongs_to :product, class_name: "Spree::Product", touch: true
before_destroy :dont_destroy_if_primary_taxon
after_destroy :refresh_products_cache
after_save :refresh_products_cache
private
def refresh_products_cache
product = Spree::Product.with_deleted.find(product_id) if product.blank?
product.refresh_products_cache
end
def dont_destroy_if_primary_taxon
if product.primary_taxon == taxon
errors.add :base, I18n.t(:spree_classification_primary_taxon_error, taxon: taxon.name, product: product.name)

View File

@@ -1,7 +1,4 @@
Spree::Image.class_eval do
after_save :refresh_products_cache
after_destroy :refresh_products_cache
# Spree stores attachent definitions in JSON. This converts the style name and format to
# strings. However, when paperclip encounters these, it doesn't recognise the format.
# Here we solve that problem by converting format and style name to symbols.
@@ -23,10 +20,4 @@ Spree::Image.class_eval do
end
reformat_styles
private
def refresh_products_cache
viewable.try :refresh_products_cache
end
end

View File

@@ -1,12 +1,5 @@
module Spree
OptionType.class_eval do
has_many :products, through: :product_option_types
after_save :refresh_products_cache
private
def refresh_products_cache
products(:reload).each(&:refresh_products_cache)
end
end
end

View File

@@ -1,18 +0,0 @@
module Spree
OptionValue.class_eval do
after_save :refresh_products_cache
around_destroy :refresh_products_cache_from_destroy
private
def refresh_products_cache
variants(:reload).each(&:refresh_products_cache)
end
def refresh_products_cache_from_destroy
vs = variants(:reload).to_a
yield
vs.each(&:refresh_products_cache)
end
end
end

View File

@@ -1,30 +0,0 @@
require 'open_food_network/products_cache'
module Spree
Preference.class_eval do
after_save :refresh_products_cache
# When the setting preferred_product_selection_from_inventory_only has changed, we want to
# refresh all active exchanges for this enterprise.
def refresh_products_cache
if product_selection_from_inventory_only_changed?
OpenFoodNetwork::ProductsCache.distributor_changed(enterprise)
end
end
private
def product_selection_from_inventory_only_changed?
!!(key =~ product_selection_from_inventory_only_regex)
end
def enterprise
enterprise_id = key.match(product_selection_from_inventory_only_regex)[1]
Enterprise.find(enterprise_id)
end
def product_selection_from_inventory_only_regex
/^enterprise\/product_selection_from_inventory_only\/(\d+)$/
end
end
end

View File

@@ -2,8 +2,6 @@ module Spree
Price.class_eval do
acts_as_paranoid without_default_scope: true
after_save :refresh_products_cache
# Allow prices to access associated soft-deleted variants.
def variant
Spree::Variant.unscoped { super }
@@ -16,9 +14,5 @@ module Spree
self.currency = Spree::Config[:currency]
end
end
def refresh_products_cache
variant.andand.refresh_products_cache
end
end
end

View File

@@ -38,7 +38,6 @@ Spree::Product.class_eval do
after_save :remove_previous_primary_taxon_from_taxons
after_save :ensure_standard_variant
after_save :update_units
after_save :refresh_products_cache
# -- Joins
scope :with_order_cycles_outer, -> {
@@ -192,23 +191,17 @@ Spree::Product.class_eval do
def destroy_with_delete_from_order_cycles
transaction do
OpenFoodNetwork::ProductsCache.product_deleted(self) do
touch_distributors
touch_distributors
ExchangeVariant.
where('exchange_variants.variant_id IN (?)', variants_including_master.with_deleted.
select(:id)).destroy_all
ExchangeVariant.
where('exchange_variants.variant_id IN (?)', variants_including_master.with_deleted.
select(:id)).destroy_all
destroy_without_delete_from_order_cycles
end
destroy_without_delete_from_order_cycles
end
end
alias_method_chain :destroy, :delete_from_order_cycles
def refresh_products_cache
OpenFoodNetwork::ProductsCache.product_changed self
end
private
def set_available_on_to_now

View File

@@ -1,10 +1,5 @@
module Spree
ProductProperty.class_eval do
belongs_to :product, class_name: "Spree::Product", touch: true
after_save :refresh_products_cache
after_destroy :refresh_products_cache
delegate :refresh_products_cache, to: :product
end
end

View File

@@ -20,19 +20,8 @@ module Spree
merge(OrderCycle.active)
}
after_save :refresh_products_cache
# When a Property is destroyed, dependent-destroy will destroy all ProductProperties,
# which will take care of refreshing the products cache
def property
self
end
private
def refresh_products_cache
product_properties(:reload).each(&:refresh_products_cache)
end
end
end

View File

@@ -1,10 +0,0 @@
Spree::StockMovement.class_eval do
after_save :refresh_products_cache
private
def refresh_products_cache
return if stock_item.variant.blank?
OpenFoodNetwork::ProductsCache.variant_changed stock_item.variant
end
end

View File

@@ -4,8 +4,6 @@ Spree::Taxon.class_eval do
attachment_definitions[:icon][:path] = 'public/images/spree/taxons/:id/:style/:basename.:extension'
attachment_definitions[:icon][:url] = '/images/spree/taxons/:id/:style/:basename.:extension'
after_save :refresh_products_cache
# Indicate which filters should be used for this taxon
def applicable_filters
fs = []
@@ -49,10 +47,4 @@ Spree::Taxon.class_eval do
ts[t.enterprise_id.to_i] << t.id
end
end
private
def refresh_products_cache
products(:reload).each(&:refresh_products_cache)
end
end

View File

@@ -1,7 +1,6 @@
require 'open_food_network/enterprise_fee_calculator'
require 'open_food_network/variant_and_line_item_naming'
require 'concerns/variant_stock'
require 'open_food_network/products_cache'
Spree::Variant.class_eval do
extend Spree::LocalizedNumber
@@ -30,7 +29,6 @@ Spree::Variant.class_eval do
before_validation :update_weight_from_unit_value, if: ->(v) { v.product.present? }
after_save :update_units
after_save :refresh_products_cache
around_destroy :destruction
scope :with_order_cycles_inner, -> { joins(exchanges: :order_cycle) }
@@ -108,14 +106,6 @@ Spree::Variant.class_eval do
OpenFoodNetwork::EnterpriseFeeCalculator.new(distributor, order_cycle).fees_by_type_for self
end
def refresh_products_cache
if is_master?
product.refresh_products_cache
else
OpenFoodNetwork::ProductsCache.variant_changed self
end
end
private
def update_weight_from_unit_value
@@ -123,21 +113,7 @@ Spree::Variant.class_eval do
end
def destruction
if is_master?
exchange_variants(:reload).destroy_all
yield
product.refresh_products_cache
else
OpenFoodNetwork::ProductsCache.variant_destroyed(self) do
# Remove this association here instead of using dependent: :destroy because
# dependent-destroy acts before this around_filter is called, so ProductsCache
# has no way of knowing which exchanges the variant was a member of.
exchange_variants(:reload).destroy_all
# Destroy the variant
yield
end
end
exchange_variants(:reload).destroy_all
yield
end
end

View File

@@ -12,9 +12,6 @@ class VariantOverride < ActiveRecord::Base
# Default stock can be nil, indicating stock should not be reset or zero, meaning reset to zero. Need to ensure this can be set by the user.
validates :default_stock, numericality: { greater_than_or_equal_to: 0 }, allow_nil: true
after_save :refresh_products_cache_from_save
after_destroy :refresh_products_cache_from_destroy
default_scope where(permission_revoked_at: nil)
scope :for_hubs, lambda { |hubs|
@@ -73,14 +70,4 @@ class VariantOverride < ActiveRecord::Base
end
self
end
private
def refresh_products_cache_from_save
OpenFoodNetwork::ProductsCache.variant_override_changed self
end
def refresh_products_cache_from_destroy
OpenFoodNetwork::ProductsCache.variant_override_destroyed self
end
end

View File

@@ -4,7 +4,11 @@ class Api::AddressSerializer < ActiveModel::Serializer
attributes :id, :zipcode, :city, :state_name, :state_id,
:phone, :firstname, :lastname, :address1, :address2, :city, :country_id,
:zipcode
:zipcode, :country_name
def country_name
object.country.andand.name
end
def state_name
object.state.andand.abbr

View File

@@ -0,0 +1,8 @@
module Api
class AdjustmentSerializer < ActiveModel::Serializer
attributes :id, :amount, :label, :eligible,
:source_type, :source_id,
:adjustable_type, :adjustable_id,
:originator_type, :originator_id
end
end

View File

@@ -1,4 +1,4 @@
class Api::Admin::BasicEnterpriseSerializer < ActiveModel::Serializer
attributes :name, :id, :is_primary_producer, :is_distributor, :sells, :category, :payment_method_ids, :shipping_method_ids
attributes :producer_profile_only, :permalink
attributes :name, :id, :is_primary_producer, :is_distributor, :sells, :category,
:payment_method_ids, :shipping_method_ids, :producer_profile_only, :permalink
end

View File

@@ -1,6 +1,6 @@
class Api::Admin::CustomerSerializer < ActiveModel::Serializer
attributes :id, :email, :enterprise_id, :user_id, :code, :tags, :tag_list, :name
attributes :allow_charges, :default_card_present?
attributes :id, :email, :enterprise_id, :user_id, :code, :tags, :tag_list, :name,
:allow_charges, :default_card_present?
has_one :ship_address, serializer: Api::AddressSerializer
has_one :bill_address, serializer: Api::AddressSerializer

View File

@@ -1,6 +1,6 @@
class Api::Admin::EnterpriseFeeSerializer < ActiveModel::Serializer
attributes :id, :enterprise_id, :fee_type, :name, :tax_category_id, :inherits_tax_category, :calculator_type
attributes :enterprise_name, :calculator_description, :calculator_settings
attributes :id, :enterprise_id, :fee_type, :name, :tax_category_id, :inherits_tax_category,
:calculator_type, :enterprise_name, :calculator_description, :calculator_settings
def enterprise_name
object.enterprise.andand.name
@@ -16,7 +16,9 @@ class Api::Admin::EnterpriseFeeSerializer < ActiveModel::Serializer
result = nil
options[:controller].__send__(:with_format, :html) do
result = options[:controller].render_to_string partial: 'admin/enterprise_fees/calculator_settings', locals: { enterprise_fee: object }
result = options[:controller].
render_to_string(partial: 'admin/enterprise_fees/calculator_settings',
locals: { enterprise_fee: object })
end
result.gsub('[0]', '[{{ $index }}]').gsub('_0_', '_{{ $index }}_')

View File

@@ -1,11 +1,12 @@
class Api::Admin::EnterpriseSerializer < ActiveModel::Serializer
attributes :name, :id, :is_primary_producer, :is_distributor, :sells, :category, :payment_method_ids, :shipping_method_ids
attributes :producer_profile_only, :long_description, :permalink
attributes :preferred_shopfront_message, :preferred_shopfront_closed_message, :preferred_shopfront_taxon_order, :preferred_shopfront_order_cycle_order
attributes :preferred_product_selection_from_inventory_only
attributes :owner, :contact, :users, :tag_groups, :default_tag_group
attributes :require_login, :allow_guest_orders, :allow_order_changes
attributes :logo, :promo_image
attributes :name, :id, :is_primary_producer, :is_distributor, :sells, :category, :permalink,
:payment_method_ids, :shipping_method_ids, :producer_profile_only, :long_description,
:preferred_shopfront_message, :preferred_shopfront_closed_message,
:preferred_shopfront_taxon_order, :preferred_shopfront_order_cycle_order,
:preferred_product_selection_from_inventory_only,
:owner, :contact, :users, :tag_groups, :default_tag_group,
:require_login, :allow_guest_orders, :allow_order_changes,
:logo, :promo_image
has_one :owner, serializer: Api::Admin::UserSerializer
has_many :users, serializer: Api::Admin::UserSerializer
@@ -21,7 +22,9 @@ class Api::Admin::EnterpriseSerializer < ActiveModel::Serializer
def tag_groups
object.tag_rules.prioritised.reject(&:is_default).each_with_object([]) do |tag_rule, tag_groups|
tag_group = find_match(tag_groups, tag_rule.preferred_customer_tags.split(",").map{ |t| { text: t } })
tag_group = find_match(tag_groups, tag_rule.preferred_customer_tags.
split(",").
map{ |t| { text: t } })
if tag_group[:rules].empty?
tag_groups << tag_group
tag_group[:position] = tag_groups.count
@@ -32,13 +35,16 @@ class Api::Admin::EnterpriseSerializer < ActiveModel::Serializer
def default_tag_group
default_rules = object.tag_rules.select(&:is_default)
serialized_rules = ActiveModel::ArraySerializer.new(default_rules, each_serializer: Api::Admin::TagRuleSerializer)
serialized_rules =
ActiveModel::ArraySerializer.new(default_rules,
each_serializer: Api::Admin::TagRuleSerializer)
{ tags: [], rules: serialized_rules }
end
def find_match(tag_groups, tags)
tag_groups.each do |tag_group|
return tag_group if tag_group[:tags].length == tags.length && (tag_group[:tags] & tags) == tag_group[:tags]
return tag_group if tag_group[:tags].length == tags.length &&
(tag_group[:tags] & tags) == tag_group[:tags]
end
{ tags: tags, rules: [] }
end
@@ -56,7 +62,7 @@ class Api::Admin::EnterpriseSerializer < ActiveModel::Serializer
# # medium: LOGO_MEDIUM_URL
# # }
def attachment_urls(attachment, versions)
return unless attachment.exists?
return unless attachment.file?
versions.each_with_object({}) do |version, urls|
urls[version] = attachment.url(version)

View File

@@ -1,6 +1,7 @@
class Api::Admin::ExchangeSerializer < ActiveModel::Serializer
attributes :id, :sender_id, :receiver_id, :incoming, :variants, :receival_instructions, :pickup_time, :pickup_instructions
attributes :tags, :tag_list
attributes :id, :sender_id, :receiver_id, :incoming, :variants,
:receival_instructions, :pickup_time, :pickup_instructions,
:tags, :tag_list
has_many :enterprise_fees, serializer: Api::Admin::BasicEnterpriseFeeSerializer

View File

@@ -1,12 +1,16 @@
require 'open_food_network/enterprise_issue_validator'
class Api::Admin::ForOrderCycle::EnterpriseSerializer < ActiveModel::Serializer
attributes :id, :name, :managed, :supplied_products
attributes :issues_summary_supplier, :issues_summary_distributor
attributes :is_primary_producer, :is_distributor, :sells
attributes :id, :name, :managed, :supplied_products,
:issues_summary_supplier, :issues_summary_distributor,
:is_primary_producer, :is_distributor, :sells
def issues_summary_supplier
issues = OpenFoodNetwork::EnterpriseIssueValidator.new(object).issues_summary confirmation_only: true
issues =
OpenFoodNetwork::EnterpriseIssueValidator.
new(object).
issues_summary(confirmation_only: true)
if issues.nil? && products.empty?
issues = "no products in inventory"
end
@@ -23,7 +27,8 @@ class Api::Admin::ForOrderCycle::EnterpriseSerializer < ActiveModel::Serializer
def supplied_products
serializer = Api::Admin::ForOrderCycle::SuppliedProductSerializer
ActiveModel::ArraySerializer.new(products, each_serializer: serializer, order_cycle: order_cycle)
ActiveModel::ArraySerializer.new(products, each_serializer: serializer,
order_cycle: order_cycle)
end
private

View File

@@ -1,9 +1,8 @@
require 'open_food_network/enterprise_issue_validator'
class Api::Admin::IndexEnterpriseSerializer < ActiveModel::Serializer
attributes :name, :id, :permalink, :is_primary_producer, :sells, :producer_profile_only, :owned, :edit_path
attributes :issues, :warnings
attributes :name, :id, :permalink, :is_primary_producer, :sells, :producer_profile_only, :owned,
:edit_path, :issues, :warnings
def owned
return true if options[:spree_current_user].admin?

View File

@@ -5,9 +5,9 @@ module Api
class IndexOrderCycleSerializer < ActiveModel::Serializer
include OrderCyclesHelper
attributes :id, :name, :orders_open_at, :orders_close_at, :status, :variant_count, :deletable
attributes :coordinator, :producers, :shops, :viewing_as_coordinator
attributes :edit_path, :clone_path, :delete_path, :subscriptions_count
attributes :id, :name, :orders_open_at, :orders_close_at, :status, :variant_count, :deletable,
:coordinator, :producers, :shops, :viewing_as_coordinator,
:edit_path, :clone_path, :delete_path, :subscriptions_count
has_many :schedules, serializer: Api::Admin::IdNameSerializer
@@ -68,7 +68,10 @@ module Api
private
def visible_enterprises
@visible_enterprises ||= OpenFoodNetwork::OrderCyclePermissions.new(options[:current_user], object).visible_enterprises
@visible_enterprises ||=
OpenFoodNetwork::OrderCyclePermissions.
new(options[:current_user], object).
visible_enterprises
end
end
end

View File

@@ -1,5 +1,6 @@
class Api::Admin::LineItemSerializer < ActiveModel::Serializer
attributes :id, :quantity, :max_quantity, :price, :supplier, :final_weight_volume, :units_product, :units_variant
attributes :id, :quantity, :max_quantity, :price, :supplier, :final_weight_volume,
:units_product, :units_variant
has_one :order, serializer: Api::Admin::IdSerializer
@@ -20,7 +21,8 @@ class Api::Admin::LineItemSerializer < ActiveModel::Serializer
end
def max_quantity
return object.quantity unless object.max_quantity.present? && object.max_quantity > object.quantity
return object.quantity unless object.max_quantity.present? &&
object.max_quantity > object.quantity
object.max_quantity
end
end

View File

@@ -1,10 +1,10 @@
require 'open_food_network/order_cycle_permissions'
class Api::Admin::OrderCycleSerializer < ActiveModel::Serializer
attributes :id, :name, :orders_open_at, :orders_close_at, :coordinator_id, :exchanges
attributes :editable_variants_for_incoming_exchanges, :editable_variants_for_outgoing_exchanges
attributes :visible_variants_for_outgoing_exchanges
attributes :viewing_as_coordinator, :schedule_ids, :subscriptions_count
attributes :id, :name, :orders_open_at, :orders_close_at, :coordinator_id, :exchanges,
:editable_variants_for_incoming_exchanges, :editable_variants_for_outgoing_exchanges,
:visible_variants_for_outgoing_exchanges,
:viewing_as_coordinator, :schedule_ids, :subscriptions_count
has_many :coordinator_fees, serializer: Api::IdSerializer
@@ -25,8 +25,14 @@ class Api::Admin::OrderCycleSerializer < ActiveModel::Serializer
end
def exchanges
scoped_exchanges = OpenFoodNetwork::OrderCyclePermissions.new(options[:current_user], object).visible_exchanges.by_enterprise_name
ActiveModel::ArraySerializer.new(scoped_exchanges, each_serializer: Api::Admin::ExchangeSerializer, current_user: options[:current_user])
scoped_exchanges =
OpenFoodNetwork::OrderCyclePermissions.
new(options[:current_user], object).
visible_exchanges.by_enterprise_name
ActiveModel::ArraySerializer.
new(scoped_exchanges, each_serializer: Api::Admin::ExchangeSerializer,
current_user: options[:current_user])
end
def editable_variants_for_incoming_exchanges
@@ -66,9 +72,13 @@ class Api::Admin::OrderCycleSerializer < ActiveModel::Serializer
# for shops. We need this here to allow hubs to restrict visible variants to only those in
# their inventory if they so choose
variants = if enterprise.prefers_product_selection_from_inventory_only?
permissions.visible_variants_for_outgoing_exchanges_to(enterprise).visible_for(enterprise)
permissions.
visible_variants_for_outgoing_exchanges_to(enterprise).
visible_for(enterprise)
else
permissions.visible_variants_for_outgoing_exchanges_to(enterprise).not_hidden_for(enterprise)
permissions.
visible_variants_for_outgoing_exchanges_to(enterprise).
not_hidden_for(enterprise)
end.pluck(:id)
visible[enterprise.id] = variants if variants.any?
end

View File

@@ -1,8 +1,9 @@
class Api::Admin::OrderSerializer < ActiveModel::Serializer
attributes :id, :number, :full_name, :email, :phone, :completed_at, :display_total
attributes :edit_path, :state, :payment_state, :shipment_state
attributes :payments_path, :ship_path, :ready_to_ship, :created_at
attributes :distributor_name, :special_instructions, :payment_capture_path
attributes :id, :number, :user_id, :full_name, :email, :phone, :completed_at, :display_total,
:edit_path, :state, :payment_state, :shipment_state,
:payments_path, :ship_path, :ready_to_ship, :created_at,
:distributor_name, :special_instructions, :payment_capture_path,
:item_total, :adjustment_total, :payment_total, :total
has_one :distributor, serializer: Api::Admin::IdSerializer
has_one :order_cycle, serializer: Api::Admin::IdSerializer

View File

@@ -1,9 +1,10 @@
module Api
module Admin
class SubscriptionSerializer < ActiveModel::Serializer
attributes :id, :shop_id, :customer_id, :schedule_id, :payment_method_id, :shipping_method_id, :begins_at, :ends_at
attributes :customer_email, :schedule_name, :edit_path, :canceled_at, :paused_at, :state
attributes :shipping_fee_estimate, :payment_fee_estimate
attributes :id, :shop_id, :customer_id, :schedule_id, :payment_method_id, :shipping_method_id,
:begins_at, :ends_at,
:customer_email, :schedule_name, :edit_path, :canceled_at, :paused_at, :state,
:shipping_fee_estimate, :payment_fee_estimate
has_many :subscription_line_items, serializer: Api::Admin::SubscriptionLineItemSerializer
has_many :closed_proxy_orders, serializer: Api::Admin::ProxyOrderSerializer

View File

@@ -16,7 +16,8 @@ module Api::Admin::TagRule
end
class FilterShippingMethodsSerializer < BaseSerializer
attributes :preferred_matched_shipping_methods_visibility, :preferred_shipping_method_tags, :shipping_method_tags
attributes :preferred_matched_shipping_methods_visibility, :preferred_shipping_method_tags,
:shipping_method_tags
def shipping_method_tags
object.preferred_shipping_method_tags.split(",")
@@ -24,7 +25,8 @@ module Api::Admin::TagRule
end
class FilterPaymentMethodsSerializer < BaseSerializer
attributes :preferred_matched_payment_methods_visibility, :preferred_payment_method_tags, :payment_method_tags
attributes :preferred_matched_payment_methods_visibility, :preferred_payment_method_tags,
:payment_method_tags
def payment_method_tags
object.preferred_payment_method_tags.split(",")

View File

@@ -1,6 +1,6 @@
class Api::Admin::VariantOverrideSerializer < ActiveModel::Serializer
attributes :id, :hub_id, :variant_id, :sku, :price, :count_on_hand, :on_demand, :default_stock, :resettable
attributes :tag_list, :tags, :import_date
attributes :id, :hub_id, :variant_id, :sku, :price, :count_on_hand, :on_demand, :default_stock,
:resettable, :tag_list, :tags, :import_date
def tag_list
object.tag_list.join(",")

View File

@@ -1,8 +1,8 @@
class Api::Admin::VariantSerializer < ActiveModel::Serializer
attributes :id, :name, :producer_name, :image, :sku, :import_date
attributes :options_text, :unit_value, :unit_description, :unit_to_display
attributes :display_as, :display_name, :name_to_display
attributes :price, :on_demand, :on_hand, :in_stock, :stock_location_id, :stock_location_name
attributes :id, :name, :producer_name, :image, :sku, :import_date,
:options_text, :unit_value, :unit_description, :unit_to_display,
:display_as, :display_name, :name_to_display,
:price, :on_demand, :on_hand, :in_stock, :stock_location_id, :stock_location_name
has_many :variant_overrides

View File

@@ -0,0 +1,12 @@
module Api
class OrderDetailedSerializer < Api::Admin::OrderSerializer
has_one :shipping_method, serializer: Api::ShippingMethodSerializer
has_one :ship_address, serializer: Api::AddressSerializer
has_one :bill_address, serializer: Api::AddressSerializer
has_many :line_items, serializer: Api::LineItemSerializer
has_many :adjustments, serializer: Api::AdjustmentSerializer
has_many :payments, serializer: Api::PaymentSerializer
end
end

View File

@@ -1,9 +1,9 @@
module Api
class OrderSerializer < ActiveModel::Serializer
attributes :number, :completed_at, :total, :state, :shipment_state, :payment_state
attributes :outstanding_balance, :payments, :path, :cancel_path
attributes :changes_allowed, :changes_allowed_until, :item_count
attributes :shop_id
attributes :number, :completed_at, :total, :state, :shipment_state, :payment_state,
:outstanding_balance, :payments, :path, :cancel_path,
:changes_allowed, :changes_allowed_until, :item_count,
:shop_id
has_many :payments, serializer: Api::PaymentSerializer

View File

@@ -1,6 +1,7 @@
module Api
class PaymentSerializer < ActiveModel::Serializer
attributes :amount, :updated_at, :payment_method, :state
def payment_method
object.payment_method.try(:name)
end

View File

@@ -1,43 +1,11 @@
require 'open_food_network/scope_variant_to_hub'
class Api::ProductSerializer < ActiveModel::Serializer
# TODO
# Prices can't be cached? How?
def serializable_hash
cached_serializer_hash.merge(uncached_serializer_hash)
end
private
def cached_serializer_hash
Api::CachedProductSerializer.new(object, @options).serializable_hash
end
def uncached_serializer_hash
Api::UncachedProductSerializer.new(object, @options).serializable_hash
end
end
class Api::UncachedProductSerializer < ActiveModel::Serializer
attributes :price
def price
if options[:enterprise_fee_calculator]
object.master.price + options[:enterprise_fee_calculator].indexed_fees_for(object.master)
else
object.master.price_with_fees(options[:current_distributor], options[:current_order_cycle])
end
end
end
class Api::CachedProductSerializer < ActiveModel::Serializer
# cached
# delegate :cache_key, to: :object
include ActionView::Helpers::SanitizeHelper
attributes :id, :name, :permalink, :meta_keywords
attributes :group_buy, :notes, :description, :description_html
attributes :properties_with_values
attributes :properties_with_values, :price
has_many :variants, serializer: Api::VariantSerializer
has_one :master, serializer: Api::VariantSerializer
@@ -70,4 +38,12 @@ class Api::CachedProductSerializer < ActiveModel::Serializer
def master
options[:master_variants][object.id].andand.first
end
def price
if options[:enterprise_fee_calculator]
object.master.price + options[:enterprise_fee_calculator].indexed_fees_for(object.master)
else
object.master.price_with_fees(options[:current_distributor], options[:current_order_cycle])
end
end
end

View File

@@ -1,9 +1,9 @@
class Api::VariantSerializer < ActiveModel::Serializer
attributes :id, :is_master, :product_name, :sku
attributes :options_text, :unit_value, :unit_description, :unit_to_display
attributes :display_as, :display_name, :name_to_display
attributes :price, :on_demand, :on_hand, :fees, :price_with_fees
attributes :tag_list
attributes :id, :is_master, :product_name, :sku,
:options_text, :unit_value, :unit_description, :unit_to_display,
:display_as, :display_name, :name_to_display,
:price, :on_demand, :on_hand, :fees, :price_with_fees,
:tag_list
delegate :price, to: :object

View File

@@ -0,0 +1,13 @@
# Encapsulates the concept of default stock location in creation of a product or a shipping method.
class DefaultShippingCategory
NAME = 'Default'.freeze
def self.create!
Spree::ShippingCategory.create!(name: NAME)
end
def self.find_or_create
Spree::ShippingCategory.find_or_create_by_name(NAME)
end
end

View File

@@ -1,9 +1,10 @@
# Returns a (paginatable) AR object for the products or variants in stock for a given shop and OC.
# The stock-checking includes on_demand and stock level overrides from variant_overrides.
class OrderCycleDistributedProducts
def initialize(distributor, order_cycle)
def initialize(distributor, order_cycle, customer)
@distributor = distributor
@order_cycle = order_cycle
@customer = customer
end
def products_relation
@@ -11,26 +12,30 @@ class OrderCycleDistributedProducts
end
def variants_relation
@order_cycle.
variants_distributed_by(@distributor).
order_cycle.
variants_distributed_by(distributor).
merge(stocked_variants_and_overrides)
end
private
attr_reader :distributor, :order_cycle, :customer
def stocked_products
@order_cycle.
variants_distributed_by(@distributor).
order_cycle.
variants_distributed_by(distributor).
merge(stocked_variants_and_overrides).
select("DISTINCT spree_variants.product_id")
end
def stocked_variants_and_overrides
Spree::Variant.
stocked_variants = Spree::Variant.
joins("LEFT OUTER JOIN variant_overrides ON variant_overrides.variant_id = spree_variants.id
AND variant_overrides.hub_id = #{@distributor.id}").
AND variant_overrides.hub_id = #{distributor.id}").
joins(:stock_items).
where(query_stock_with_overrides)
ProductTagRulesFilterer.new(distributor, customer, stocked_variants).call
end
def query_stock_with_overrides

View File

@@ -0,0 +1,111 @@
# Takes a Spree::Variant AR object and filters results based on applicable tag rules.
# Tag rules exists in the context of enterprise, customer, and variant_overrides,
# and are applied to variant_overrides only. Returns a Spree::Variant AR object.
class ProductTagRulesFilterer
def initialize(distributor, customer, variants_relation)
@distributor = distributor
@customer = customer
@variants_relation = variants_relation
end
def call
return variants_relation unless distributor_rules.any?
filter(variants_relation)
end
private
attr_accessor :distributor, :customer, :variants_relation
def distributor_rules
@distributor_rules ||= TagRule::FilterProducts.prioritised.for(distributor).all
end
def filter(variants_relation)
return variants_relation unless overrides_to_hide.any?
variants_relation.where(query_with_tag_rules)
end
def query_with_tag_rules
"#{variant_not_overriden} OR ( #{variant_overriden}
AND ( #{override_not_hidden_by_rule}
OR #{override_shown_by_rule} ) )"
end
def variant_not_overriden
"variant_overrides.id IS NULL"
end
def variant_overriden
"variant_overrides.id IS NOT NULL"
end
def override_not_hidden_by_rule
return "FALSE" unless overrides_to_hide.any?
"variant_overrides.id NOT IN (#{overrides_to_hide.join(',')})"
end
def override_shown_by_rule
return "FALSE" unless overrides_to_show.any?
"variant_overrides.id IN (#{overrides_to_show.join(',')})"
end
def overrides_to_hide
@overrides_to_hide ||= VariantOverride.where(hub_id: distributor.id).
tagged_with(default_rule_tags + hide_rule_tags, any: true).
pluck(:id)
end
def overrides_to_show
@overrides_to_show ||= VariantOverride.where(hub_id: distributor.id).
tagged_with(show_rule_tags, any: true).
pluck(:id)
end
def default_rule_tags
default_rules.map(&:preferred_variant_tags)
end
def hide_rule_tags
hide_rules.map(&:preferred_variant_tags)
end
def show_rule_tags
show_rules.map(&:preferred_variant_tags)
end
def default_rules
# These rules hide a variant_override with tag X and apply to all customers
distributor_rules.select(&:is_default?)
end
def non_default_rules
# These rules show or hide a variant_override with tag X for customer with tag Y
distributor_rules.reject(&:is_default?)
end
def customer_applicable_rules
# Rules which apply specifically to the current customer
@customer_applicable_rules ||= non_default_rules.select{ |rule| customer_tagged?(rule) }
end
def hide_rules
@hide_rules ||= customer_applicable_rules.
select{ |rule| rule.preferred_matched_variants_visibility == 'hidden' }
end
def show_rules
customer_applicable_rules - hide_rules
end
def customer_tagged?(rule)
customer_tag_list.include? rule.preferred_customer_tags
end
def customer_tag_list
customer.andand.tag_list || []
end
end

View File

@@ -0,0 +1,98 @@
require 'open_food_network/scope_product_to_hub'
class ProductsRenderer
class NoProducts < RuntimeError; end
DEFAULT_PAGE = 1
DEFAULT_PER_PAGE = 10
def initialize(distributor, order_cycle, customer, args = {})
@distributor = distributor
@order_cycle = order_cycle
@customer = customer
@args = args
end
def products_json
raise NoProducts unless order_cycle && distributor && products
ActiveModel::ArraySerializer.new(products,
each_serializer: Api::ProductSerializer,
current_order_cycle: order_cycle,
current_distributor: distributor,
variants: variants_for_shop_by_id,
master_variants: master_variants_for_shop_by_id,
enterprise_fee_calculator: enterprise_fee_calculator).to_json
end
private
attr_reader :order_cycle, :distributor, :customer, :args
def products
return unless order_cycle
@products ||= begin
results = distributed_products.products_relation.order(taxon_order)
filter_and_paginate(results).
each { |product| product_scoper.scope(product) } # Scope results with variant_overrides
end
end
def product_scoper
OpenFoodNetwork::ScopeProductToHub.new(distributor)
end
def enterprise_fee_calculator
OpenFoodNetwork::EnterpriseFeeCalculator.new distributor, order_cycle
end
def filter_and_paginate(query)
query.
ransack(args[:q]).
result.
page(args[:page] || DEFAULT_PAGE).
per(args[:per_page] || DEFAULT_PER_PAGE)
end
def distributed_products
OrderCycleDistributedProducts.new(distributor, order_cycle, customer)
end
def taxon_order
if distributor.preferred_shopfront_taxon_order.present?
distributor
.preferred_shopfront_taxon_order
.split(",").map { |id| "primary_taxon_id=#{id} DESC" }
.join(",") + ", name ASC"
else
"name ASC"
end
end
def variants_for_shop
@variants_for_shop ||= begin
scoper = OpenFoodNetwork::ScopeVariantToHub.new(distributor)
distributed_products.variants_relation.
includes(:default_price, :stock_locations, :product).
where(product_id: products).
each { |v| scoper.scope(v) } # Scope results with variant_overrides
end
end
def variants_for_shop_by_id
index_by_product_id variants_for_shop.reject(&:is_master)
end
def master_variants_for_shop_by_id
index_by_product_id variants_for_shop.select(&:is_master)
end
def index_by_product_id(variants)
variants.each_with_object({}) do |v, vs|
vs[v.product_id] ||= []
vs[v.product_id] << v
end
end
end

View File

@@ -1,31 +0,0 @@
- content_for :page_title do
= t(:cache_settings)
= form_tag main_app.admin_cache_settings_path, :method => :put do
.field
= hidden_field_tag 'preferences[enable_products_cache?]', '0'
= check_box_tag 'preferences[enable_products_cache?]', '1', Spree::Config[:enable_products_cache?]
= label_tag nil, t('.enable_products_cache')
.form-buttons
= button t(:update), 'icon-refresh'
%br
%br
%h4= t(:cache_state)
%br
%table.index
%thead
%tr
%th= t('.distributor')
%th= t('.order_cycle')
%th= t('.status')
%th= t('.diff')
%tbody
- @results.each do |result|
%tr
%td= result[:distributor].name
%td= result[:order_cycle].name
%td= result[:status] ? t(:ok) : t('.error')
%td
%pre= result[:diff].to_s(:text)

View File

@@ -1,18 +1,17 @@
%h3
= "#{t(:email_welcome)}!"
= "#{t(".email_welcome")}!"
%p.lead
%strong
= @enterprise.name
= "#{t(:email_registered)} #{ Spree::Config.site_name }!"
= "#{t(".email_registered")} #{ Spree::Config.site_name }!"
%p
= t :email_userguide_html, link: link_to('Open Food Network User Guide', ContentConfig.user_guide_link)
= t(".email_userguide_html", link: link_to(t(".userguide"), ContentConfig.user_guide_link))
%p
= t(".email_admin_html", link: link_to(t(".admin_panel"), spree.admin_url))
%p
= t :email_admin_html, link: link_to('Admin Panel', spree.admin_url)
%p
= t :email_community_html, link: link_to(t(:join_community), ContentConfig.community_forum_url)
= t(".email_community_html", link: link_to(t(".join_community"), ContentConfig.community_forum_url))
= render 'shared/mailers/signoff'

View File

@@ -1,5 +1,5 @@
.filter-shopfront.taxon-selectors.text-right
%single-line-selectors{ selectors: "taxonSelectors", objects: "Products.products | products:query | properties:activeProperties | taxonsOf", "active-selectors" => "activeTaxons"}
.filter-shopfront.taxon-selectors.text-right{ng: {show: 'supplied_taxons != null'}}
%single-line-selectors{ selectors: "taxonSelectors", objects: "supplied_taxons", "active-selectors" => "activeTaxons"}
.filter-shopfront.property-selectors.text-right
%single-line-selectors{ selectors: "propertySelectors", objects: "Products.products | products:query | taxons:activeTaxons | propertiesOf", "active-selectors" => "activeProperties"}
.filter-shopfront.property-selectors.text-right{ng: {show: 'supplied_properties != null'}}
%single-line-selectors{ selectors: "propertySelectors", objects: "supplied_properties", "active-selectors" => "activeProperties"}

View File

@@ -22,14 +22,14 @@
.small-12.medium-6.large-5.columns
%input#search.text{"ng-model" => "query",
placeholder: t(:products_search),
"ng-debounce" => "100",
"ng-debounce" => "200",
"ofn-disable-enter" => true}
.small-12.medium-6.large-6.large-offset-1.columns
= render partial: "shop/products/filters"
%div.pad-top{ "infinite-scroll" => "incrementLimit()", "infinite-scroll-distance" => "1", "infinite-scroll-disabled" => 'filteredProducts.length <= limit' }
%product.animate-repeat{"ng-controller" => "ProductNodeCtrl", "ng-repeat" => "product in visibleProducts track by product.id", "id" => "product-{{ product.id }}"}
%div.pad-top{ "infinite-scroll" => "loadMore()", "infinite-scroll-distance" => "1", "infinite-scroll-disabled" => 'Products.loading' }
%product.animate-repeat{"ng-controller" => "ProductNodeCtrl", "ng-repeat" => "product in Products.products track by product.id", "id" => "product-{{ product.id }}"}
= render "shop/products/summary"
%shop-variant{variant: 'variant', "ng-repeat" => "variant in product.variants | orderBy: ['name_to_display','unit_value'] track by variant.id", "id" => "variant-{{ variant.id }}", "ng-class" => "{'out-of-stock': !variant.on_demand && variant.on_hand == 0}"}
@@ -41,7 +41,7 @@
.small-12.columns.text-center
%img.spinner{ src: "/assets/spinning-circles.svg" }
%div{"ng-show" => "filteredProducts.length == 0 && !Products.loading"}
%div{"ng-show" => "Products.products.length == 0 && !Products.loading"}
.row.summary
.small-12.columns
%p.no-results

View File

@@ -0,0 +1,60 @@
%div
.row
.alpha.six.columns
%fieldset.no-border-bottom
%legend{align: "center"}= t("spree.general")
.field
= preference_field_tag("enable_mail_delivery", Spree::Config[:enable_mail_delivery], type: :boolean)
= label_tag :enable_mail_delivery, t("spree.enable_mail_delivery")
.field
= label_tag :mails_from, t("spree.send_mails_as")
%br/
= text_field_tag :mails_from, Spree::Config[:mails_from], maxlength: 256, class: 'fullwidth'
%br/
%span.info
= t("spree.smtp_send_all_emails_as_from_following_address")
.field
= label_tag :mail_bcc, t("spree.send_copy_of_all_mails_to")
%br/
= text_field_tag :mail_bcc, Spree::Config[:mail_bcc], maxlength: 256, class: 'fullwidth'
%br/
%span.info
= t("spree.smtp_send_copy_to_this_addresses")
.field
= label_tag :intercept_email, t("spree.intercept_email_address")
%br/
= text_field_tag :intercept_email, Spree::Config[:intercept_email], maxlength: 256, class: 'fullwidth'
%br/
%span.info
= t("spree.intercept_email_instructions")
.six.columns.omega
%fieldset.no-border-bottom
%legend{align: "center"}= t("spree.smtp")
.field
= label_tag :mail_domain, t("spree.smtp_domain")
%br/
= text_field_tag :mail_domain, Spree::Config[:mail_domain], class: 'fullwidth'
.field
= label_tag :mail_host, t("spree.smtp_mail_host")
%br/
= text_field_tag :mail_host, Spree::Config[:mail_host], class: 'fullwidth'
.field
= label_tag :mail_port, t("spree.smtp_port")
%br/
= text_field_tag :mail_port, Spree::Config[:mail_port], class: 'fullwidth'
.field
= label_tag :secure_connection_type, t("spree.secure_connection_type")
%br/
= select_tag(:secure_connection_type, options_from_collection_for_select(Spree::Core::MailSettings::SECURE_CONNECTION_TYPES.map{|w| Spree.t(w.downcase.to_sym, default: w)}, :to_s, :to_s, Spree::Config[:secure_connection_type]), class: 'select2 fullwidth')
.field
= label_tag :mail_auth_type, t("spree.smtp_authentication_type")
%br/
= select_tag(:mail_auth_type, options_from_collection_for_select(Spree::Core::MailSettings::MAIL_AUTH.map{|w| Spree.t(w.downcase.to_sym, default: w)}, :to_s, :to_s, Spree::Config[:mail_auth_type]), class: 'select2 fullwidth')
.field
= label_tag :smtp_username, t("spree.smtp_username")
%br/
= text_field_tag :smtp_username, Spree::Config[:smtp_username], class: 'fullwidth'
.field
= label_tag :preferred_smtp_password, t("spree.smtp_password")
%br/
= password_field_tag :smtp_password, Spree::Config[:smtp_password], class: 'fullwidth'

View File

@@ -0,0 +1,15 @@
= render partial: 'spree/admin/shared/configuration_menu'
- content_for :page_title do
= t("spree.mail_method_settings")
- content_for :page_actions do
%li
= link_to_with_icon 'icon-envelope-alt', t("spree.admin.mail_methods.send_testmail"), testmail_admin_mail_method_path, method: :post, title: t("spree.admin.mail_methods.send_testmail"), class: 'send_mail button no-text'
= render partial: 'spree/shared/error_messages', locals: { target: @mail_method }
= form_tag admin_mail_method_path, method: :put do |f|
%fieldset.no-border-top
= render partial: 'form', locals: { f: f }
.form-buttons.filter-actions.actions= button t("spree.actions.update"), 'icon-refresh'

View File

@@ -1,4 +1,4 @@
= f.field_container :shipping_categories do
= f.label :shipping_category_id, t(:shipping_category)
= f.collection_select(:shipping_category_id, Spree::ShippingCategory.all, :id, :name, {:include_blank => true}, {:class => 'select2 fullwidth'})
= f.collection_select(:shipping_category_id, Spree::ShippingCategory.all, :id, :name, {:include_blank => false}, {:class => 'select2 fullwidth'})
= f.error_message_on :shipping_category_id

View File

@@ -21,7 +21,6 @@
= configurations_sidebar_menu_item Spree.t(:shipping_categories), admin_shipping_categories_path
= configurations_sidebar_menu_item t(:enterprise_fees), main_app.admin_enterprise_fees_path
= configurations_sidebar_menu_item Spree.t(:analytics_trackers), admin_trackers_path
= configurations_sidebar_menu_item t('admin.cache_settings.edit.title'), main_app.edit_admin_cache_settings_path
= configurations_sidebar_menu_item t('admin.contents.edit.title'), main_app.edit_admin_contents_path
= configurations_sidebar_menu_item t('admin.invoice_settings.edit.title'), main_app.edit_admin_invoice_settings_path
= configurations_sidebar_menu_item t('admin.matomo_settings.edit.title'), main_app.edit_admin_matomo_settings_path

View File

@@ -14,9 +14,9 @@
= text_field_tag :unit_value_human, nil, {class: "fullwidth", 'ng-model' => 'unit_value_human', 'ng-change' => 'updateValue()'}
= f.text_field :unit_value, {hidden: true, 'ng-value' => 'unit_value'}
.field
= f.label :unit_description, t(:spree_admin_unit_description)
= f.text_field :unit_description, class: "fullwidth", placeholder: t('admin.products.unit_name_placeholder')
.field
= f.label :unit_description, t(:spree_admin_unit_description)
= f.text_field :unit_description, class: "fullwidth", placeholder: t('admin.products.unit_name_placeholder')
%div
- @product.option_types.each do |option_type|

View File

@@ -56,3 +56,5 @@ SMTP_PASSWORD: 'f00d'
# STRIPE_INSTANCE_PUBLISHABLE_KEY: "pk_test_xxxx" # This can be a test key or a live key
# STRIPE_CLIENT_ID: "ca_xxxx" # This can be a development ID or a production ID
# STRIPE_ENDPOINT_SECRET: "whsec_xxxx"
MEMCACHED_VALUE_MAX_MEGABYTES: 4

View File

@@ -40,7 +40,9 @@ Openfoodnetwork::Application.configure do
# config.logger = SyslogLogger.new
# Use a different cache store in production
config.cache_store = :dalli_store
memcached_value_max_megabytes = ENV.fetch("MEMCACHED_VALUE_MAX_MEGABYTES", 1).to_i
memcached_value_max_bytes = memcached_value_max_megabytes * 1024 * 1024
config.cache_store = :dalli_store, { value_max_bytes: memcached_value_max_bytes }
# Enable serving of images, stylesheets, and JavaScripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"

View File

@@ -40,7 +40,9 @@ Openfoodnetwork::Application.configure do
# config.logger = SyslogLogger.new
# Use a different cache store in production
config.cache_store = :dalli_store
memcached_value_max_megabytes = ENV.fetch("MEMCACHED_VALUE_MAX_MEGABYTES", 1).to_i
memcached_value_max_bytes = memcached_value_max_megabytes * 1024 * 1024
config.cache_store = :dalli_store, { value_max_bytes: memcached_value_max_bytes }
# Enable serving of images, stylesheets, and JavaScripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"

3144
config/locales/ar.yml Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -136,6 +136,14 @@ en:
subject: "Please confirm the email address for %{enterprise}"
welcome:
subject: "%{enterprise} is now on %{sitename}"
email_welcome: "Welcome"
email_registered: "is now part of"
email_userguide_html: "The User Guide with detailed support for setting up your Producer or Hub is here: %{link}"
userguide: "Open Food Network User Guide"
email_admin_html: "You can manage your account by logging into the %{link} or by clicking on the cog in the top right hand side of the homepage, and selecting Administration."
admin_panel: "Admin Panel"
email_community_html: "We also have an online forum for community discussion related to OFN software and the unique challenges of running a food enterprise. You are encouraged to join in. We are constantly evolving and your input into this forum will shape what happens next. %{link}"
join_community: "Join the community"
invite_manager:
subject: "%{enterprise} has invited you to be a manager"
producer_mailer:
@@ -365,16 +373,6 @@ en:
number_localization_settings: "Number Localization Settings"
enable_localized_number: "Use the international thousand/decimal separator logic"
cache_settings:
edit:
title: "Caching"
distributor: "Distributor"
order_cycle: "Order Cycle"
status: "Status"
diff: "Diff"
error: "Error"
enable_products_cache: "Enable Products Cache?"
invoice_settings:
edit:
title: "Invoice Settings"
@@ -1476,15 +1474,7 @@ en:
products_at: "at %{distributor}"
products_elsewhere: "Products found elsewhere"
email_welcome: "Welcome"
email_confirmed: "Thank you for confirming your email address."
email_registered: "is now part of"
email_userguide_html: "The User Guide with detailed support for setting up your Producer or Hub is here:
%{link}"
email_admin_html: "You can manage your account by logging into the %{link} or by clicking on the cog in the top right hand side of the homepage, and selecting Administration."
email_community_html: "We also have an online forum for community discussion related to OFN software and the unique challenges of running a food enterprise. You are encouraged to join in. We are constantly evolving and your input into this forum will shape what happens next.
%{link}"
join_community: "Join the community"
email_confirmation_activate_account: "Before we can activate your new account, we need to confirm your email address."
email_confirmation_greeting: "Hi, %{contact}!"
email_confirmation_profile_created: "A profile for %{name} has been successfully created!

View File

@@ -119,9 +119,9 @@ en_CA:
shipment_mailer:
shipped_email:
dear_customer: "Dear Customer, "
instructions: "Your order has been shipped"
shipment_summary: "Shipment Summary"
subject: "Shipment Notification"
instructions: "Your order has been shipped or picked up."
shipment_summary: "Shipment/Pick Up Summary"
subject: "Shipment/Pick Up Notification"
thanks: "Thank you for your business."
track_information: "Tracking Information: %{tracking}"
track_link: "Tracking Link: %{url}"
@@ -311,7 +311,7 @@ en_CA:
tag_has_rules: "Existing rules for this tag: %{num}"
has_one_rule: "has one rule"
has_n_rules: "has %{num} rules"
unsaved_confirm_leave: "There are unsaved changed on this page. Continue without saving?"
unsaved_confirm_leave: "There are unsaved changes on this page. Continue without saving?"
unsaved_changes: "You have unsaved changes"
shopfront_settings:
embedded_shopfront_settings: "Embedded Shopfront Settings"
@@ -608,7 +608,7 @@ en_CA:
email_address_placeholder: eg. inquiries@fresh-food.com
email_address_tip: "This email address will be displayed in your public profile"
phone: Phone
phone_placeholder: eg. 98 7654 3210
phone_placeholder: eg. 519 885 8888
website: Website
website_placeholder: eg. www.truffles.com
enterprise_fees:
@@ -1196,7 +1196,7 @@ en_CA:
city: City
city_placeholder: eg. Northcote
postcode: Postal Code
postcode_placeholder: eg. 3070
postcode_placeholder: eg. N0B 2L0
suburb: City
state: Province
country: Country
@@ -1452,7 +1452,7 @@ en_CA:
set_a_password: "You will then be prompted to set a password before you are able to administer the enterprise."
mistakenly_sent: "Not sure why you have received this email? Please contact %{owner_email} for more information."
producer_mail_greeting: "Dear"
producer_mail_text_before: "We now have all the consumer orders for the next food drop."
producer_mail_text_before: "We now have all the orders for the next pick-up/delivery."
producer_mail_order_text: "Here is a summary of the orders for your products:"
producer_mail_delivery_instructions: "Stock pickup/delivery instructions:"
producer_mail_signoff: "Thanks and best wishes"
@@ -1469,7 +1469,7 @@ en_CA:
shopping_producers_of_hub: "%{hub}'s producers:"
enterprises_next_closing: "Next order closing"
enterprises_ready_for: "Ready for"
enterprises_choose: "Choose when you want your order:"
enterprises_choose: "Choose from the dropdown:"
maps_open: "Open"
maps_closed: "Closed"
hubs_buy: "Shop for:"
@@ -1600,7 +1600,7 @@ en_CA:
sell_hubs_detail: "Set up a profile for your food enterprise or organisation on the OFN. At any time you can upgrade your profile to a multi-producer shop."
sell_groups_detail: "Set up a tailored directory of enterprises (producers and other food enterprises) for your region or for your organisation."
sell_user_guide: "Find out more in our user guide."
sell_listing_price: "Listing on the OFN is free. Opening and running a shop on OFN is free up to $500 of monthly sales. If you sell more we will invoice you for 2% of sales to a maximum of $100/month. For more detail on pricing visit the Software Platform section via the About link in the top menu."
sell_listing_price: "Listing on the OFN is free. Opening and running a shop on OFN is free up to $500 of monthly sales. If you sell more we will invoice you for 2% of sales to a maximum of $150/month. For more detail on pricing visit the Software Platform section via the About link in the top menu."
sell_embed: "We can also embed an OFN shop in your own customised website or build a customised local food network website for your region."
sell_ask_services: "Ask us about OFN services."
shops_title: Shops
@@ -1741,11 +1741,11 @@ en_CA:
address1_field_placeholder: "e.g. 123 Cranberry Drive"
address1_field_error: "Please enter an address"
address2_field: "Address line 2:"
suburb_field: "Suburb:"
suburb_field_placeholder: "e.g. Northcote"
suburb_field_error: "Please enter a suburb"
suburb_field: "City/Town"
suburb_field_placeholder: "e.g. Kitchener"
suburb_field_error: "Please enter a City or Town"
postcode_field: "Postal Code"
postcode_field_placeholder: "e.g. 3070"
postcode_field_placeholder: "e.g. N0B 2L0"
postcode_field_error: "Postal Code"
state_field: "Province:"
state_field_error: "Province required"
@@ -1758,7 +1758,7 @@ en_CA:
contact_field_placeholder: "Contact Name"
contact_field_required: "You need to enter a primary contact."
phone_field: "Phone number"
phone_field_placeholder: "eg. (03) 1234 5678"
phone_field_placeholder: "eg.(519) 885 8888"
type:
title: "Type"
headline: "Last step to add %{enterprise}!"
@@ -1782,8 +1782,8 @@ en_CA:
enterprise_long_desc_length: "%{num} characters / up to 600 recommended"
enterprise_abn: "Business Number"
enterprise_abn_placeholder: "Number will show on invoices"
enterprise_acn: "Business Number"
enterprise_acn_placeholder: "eg. 123 456 789"
enterprise_acn: "Additional identifier"
enterprise_acn_placeholder: "if entered, will show on invoices"
enterprise_tax_required: "You need to make a selection."
images:
title: "Images"
@@ -1887,10 +1887,10 @@ en_CA:
admin_enterprise_groups_data_powertip_logo: "This is the logo for the group"
admin_enterprise_groups_data_powertip_promo_image: "This image is displayed at the top of the Group profile"
admin_enterprise_groups_contact: "Contact"
admin_enterprise_groups_contact_phone_placeholder: "eg. 98 7654 3210"
admin_enterprise_groups_contact_phone_placeholder: "eg. 519 885 5566"
admin_enterprise_groups_contact_address1_placeholder: "eg. 123 High Street"
admin_enterprise_groups_contact_city: "Suburb"
admin_enterprise_groups_contact_city_placeholder: "eg. Northcote"
admin_enterprise_groups_contact_city: "City/Town"
admin_enterprise_groups_contact_city_placeholder: "eg. Kitchener"
admin_enterprise_groups_contact_zipcode: "Postal Code"
admin_enterprise_groups_contact_zipcode_placeholder: "eg. 3070"
admin_enterprise_groups_contact_state_id: "Province"
@@ -1975,7 +1975,7 @@ en_CA:
change_package: "Change Package"
spree_admin_single_enterprise_hint: "Hint: To allow people to find you, turn on your visibility under"
spree_admin_eg_pickup_from_school: "eg. 'Pick-up from Primary School'"
spree_admin_eg_collect_your_order: "eg. 'Please collect your order from 123 Imaginary St, Northcote, 3070'"
spree_admin_eg_collect_your_order: "eg. 'Please collect your order from 123 Imaginary St, YourCity'"
spree_classification_primary_taxon_error: "Taxon %{taxon} is the primary taxon of %{product} and cannot be deleted"
spree_order_availability_error: "Distributor or order cycle cannot supply the products in your cart"
spree_order_populator_error: "That distributor or order cycle can't supply all the products in your cart. Please choose another."
@@ -2046,7 +2046,7 @@ en_CA:
report_header_first_name: First Name
report_header_last_name: Last Name
report_header_phone: Phone
report_header_suburb: Suburb
report_header_suburb: City/Town
report_header_address: Address
report_header_billing_address: Billing Address
report_header_relationship: Relationship
@@ -2102,7 +2102,7 @@ en_CA:
report_header_taxons: Taxons
report_header_supplier: Supplier
report_header_producer: Producer
report_header_producer_suburb: Producer Suburb
report_header_producer_suburb: Producer City/Town
report_header_unit: Unit
report_header_group_buy_unit_quantity: Group Buy Unit Quantity
report_header_cost: Cost
@@ -2782,6 +2782,7 @@ en_CA:
discount_amount: "Discount Amount"
email: Email
account_updated: "Account updated!"
email_updated: "The account will be updated once the new email is confirmed."
my_account: "My account"
date: "Date"
time: "Time"

View File

@@ -163,7 +163,7 @@ en_GB:
home: "OFN"
title: Open Food Network
welcome_to: 'Welcome to '
site_meta_description: "We begin from the ground up. With farmers and growers ready to tell their stories proudly and truly. With distributors ready to connect people with products fairly and honestly. With buyers who believe that better weekly shopping decisions can seriously change the world."
site_meta_description: "The Open Food Network software platform allows farmers to sell produce online, at a price that works for them. It has been built specifically for selling food so it can handle tricky measures or stock levels that only food has - a dozen eggs, a bunch of parsley, a whole chicken that varies in weight…"
search_by_name: Search by name, town, county or postcode...
producers_join: UK producers are now welcome to join Open Food Network UK.
charges_sales_tax: Charges VAT?
@@ -1302,26 +1302,26 @@ en_GB:
cookies_policy_link: "cookies policy"
cookies_accept_button: "Accept Cookies"
home_shop: Shop Now
brandstory_headline: "Re-imagining Local Food"
brandstory_intro: "A learning community & tools to support local food systems to thrive"
brandstory_part1: "We begin from the ground up. With farmers and growers ready to tell their stories proudly and truly. With distributors ready to connect people with products fairly and honestly. With buyers who believe that better weekly shopping decisions can seriously change the world."
brandstory_part2: "Then we need a way to make it real. A way to empower everyone who grows, sells and buys food. A way to tell all the stories, to handle all the logistics. A way to turn transaction into transformation every day."
brandstory_part3: "So we build an online marketplace that levels the playing field. Its transparent, so it creates real relationships. Its open source, so its owned by everyone. It scales to regions and nations, so people start versions across the world."
brandstory_part4: "It works everywhere. It changes everything."
brandstory_part5_strong: "We call it Open Food Network."
brandstory_part6: "We all love food. Now we can love our food system too."
brandstory_headline: "Growing Local Food Online"
brandstory_intro: "THE online community helping you to build a successful food enterprise"
brandstory_part1: "The Open Food Network software platform allows farmers to sell produce online, at a price that works for them. It has been built specifically for selling food so it can handle tricky measures or stock levels that only food has - a dozen eggs, a bunch of parsley, a whole chicken that varies in weight…"
brandstory_part2: "Food Producers can create an online shop, collect payments, sell through other shops on the platform and access reduced-rate courier services."
brandstory_part3: "Wholesalers can integrate OFN with their existing systems and manage buying groups to  supply customers with their produce through our national network of food hubs and shops."
brandstory_part4: "Communities can bring together producers in their local area to create virtual farmers markets, building a resilient local food economy."
brandstory_part5_strong: "And whats just as important as the software itself are the values which underpin it. "
brandstory_part6: "If you sell good food - as a farmer, farmers market, food co-op, or food hub- then choose software that aligns with your values to build food systems for people and planet, not profit. By working collectively rather than competitively, we share the costs of developing new software, and we ensure that our project is resilient!"
learn_body: "Explore models, stories and resources to support you to develop your fair food business or organisation. Find training, events and other opportunities to learn from peers."
learn_cta: "Get Inspired"
connect_body: "Search our full directories of producers, hubs and groups to find fair food traders near you. List your business or organisation on the OFN so buyers can find you. Join the community to get advice and solve problems together."
connect_cta: "Go Exploring"
system_headline: "Shopping - here's how it works."
system_step1: "1. Search"
system_step1_text: "Search our diverse, independent shops for seasonal local food. Search by neighbourhood and food category, or whether you prefer delivery or pickup."
system_step2: "2. Shop"
system_step2_text: "Transform your transactions with affordable local food from diverse producers and hubs. Know the stories behind your food and the people who make it!"
system_step3: "3. Pick-up / Delivery"
system_step3_text: "Hang on for your delivery, or visit your producer or hub for a more personal connection with your food. Food shopping as diverse as nature intended it."
cta_headline: "Shopping that makes the world a better place."
system_headline: "Selling on OFN - 3 easy steps"
system_step1: "1. Create Your Enterprise"
system_step1_text: "Set up your enterprise with a name, description, photos, contact details and social media links."
system_step2: "2. Add Your Products"
system_step2_text: "Add products to your shop - your own and/or from other producers around you. Set images, descriptions, prices, stock levels and flexible weights and measures."
system_step3: "3. Plan your Deliveries"
system_step3_text: "Set up payment methods. Create multiple pick-up points and delivery details. Create recurring orders and regular distributions."
cta_headline: "The sustainable Food Network of the future."
cta_label: "I'm Ready"
stats_headline: "We're creating a new food system."
stats_producers: "food producers"

View File

@@ -245,6 +245,7 @@ en_US:
expired: has expired, please request a new one
back_to_payments_list: "Back to Payments List"
maestro_or_solo_cards: "Debit cards"
backordered: "Backordered"
on hand: "On Hand"
ship: "Ship"
actions:
@@ -2629,6 +2630,8 @@ en_US:
name_or_sku: "Name or SKU (enter at least first 4 characters of product name)"
resend: Resend
back_to_orders_list: Back To Orders List
return_authorizations: Return Authorizations
cannot_create_returns: Cannot create returns as this order has no shipped units.
select_stock: "Select stock"
location: "Location"
count_on_hand: "Count On Hand"
@@ -2779,6 +2782,7 @@ en_US:
discount_amount: "Discount Amount"
email: Email
account_updated: "Account updated!"
email_updated: "The account will be updated once the new email is confirmed."
my_account: "My account"
date: "Date"
time: "Time"

View File

@@ -111,6 +111,14 @@ nb:
subject: "Vennligst bekreft epostadressen til %{enterprise}"
welcome:
subject: "%{enterprise} er nå på %{sitename}"
email_welcome: "Velkommen"
email_registered: "er nå en del av"
email_userguide_html: "Brukerhåndboken med detaljert støtte om hvordan man kommer i gang som Produsent eller Hub finnes her: %{link}"
userguide: "Brukermanual for Open Food Network"
email_admin_html: "Du kan administrere din konto ved å logge inn på %{link} eller ved klikke på tannhjulet øverst til høyre på hjemmesiden og velge Administrasjon."
admin_panel: "Administrasjonspanel"
email_community_html: "Vi har også et online forum for diskusjon relatert til OFN programvaren og de forskjellige utfordringene med å drive et matfirma. Vi oppfordrer deg til å bli med. Vi utvikler oss hele tiden og dine innspill til dette forumet vil forme det som skjer videre. %{link}"
join_community: "Bli med"
invite_manager:
subject: "%{enterprise} har invitert deg til å være en administrator"
producer_mailer:
@@ -320,15 +328,6 @@ nb:
number_localization:
number_localization_settings: "Innstillinger for nummerlokalisering"
enable_localized_number: "Bruk internasjonale tusen- og desimalskilletegn"
cache_settings:
edit:
title: "Mellomlagring"
distributor: "Distributør"
order_cycle: "Bestillingsrunde"
status: "Status"
diff: "Forskjell"
error: "Feil"
enable_products_cache: "Aktiver Mellomlagring for Produkter?"
invoice_settings:
edit:
title: "Fakturainnstillinger"
@@ -1377,13 +1376,7 @@ nb:
products_in: "i %{oc}"
products_at: "hos %{distributor}"
products_elsewhere: "Produkter funnet andre steder"
email_welcome: "Velkommen"
email_confirmed: "Takk for at du bekrefter din epostadresse"
email_registered: "er nå en del av"
email_userguide_html: "Brukerhåndboken med detaljert støtte om hvordan man kommer i gang som Produsent eller Hub finnes her: %{link}"
email_admin_html: "Du kan administrere din konto ved å logge inn på %{link} eller ved klikke på tannhjulet øverst til høyre på hjemmesiden og velge Administrasjon."
email_community_html: "Vi har også et online forum for diskusjon relatert til OFN programvaren og de forskjellige utfordringene med å drive et matfirma. Vi oppfordrer deg til å bli med. Vi utvikler oss hele tiden og dine innspill til dette forumet vil forme det som skjer videre. %{link}"
join_community: "Bli med"
email_confirmation_activate_account: "Før vi kan aktivere den nye kontoen din, må vi bekrefte epostadressen din."
email_confirmation_greeting: "Hei, %{contact}!"
email_confirmation_profile_created: "En profil for %{name} har blitt opprettet! For å aktivere din profil må du bekrefte denne epostadressen."

View File

@@ -2784,6 +2784,7 @@ pt_BR:
discount_amount: "Valor do desconto"
email: E-mail
account_updated: "Conta atualizada!"
email_updated: "A conta vai ser atualizada assim que o email for confirmado."
my_account: "Minha conta"
date: "Data"
time: "Tempo"
@@ -2938,9 +2939,11 @@ pt_BR:
product_name: "Nome do Produto"
units: "Tamanho da Unidade"
value: "Valor"
unit_name: "Nome da Unidade"
price: "Preço"
on_hand: "Disponível"
on_demand: "Sob Encomenda"
product_description: "Descrição do Produto"
image: "Imagem"
or: "ou"
unit_name_placeholder: 'por exemplo. cachos'

View File

@@ -33,7 +33,6 @@ Openfoodnetwork::Application.routes.draw do
end
resource :shop, controller: "shop" do
get :products
post :order_cycle
get :order_cycle
get :changeable_orders_alert

View File

@@ -75,8 +75,6 @@ Openfoodnetwork::Application.routes.draw do
resource :contents
resource :cache_settings
resources :column_preferences, only: [], format: :json do
put :bulk_update, on: :collection
end

View File

@@ -15,7 +15,7 @@ Openfoodnetwork::Application.routes.draw do
resources :variants, :only => [:index]
resources :orders, only: [:index] do
resources :orders, only: [:index, :show] do
get :managed, on: :collection
resources :shipments, :only => [:create, :update] do
@@ -44,6 +44,10 @@ Openfoodnetwork::Application.routes.draw do
resources :order_cycles do
get :managed, on: :collection
get :accessible, on: :collection
get :products, on: :member
get :taxons, on: :member
get :properties, on: :member
end
resource :status do

View File

@@ -90,6 +90,23 @@ Spree::Core::Engine.routes.prepend do
end
# Configuration section
resource :general_settings do
collection do
post :dismiss_alert
end
end
resource :mail_method, :only => [:edit, :update] do
post :testmail, :on => :collection
end
resource :image_settings
resources :zones
resources :countries do
resources :states
end
resources :states
resources :taxonomies do
collection do
post :update_positions
@@ -109,12 +126,6 @@ Spree::Core::Engine.routes.prepend do
resources :tax_rates
resource :tax_settings
resources :tax_categories
resources :zones
resources :countries do
resources :states
end
resources :states
end
resources :orders do

View File

@@ -12,10 +12,6 @@ job_type :run_file, "cd :path; :environment_variable=:environment bundle exec sc
job_type :enqueue_job, "cd :path; :environment_variable=:environment bundle exec script/enqueue :task :priority :output"
every 1.day, at: '01:00am' do
rake 'ofn:cache:check_products_integrity'
end
every 1.day, at: '2:45am' do
rake 'db2fog:clean' if ENV['S3_BACKUPS_BUCKET']
end

View File

@@ -0,0 +1,9 @@
class DropOrdersShippingMethodId < ActiveRecord::Migration
def up
remove_column :spree_orders, :shipping_method_id
end
def down
add_column :spree_orders, :shipping_method_id, :integer
end
end

View File

@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20190918105234) do
ActiveRecord::Schema.define(:version => 20190922201034) do
create_table "adjustment_metadata", :force => true do |t|
t.integer "adjustment_id"
@@ -563,7 +563,6 @@ ActiveRecord::Schema.define(:version => 20190918105234) do
t.integer "bill_address_id"
t.integer "ship_address_id"
t.decimal "payment_total", :precision => 10, :scale => 2, :default => 0.0
t.integer "shipping_method_id"
t.string "shipment_state"
t.string "payment_state"
t.string "email"

View File

@@ -52,3 +52,4 @@ end
require File.join(File.dirname(__FILE__), 'default', 'users')
DefaultStockLocation.find_or_create
DefaultShippingCategory.find_or_create

View File

@@ -7,6 +7,7 @@ services:
environment:
POSTGRES_PASSWORD: f00d
POSTGRES_USER: ofn
POSTGRES_DB: open_food_network_dev
volumes:
- 'postgres:/var/lib/postgresql/data'
web:

View File

@@ -1,48 +0,0 @@
require 'open_food_network/products_renderer'
# Wrapper for ProductsRenderer that caches the JSON output.
# ProductsRenderer::NoProducts is represented in the cache as nil,
# but re-raised to provide the same interface as ProductsRenderer.
module OpenFoodNetwork
class CachedProductsRenderer
class NoProducts < RuntimeError; end
def initialize(distributor, order_cycle)
@distributor = distributor
@order_cycle = order_cycle
end
def products_json
raise NoProducts, I18n.t(:no_products) if @distributor.nil? || @order_cycle.nil?
products_json = cached_products_json
raise NoProducts, I18n.t(:no_products) if products_json.nil?
products_json
end
private
def cached_products_json
return uncached_products_json unless use_cached_products?
Rails.cache.fetch("products-json-#{@distributor.id}-#{@order_cycle.id}") do
begin
uncached_products_json
rescue ProductsRenderer::NoProducts
nil
end
end
end
def use_cached_products?
Spree::Config[:enable_products_cache?]
end
def uncached_products_json
ProductsRenderer.new(@distributor, @order_cycle).products_json
end
end
end

View File

@@ -1,295 +1,55 @@
require "open_food_network/reports/line_items"
require "open_food_network/orders_and_fulfillments_report/supplier_totals_report"
require "open_food_network/orders_and_fulfillments_report/supplier_totals_by_distributor_report"
require "open_food_network/orders_and_fulfillments_report/distributor_totals_by_supplier_report"
require "open_food_network/orders_and_fulfillments_report/customer_totals_report"
require 'open_food_network/orders_and_fulfillments_report/default_report'
include Spree::ReportsHelper
module OpenFoodNetwork
class OrdersAndFulfillmentsReport
attr_reader :params
def initialize(permissions, params = {}, render_table = false)
@params = params
attr_reader :options, :report_type
delegate :header, :rules, :columns, to: :report
def initialize(permissions, options = {}, render_table = false)
@options = options
@report_type = options[:report_type]
@permissions = permissions
@render_table = render_table
end
def header
case params[:report_type]
when "order_cycle_supplier_totals"
[I18n.t(:report_header_producer), I18n.t(:report_header_product), I18n.t(:report_header_variant), I18n.t(:report_header_amount),
I18n.t(:report_header_total_units), I18n.t(:report_header_curr_cost_per_unit), I18n.t(:report_header_total_cost),
I18n.t(:report_header_status), I18n.t(:report_header_incoming_transport)]
when "order_cycle_supplier_totals_by_distributor"
[I18n.t(:report_header_producer), I18n.t(:report_header_product), I18n.t(:report_header_variant), I18n.t(:report_header_to_hub),
I18n.t(:report_header_amount), I18n.t(:report_header_curr_cost_per_unit), I18n.t(:report_header_total_cost),
I18n.t(:report_header_shipping_method)]
when "order_cycle_distributor_totals_by_supplier"
[I18n.t(:report_header_hub), I18n.t(:report_header_producer), I18n.t(:report_header_product), I18n.t(:report_header_variant),
I18n.t(:report_header_amount), I18n.t(:report_header_curr_cost_per_unit), I18n.t(:report_header_total_cost),
I18n.t(:report_header_total_shipping_cost), I18n.t(:report_header_shipping_method)]
when "order_cycle_customer_totals"
[I18n.t(:report_header_hub), I18n.t(:report_header_customer), I18n.t(:report_header_email), I18n.t(:report_header_phone),
I18n.t(:report_header_producer), I18n.t(:report_header_product), I18n.t(:report_header_variant), I18n.t(:report_header_amount),
I18n.t(:report_header_item_price, currency: currency_symbol),
I18n.t(:report_header_item_fees_price, currency: currency_symbol),
I18n.t(:report_header_admin_handling_fees, currency: currency_symbol),
I18n.t(:report_header_ship_price, currency: currency_symbol),
I18n.t(:report_header_pay_fee_price, currency: currency_symbol),
I18n.t(:report_header_total_price, currency: currency_symbol),
I18n.t(:report_header_paid), I18n.t(:report_header_shipping), I18n.t(:report_header_delivery),
I18n.t(:report_header_ship_street), I18n.t(:report_header_ship_street_2), I18n.t(:report_header_ship_city), I18n.t(:report_header_ship_postcode), I18n.t(:report_header_ship_state),
I18n.t(:report_header_comments), I18n.t(:report_header_sku),
I18n.t(:report_header_order_cycle), I18n.t(:report_header_payment_method), I18n.t(:report_header_customer_code), I18n.t(:report_header_tags),
I18n.t(:report_header_billing_street), I18n.t(:report_header_billing_street_2), I18n.t(:report_header_billing_city), I18n.t(:report_header_billing_postcode), I18n.t(:report_header_billing_state),]
else
DefaultReport.new(self).header
end
end
def search
Reports::LineItems.search_orders(permissions, params)
Reports::LineItems.search_orders(permissions, options)
end
def table_items
return [] unless @render_table
Reports::LineItems.list(permissions, params)
end
def rules
case params[:report_type]
when "order_cycle_supplier_totals"
[
{
group_by: proc { |line_item| line_item.variant.product.supplier },
sort_by: proc { |supplier| supplier.name }
},
{
group_by: proc { |line_item| line_item.variant.product },
sort_by: proc { |product| product.name }
},
{
group_by: proc { |line_item| line_item.variant.full_name },
sort_by: proc { |full_name| full_name }
}
]
when "order_cycle_supplier_totals_by_distributor"
[
{
group_by: proc { |line_item| line_item.variant.product.supplier },
sort_by: proc { |supplier| supplier.name }
},
{
group_by: proc { |line_item| line_item.variant.product },
sort_by: proc { |product| product.name }
},
{
group_by: proc { |line_item| line_item.variant.full_name },
sort_by: proc { |full_name| full_name },
summary_columns: [
proc { |_line_items| "" },
proc { |_line_items| "" },
proc { |_line_items| "" },
proc { |_line_items| I18n.t('admin.reports.total') },
proc { |_line_items| "" },
proc { |_line_items| "" },
proc { |line_items| line_items.sum(&:amount) },
proc { |_line_items| "" }
]
},
{
group_by: proc { |line_item| line_item.order.distributor },
sort_by: proc { |distributor| distributor.name }
}
]
when "order_cycle_distributor_totals_by_supplier"
[
{
group_by: proc { |line_item| line_item.order.distributor },
sort_by: proc { |distributor| distributor.name },
summary_columns: [
proc { |_line_items| "" },
proc { |_line_items| I18n.t('admin.reports.total') },
proc { |_line_items| "" },
proc { |_line_items| "" },
proc { |_line_items| "" },
proc { |_line_items| "" },
proc { |line_items| line_items.sum(&:amount) },
proc { |line_items| line_items.map(&:order).uniq.sum(&:ship_total) },
proc { |_line_items| "" }
]
},
{
group_by: proc { |line_item| line_item.variant.product.supplier },
sort_by: proc { |supplier| supplier.name }
},
{
group_by: proc { |line_item| line_item.variant.product },
sort_by: proc { |product| product.name }
},
{
group_by: proc { |line_item| line_item.variant.full_name },
sort_by: proc { |full_name| full_name }
}
]
when "order_cycle_customer_totals"
[
{
group_by: proc { |line_item| line_item.order.distributor },
sort_by: proc { |distributor| distributor.name }
},
{
group_by: proc { |line_item| line_item.order },
sort_by: proc { |order| order.bill_address.full_name_reverse },
summary_columns: [
proc { |line_items| line_items.first.order.distributor.name },
proc { |line_items| line_items.first.order.bill_address.full_name },
proc { |_line_items| "" },
proc { |_line_items| "" },
proc { |_line_items| "" },
proc { |_line_items| I18n.t('admin.reports.total') },
proc { |_line_items| "" },
proc { |_line_items| "" },
proc { |line_items| line_items.sum(&:amount) },
proc { |line_items| line_items.sum(&:amount_with_adjustments) },
proc { |line_items| line_items.first.order.admin_and_handling_total },
proc { |line_items| line_items.first.order.ship_total },
proc { |line_items| line_items.first.order.payment_fee },
proc { |line_items| line_items.first.order.total },
proc { |line_items| line_items.first.order.paid? ? I18n.t(:yes) : I18n.t(:no) },
proc { |_line_items| "" },
proc { |_line_items| "" },
proc { |_line_items| "" },
proc { |_line_items| "" },
proc { |_line_items| "" },
proc { |_line_items| "" },
proc { |_line_items| "" },
proc { |line_items| line_items.first.order.special_instructions },
proc { |_line_items| "" },
proc { |line_items| line_items.first.order.order_cycle.andand.name },
proc { |line_items|
line_items.first.order.payments.first.andand.payment_method.andand.name
},
proc { |_line_items| "" },
proc { |_line_items| "" },
proc { |_line_items| "" },
proc { |_line_items| "" },
proc { |_line_items| "" },
proc { |_line_items| "" },
proc { |_line_items| "" }
]
},
{
group_by: proc { |line_item| line_item.variant.product },
sort_by: proc { |product| product.name }
},
{
group_by: proc { |line_item| line_item.variant },
sort_by: proc { |variant| variant.full_name }
},
{
group_by: line_item_name,
sort_by: proc { |full_name| full_name }
}
]
else
DefaultReport.new(self).rules
end
end
# Returns a proc for each column displayed in each report type containing
# the logic to compute the value for each cell.
def columns
case params[:report_type]
when "order_cycle_supplier_totals"
[
supplier_name,
product_name,
line_items_name,
proc { |line_items| line_items.sum(&:quantity) },
proc { |line_items| total_units(line_items) },
proc { |line_items| line_items.first.price },
proc { |line_items| line_items.sum(&:amount) },
proc { |_line_items| "" },
proc { |_line_items| I18n.t(:report_header_incoming_transport) }
]
when "order_cycle_supplier_totals_by_distributor"
[
supplier_name,
proc { |line_items| line_items.first.variant.product.name },
proc { |line_items| line_items.first.variant.full_name },
proc { |line_items| line_items.first.order.distributor.name },
proc { |line_items| line_items.sum(&:quantity) },
proc { |line_items| line_items.first.price },
proc { |line_items| line_items.sum(&:amount) },
proc { |_line_items| I18n.t(:report_header_shipping_method) }
]
when "order_cycle_distributor_totals_by_supplier"
[proc { |line_items| line_items.first.order.distributor.name },
proc { |line_items| line_items.first.variant.product.supplier.name },
proc { |line_items| line_items.first.variant.product.name },
proc { |line_items| line_items.first.variant.full_name },
proc { |line_items| line_items.sum(&:quantity) },
proc { |line_items| line_items.first.price },
proc { |line_items| line_items.sum(&:amount) },
proc { |_line_items| "" },
proc { |_line_items| I18n.t(:report_header_shipping_method) }]
when "order_cycle_customer_totals"
rsa = proc { |line_items| line_items.first.order.shipping_method.andand.delivery? }
[
proc { |line_items| line_items.first.order.distributor.name },
proc { |line_items| line_items.first.order.bill_address.firstname + " " + line_items.first.order.bill_address.lastname },
proc { |line_items| line_items.first.order.email },
proc { |line_items| line_items.first.order.bill_address.phone },
proc { |line_items| line_items.first.variant.product.supplier.name },
proc { |line_items| line_items.first.variant.product.name },
proc { |line_items| line_items.first.variant.full_name },
proc { |line_items| line_items.sum(&:quantity) },
proc { |line_items| line_items.sum(&:amount) },
proc { |line_items| line_items.sum(&:amount_with_adjustments) },
proc { |_line_items| "" },
proc { |_line_items| "" },
proc { |_line_items| "" },
proc { |_line_items| "" },
proc { |line_items| line_items.all? { |li| li.order.paid? } ? I18n.t(:yes) : I18n.t(:no) },
proc { |line_items| line_items.first.order.shipping_method.andand.name },
proc { |line_items| rsa.call(line_items) ? I18n.t(:yes) : I18n.t(:no) },
proc { |line_items| line_items.first.order.ship_address.andand.address1 if rsa.call(line_items) },
proc { |line_items| line_items.first.order.ship_address.andand.address2 if rsa.call(line_items) },
proc { |line_items| line_items.first.order.ship_address.andand.city if rsa.call(line_items) },
proc { |line_items| line_items.first.order.ship_address.andand.zipcode if rsa.call(line_items) },
proc { |line_items| line_items.first.order.ship_address.andand.state if rsa.call(line_items) },
proc { |_line_items| "" },
proc { |line_items| line_items.first.variant.sku },
proc { |line_items| line_items.first.order.order_cycle.andand.name },
proc { |line_items| line_items.first.order.payments.first.andand.payment_method.andand.name },
proc { |line_items| line_items.first.order.user.andand.customer_of(line_items.first.order.distributor).andand.code },
proc { |line_items| line_items.first.order.user.andand.customer_of(line_items.first.order.distributor).andand.tags.andand.join(', ') },
proc { |line_items| line_items.first.order.bill_address.andand.address1 },
proc { |line_items| line_items.first.order.bill_address.andand.address2 },
proc { |line_items| line_items.first.order.bill_address.andand.city },
proc { |line_items| line_items.first.order.bill_address.andand.zipcode },
proc { |line_items| line_items.first.order.bill_address.andand.state }
]
else
DefaultReport.new(self).columns
end
list_options = options.merge(line_item_includes: report.line_item_includes)
Reports::LineItems.list(permissions, list_options)
end
private
attr_reader :permissions
def report
@report ||= report_klass.new(self)
end
def report_klass
case report_type
when SupplierTotalsReport::REPORT_TYPE then SupplierTotalsReport
when SupplierTotalsByDistributorReport::REPORT_TYPE then SupplierTotalsByDistributorReport
when DistributorTotalsBySupplierReport::REPORT_TYPE then DistributorTotalsBySupplierReport
when CustomerTotalsReport::REPORT_TYPE then CustomerTotalsReport
else
DefaultReport
end
end
def supplier_name
proc { |line_items| line_items.first.variant.product.supplier.name }
end

Some files were not shown because too many files have changed in this diff Show More