mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-14 18:56:49 +00:00
Compare commits
289 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
34e6f92d0c | ||
|
|
28570cded2 | ||
|
|
c0bb9aad5e | ||
|
|
b281e7e9e5 | ||
|
|
66b531ddf6 | ||
|
|
213f3cf072 | ||
|
|
e1962419c2 | ||
|
|
bb6f5cb3a7 | ||
|
|
db3576f469 | ||
|
|
c2362921fa | ||
|
|
0668dd2591 | ||
|
|
d8f9dead8b | ||
|
|
bc96ad9515 | ||
|
|
bd4da3b5ce | ||
|
|
8e3f0d2152 | ||
|
|
1ea503ed5d | ||
|
|
719007ecb4 | ||
|
|
bd06f898a3 | ||
|
|
246a1f368b | ||
|
|
f6443f00e5 | ||
|
|
fd52800d2c | ||
|
|
4b1f5ae060 | ||
|
|
31a34fc9d2 | ||
|
|
3fc0d1bcb9 | ||
|
|
bb89557beb | ||
|
|
0ae3bf985a | ||
|
|
387326b9b4 | ||
|
|
cb80f67dc6 | ||
|
|
3170db9532 | ||
|
|
42d5f377e0 | ||
|
|
f513d888a3 | ||
|
|
5cde085241 | ||
|
|
23956726e9 | ||
|
|
f6d0905517 | ||
|
|
c2591104ee | ||
|
|
3beea43143 | ||
|
|
8f2d52b9e3 | ||
|
|
eada388534 | ||
|
|
f6f4faf146 | ||
|
|
5c4ea1a6be | ||
|
|
72c454a211 | ||
|
|
543a9592c7 | ||
|
|
2ce96f4bbe | ||
|
|
00d121ebfc | ||
|
|
c785d0d1d7 | ||
|
|
80cbe6b30f | ||
|
|
09aef524f3 | ||
|
|
805b4d243e | ||
|
|
a07029f660 | ||
|
|
ccab133d63 | ||
|
|
a51645f316 | ||
|
|
4125fe1690 | ||
|
|
6950d7717f | ||
|
|
ab53db0c61 | ||
|
|
1b4a4a8113 | ||
|
|
66fb3a9cf3 | ||
|
|
79a7cf9b39 | ||
|
|
a18a198812 | ||
|
|
0ca71ce0a9 | ||
|
|
b7aa04353c | ||
|
|
bfeebccbc5 | ||
|
|
4b21667974 | ||
|
|
9bbeec5031 | ||
|
|
af3057f55f | ||
|
|
e8381304f9 | ||
|
|
58a476751b | ||
|
|
3320a3f0bc | ||
|
|
4c6708267a | ||
|
|
2f0d61d54f | ||
|
|
451d8488d9 | ||
|
|
bcca2eee9d | ||
|
|
1bce516a45 | ||
|
|
f6195f1159 | ||
|
|
503c17f896 | ||
|
|
795b7101ab | ||
|
|
9d4a15b0e0 | ||
|
|
459959c068 | ||
|
|
ba16de6627 | ||
|
|
72a39fdf54 | ||
|
|
4b8515358c | ||
|
|
cf7d8067df | ||
|
|
d4e4669e49 | ||
|
|
e9f76cb339 | ||
|
|
b68c5ee0f9 | ||
|
|
072cd2bd54 | ||
|
|
2f8198eecc | ||
|
|
f85044e035 | ||
|
|
751beceb34 | ||
|
|
8cb75fc6d8 | ||
|
|
d147996af6 | ||
|
|
daff0a250c | ||
|
|
65bccb9236 | ||
|
|
efe5a4700a | ||
|
|
0103cc3a2f | ||
|
|
2a2c7bdc4e | ||
|
|
ad76f3e91e | ||
|
|
201c9c109d | ||
|
|
4911bb6613 | ||
|
|
9de74500cd | ||
|
|
04f5249176 | ||
|
|
5c81f645c9 | ||
|
|
6ff8cadb26 | ||
|
|
04358dfa39 | ||
|
|
b23d6674b5 | ||
|
|
8904273bea | ||
|
|
1bb7fd9ec8 | ||
|
|
0af20e48b0 | ||
|
|
bc40088eaf | ||
|
|
1abdd0112e | ||
|
|
bc6ffe3b0c | ||
|
|
eea73aa989 | ||
|
|
03b0ce430d | ||
|
|
bfce012a4b | ||
|
|
fb3dd0aa18 | ||
|
|
01320105ea | ||
|
|
c2c12b34f9 | ||
|
|
c71ebc38bb | ||
|
|
4b03dec119 | ||
|
|
ca1373a366 | ||
|
|
b0e889be2a | ||
|
|
b3196295e6 | ||
|
|
75cec3b606 | ||
|
|
92417d849c | ||
|
|
bf5fcde885 | ||
|
|
40f8c785a2 | ||
|
|
403384dbb1 | ||
|
|
c30cba8bfe | ||
|
|
e8138e8c23 | ||
|
|
4845cde20f | ||
|
|
a8265aff89 | ||
|
|
9cb3b0b14a | ||
|
|
06433b1be3 | ||
|
|
d4c52ce122 | ||
|
|
eb4e732c1a | ||
|
|
3fe2684270 | ||
|
|
3e6e338e3d | ||
|
|
ad14f7f9b0 | ||
|
|
7cc7c62232 | ||
|
|
b6dc46a911 | ||
|
|
0b70c67908 | ||
|
|
71a181341b | ||
|
|
cf3f511f4d | ||
|
|
1d1067ebc1 | ||
|
|
bd4d0ba5d3 | ||
|
|
3b682bc47f | ||
|
|
be35f97622 | ||
|
|
ca79270ba3 | ||
|
|
2cf7b1b36c | ||
|
|
f7c07f492c | ||
|
|
9f17e4fd8f | ||
|
|
c980d22826 | ||
|
|
ceee89fad0 | ||
|
|
a942218708 | ||
|
|
26946ec102 | ||
|
|
dd31cbe014 | ||
|
|
46733d0c0d | ||
|
|
57a9d6e1e2 | ||
|
|
ad592785cf | ||
|
|
f3ba0ebdbb | ||
|
|
4d64bf6ece | ||
|
|
3c9c5862d1 | ||
|
|
78a8f53d8d | ||
|
|
806c8b943d | ||
|
|
85096a997f | ||
|
|
19b6cb13f1 | ||
|
|
dd228cc750 | ||
|
|
5aa8c783b1 | ||
|
|
5a66c855bc | ||
|
|
ea3c456d3b | ||
|
|
586e8a9abe | ||
|
|
1847b62cf4 | ||
|
|
0618c9e4dd | ||
|
|
d15301021a | ||
|
|
55e8dace44 | ||
|
|
9a9b455e66 | ||
|
|
399fe2c01b | ||
|
|
3aeb87debc | ||
|
|
7b06fdd943 | ||
|
|
6755354196 | ||
|
|
440e69e156 | ||
|
|
a53223aefc | ||
|
|
cc1b4123b7 | ||
|
|
65ce183830 | ||
|
|
7e606471e4 | ||
|
|
1dace1f0e3 | ||
|
|
08d26102d2 | ||
|
|
35790b3cca | ||
|
|
2ce05d48bf | ||
|
|
f4c7a0b2a2 | ||
|
|
6b826423c1 | ||
|
|
412457bb19 | ||
|
|
2605b9cdf0 | ||
|
|
867947f6b2 | ||
|
|
8d9b33abe8 | ||
|
|
57fe1db10e | ||
|
|
18d2599075 | ||
|
|
292b33b4ea | ||
|
|
8591934c19 | ||
|
|
9bf84bd5a8 | ||
|
|
67a603f77f | ||
|
|
331ac28b71 | ||
|
|
3ead050a56 | ||
|
|
23dd09eaad | ||
|
|
8585e6c7f0 | ||
|
|
866452383d | ||
|
|
402fc902ff | ||
|
|
8f21b66b96 | ||
|
|
c9b540677c | ||
|
|
4f579facfe | ||
|
|
fa62ec0bff | ||
|
|
cb3ea133e9 | ||
|
|
10490536e2 | ||
|
|
a43737af8b | ||
|
|
0138f04506 | ||
|
|
4a2684e3d9 | ||
|
|
e860e2ca57 | ||
|
|
da69dca471 | ||
|
|
e4f3aae7c0 | ||
|
|
72ae7ea8a2 | ||
|
|
8f95de10bc | ||
|
|
cbe1b53189 | ||
|
|
9c30c3c0ed | ||
|
|
9a03428412 | ||
|
|
76afc0b407 | ||
|
|
200e9c5078 | ||
|
|
caea5b2aa8 | ||
|
|
3730d76b44 | ||
|
|
28c25cff2c | ||
|
|
20edcfab26 | ||
|
|
642787b95a | ||
|
|
a1438d3b2e | ||
|
|
fc8e3d1ece | ||
|
|
21991515df | ||
|
|
3534559fbf | ||
|
|
f1373b902c | ||
|
|
e5e67fbdf0 | ||
|
|
f1e80e92de | ||
|
|
c5186c2412 | ||
|
|
52f56baa8c | ||
|
|
0b51d8b297 | ||
|
|
0f5aa11f05 | ||
|
|
00624d1b96 | ||
|
|
7e8aaaa5f9 | ||
|
|
49b8dcb880 | ||
|
|
479520bf97 | ||
|
|
b66b50cd56 | ||
|
|
50cbc971a1 | ||
|
|
7178a69a54 | ||
|
|
e06e8fc460 | ||
|
|
ee402db734 | ||
|
|
3f1e496731 | ||
|
|
494f0d8ff6 | ||
|
|
15715f9bb4 | ||
|
|
4baf53a0a9 | ||
|
|
8041111886 | ||
|
|
adc2bcb442 | ||
|
|
8a51c5cb5d | ||
|
|
e114d58ff2 | ||
|
|
b7fc3df86a | ||
|
|
01fe12e72b | ||
|
|
c5e125747f | ||
|
|
3baaa5cc40 | ||
|
|
e29d6048c2 | ||
|
|
c4ba8db7ed | ||
|
|
764169c9ca | ||
|
|
30a1832302 | ||
|
|
a07f64f8a8 | ||
|
|
ca2d66eacf | ||
|
|
c65108731c | ||
|
|
5928eba767 | ||
|
|
874d33caaa | ||
|
|
66be86cca9 | ||
|
|
35110eaf4a | ||
|
|
c62f1bd550 | ||
|
|
2cc751cb30 | ||
|
|
2ec35b6306 | ||
|
|
e963ab4bd4 | ||
|
|
14eee1c9e4 | ||
|
|
ff049d33e7 | ||
|
|
b02e25af0e | ||
|
|
76293c335b | ||
|
|
01d2c3cb9e | ||
|
|
80c76606df | ||
|
|
b07fbec8c6 | ||
|
|
c4205fce34 | ||
|
|
a959f8e745 | ||
|
|
437c39f795 | ||
|
|
27f1aeb803 | ||
|
|
6d169c1b08 |
@@ -42,7 +42,6 @@ Layout/LineLength:
|
||||
- app/helpers/angular_form_helper.rb
|
||||
- app/helpers/checkout_helper.rb
|
||||
- app/helpers/enterprises_helper.rb
|
||||
- app/helpers/injection_helper.rb
|
||||
- app/helpers/markdown_helper.rb
|
||||
- app/helpers/order_cycles_helper.rb
|
||||
- app/helpers/spree/orders_helper.rb
|
||||
@@ -62,11 +61,10 @@ Layout/LineLength:
|
||||
- app/models/product_import/unit_converter.rb
|
||||
- app/models/proxy_order.rb
|
||||
- app/models/schedule.rb
|
||||
- app/models/spree/app_configuration_decorator.rb
|
||||
- app/models/spree/app_configuration.rb
|
||||
- app/models/spree/gateway/stripe_connect.rb
|
||||
- app/models/spree/image.rb
|
||||
- app/models/spree/line_item_decorator.rb
|
||||
- app/models/spree/order_decorator.rb
|
||||
- app/models/spree/order.rb
|
||||
- app/models/spree/payment_method.rb
|
||||
- app/models/spree/product_decorator.rb
|
||||
- app/models/spree/user.rb
|
||||
@@ -75,6 +73,7 @@ Layout/LineLength:
|
||||
- app/models/variant_override_set.rb
|
||||
- app/serializers/api/admin/subscription_line_item_serializer.rb
|
||||
- app/services/cart_service.rb
|
||||
- app/services/checkout/post_checkout_actions.rb
|
||||
- app/services/default_stock_location.rb
|
||||
- app/services/embedded_page_service.rb
|
||||
- app/services/order_cycle_form.rb
|
||||
@@ -88,6 +87,7 @@ Layout/LineLength:
|
||||
- Gemfile
|
||||
- lib/discourse/single_sign_on.rb
|
||||
- lib/open_food_network/available_payment_method_filter.rb
|
||||
- lib/open_food_network/bulk_coop_report.rb
|
||||
- lib/open_food_network/customers_report.rb
|
||||
- lib/open_food_network/enterprise_fee_applicator.rb
|
||||
- lib/open_food_network/enterprise_fee_calculator.rb
|
||||
@@ -101,7 +101,6 @@ Layout/LineLength:
|
||||
- lib/open_food_network/scope_variants_for_search.rb
|
||||
- lib/open_food_network/xero_invoices_report.rb
|
||||
- lib/spree/localized_number.rb
|
||||
- lib/spree/product_filters.rb
|
||||
- lib/tasks/data.rake
|
||||
- lib/tasks/enterprises.rake
|
||||
- spec/controllers/admin/bulk_line_items_controller_spec.rb
|
||||
@@ -263,12 +262,17 @@ Layout/LineLength:
|
||||
- spec/models/spree/adjustment_spec.rb
|
||||
- spec/models/spree/classification_spec.rb
|
||||
- spec/models/spree/gateway/stripe_connect_spec.rb
|
||||
- spec/models/spree/inventory_unit_spec.rb
|
||||
- spec/models/spree/line_item_spec.rb
|
||||
- spec/models/spree/order/checkout_spec.rb
|
||||
- spec/models/spree/order_inventory_spec.rb
|
||||
- spec/models/spree/order_spec.rb
|
||||
- spec/models/spree/order/state_machine_spec.rb
|
||||
- spec/models/spree/payment_method_spec.rb
|
||||
- spec/models/spree/payment_spec.rb
|
||||
- spec/models/spree/product_set_spec.rb
|
||||
- spec/models/spree/product_spec.rb
|
||||
- spec/models/spree/return_authorization_spec.rb
|
||||
- spec/models/spree/shipping_method_spec.rb
|
||||
- spec/models/spree/stock_item_spec.rb
|
||||
- spec/models/spree/taxon_spec.rb
|
||||
@@ -298,6 +302,7 @@ Layout/LineLength:
|
||||
- spec/serializers/api/order_serializer_spec.rb
|
||||
- spec/services/cart_service_spec.rb
|
||||
- spec/services/checkout/form_data_adapter_spec.rb
|
||||
- spec/services/checkout/post_checkout_actions_spec.rb
|
||||
- spec/services/embedded_page_service_spec.rb
|
||||
- spec/services/exchange_products_renderer_spec.rb
|
||||
- spec/services/order_cycle_distributed_products_spec.rb
|
||||
@@ -384,17 +389,22 @@ Metrics/AbcSize:
|
||||
- app/models/proxy_order.rb
|
||||
- app/models/spree/ability.rb
|
||||
- app/models/spree/address.rb
|
||||
- app/models/spree/line_item_decorator.rb
|
||||
- app/models/spree/line_item.rb
|
||||
- app/models/spree/order/checkout.rb
|
||||
- app/models/spree/order_decorator.rb
|
||||
- app/models/spree/order_contents.rb
|
||||
- app/models/spree/order_inventory.rb
|
||||
- app/models/spree/order.rb
|
||||
- app/models/spree/payment/processing.rb
|
||||
- app/models/spree/payment.rb
|
||||
- app/models/spree/preference.rb
|
||||
- app/models/spree/preferences/preferable_class_methods.rb
|
||||
- app/models/spree/preferences/preferable.rb
|
||||
- app/models/spree/product_decorator.rb
|
||||
- app/models/spree/return_authorization.rb
|
||||
- app/models/spree/shipment.rb
|
||||
- app/models/spree/taxon.rb
|
||||
- app/models/spree/tax_rate.rb
|
||||
- app/models/spree/zone.rb
|
||||
- app/serializers/api/admin/enterprise_serializer.rb
|
||||
- app/serializers/api/product_serializer.rb
|
||||
- app/serializers/api/variant_serializer.rb
|
||||
- app/services/cart_service.rb
|
||||
@@ -452,6 +462,7 @@ Metrics/AbcSize:
|
||||
- spec/services/order_checkout_restart_spec.rb
|
||||
- spec/support/i18n_translations_checker.rb
|
||||
- spec/support/performance_helper.rb
|
||||
- spec/support/request/web_helper.rb
|
||||
|
||||
Metrics/BlockLength:
|
||||
Max: 25
|
||||
@@ -516,7 +527,11 @@ Metrics/CyclomaticComplexity:
|
||||
- app/models/spree/order/checkout.rb
|
||||
- app/models/spree/payment_method.rb
|
||||
- app/models/spree/payment.rb
|
||||
- app/models/spree/preference.rb
|
||||
- app/models/spree/preferences/preferable.rb
|
||||
- app/models/spree/preferences/preferable_class_methods.rb
|
||||
- app/models/spree/product_decorator.rb
|
||||
- app/models/spree/return_authorization.rb
|
||||
- app/models/spree/zone.rb
|
||||
- app/models/variant_override_set.rb
|
||||
- app/services/cart_service.rb
|
||||
@@ -550,7 +565,10 @@ Metrics/PerceivedComplexity:
|
||||
- app/models/spree/order/checkout.rb
|
||||
- app/models/spree/payment_method.rb
|
||||
- app/models/spree/payment.rb
|
||||
- app/models/spree/preferences/preferable.rb
|
||||
- app/models/spree/preferences/preferable_class_methods.rb
|
||||
- app/models/spree/product_decorator.rb
|
||||
- app/models/spree/return_authorization.rb
|
||||
- app/models/spree/zone.rb
|
||||
- app/models/variant_override_set.rb
|
||||
- app/services/cart_service.rb
|
||||
@@ -576,7 +594,7 @@ Metrics/PerceivedComplexity:
|
||||
- app/models/spree/ability.rb
|
||||
- app/models/spree/address.rb
|
||||
- app/models/spree/order/checkout.rb
|
||||
- app/models/spree/order_decorator.rb
|
||||
- app/models/spree/order.rb
|
||||
- app/models/spree/product_decorator.rb
|
||||
- app/models/spree/zone.rb
|
||||
- engines/order_management/app/services/order_management/reports/bulk_coop/bulk_coop_report.rb
|
||||
@@ -594,61 +612,6 @@ Metrics/PerceivedComplexity:
|
||||
Metrics/MethodLength:
|
||||
Max: 10
|
||||
Exclude:
|
||||
- app/controllers/admin/enterprise_fees_controller.rb
|
||||
- app/controllers/admin/enterprises_controller.rb
|
||||
- app/controllers/spree/admin/taxons_controller.rb
|
||||
- app/controllers/spree/orders_controller.rb
|
||||
- app/helpers/checkout_helper.rb
|
||||
- app/helpers/order_cycles_helper.rb
|
||||
- app/helpers/spree/admin/base_helper.rb
|
||||
- app/helpers/spree/admin/navigation_helper.rb
|
||||
- app/models/enterprise.rb
|
||||
- app/models/enterprise_relationship.rb
|
||||
- app/models/spree/ability.rb
|
||||
- app/models/spree/address.rb
|
||||
- app/models/spree/order/checkout.rb
|
||||
- app/models/spree/payment_method.rb
|
||||
- app/models/spree/payment.rb
|
||||
- app/models/spree/product_decorator.rb
|
||||
- app/models/spree/zone.rb
|
||||
- app/models/variant_override_set.rb
|
||||
- app/services/cart_service.rb
|
||||
- engines/order_management/app/services/order_management/reports/bulk_coop/bulk_coop_report.rb
|
||||
- engines/order_management/app/services/order_management/stock/estimator.rb
|
||||
- lib/active_merchant/billing/gateways/stripe_payment_intents.rb
|
||||
- lib/discourse/single_sign_on.rb
|
||||
- lib/open_food_network/enterprise_issue_validator.rb
|
||||
- lib/spree/core/calculated_adjustments.rb
|
||||
- lib/spree/core/controller_helpers/order.rb
|
||||
- lib/spree/core/controller_helpers/respond_with.rb
|
||||
- lib/spree/core/controller_helpers/ssl.rb
|
||||
- lib/spree/localized_number.rb
|
||||
- spec/models/product_importer_spec.rb
|
||||
- app/controllers/admin/enterprises_controller.rb
|
||||
- app/controllers/api/variants_controller.rb
|
||||
- app/controllers/spree/admin/taxons_controller.rb
|
||||
- app/controllers/spree/orders_controller.rb
|
||||
- app/helpers/checkout_helper.rb
|
||||
- app/helpers/order_cycles_helper.rb
|
||||
- app/helpers/spree/admin/navigation_helper.rb
|
||||
- app/models/enterprise_relationship.rb
|
||||
- app/models/spree/ability.rb
|
||||
- app/models/spree/address.rb
|
||||
- app/models/spree/order/checkout.rb
|
||||
- app/models/spree/order_decorator.rb
|
||||
- app/models/spree/product_decorator.rb
|
||||
- app/models/spree/zone.rb
|
||||
- engines/order_management/app/services/order_management/reports/bulk_coop/bulk_coop_report.rb
|
||||
- engines/order_management/app/services/order_management/stock/estimator.rb
|
||||
- lib/active_merchant/billing/gateways/stripe_payment_intents.rb
|
||||
- lib/discourse/single_sign_on.rb
|
||||
- lib/open_food_network/enterprise_issue_validator.rb
|
||||
- lib/spree/core/calculated_adjustments.rb
|
||||
- lib/spree/core/controller_helpers/order.rb
|
||||
- lib/spree/core/controller_helpers/respond_with.rb
|
||||
- lib/spree/core/controller_helpers/ssl.rb
|
||||
- lib/spree/localized_number.rb
|
||||
- spec/models/product_importer_spec.rb
|
||||
- app/controllers/admin/contents_controller.rb
|
||||
- app/controllers/admin/customers_controller.rb
|
||||
- app/controllers/admin/enterprise_fees_controller.rb
|
||||
@@ -698,10 +661,17 @@ Metrics/MethodLength:
|
||||
- app/models/spree/address.rb
|
||||
- app/models/spree/credit_card.rb
|
||||
- app/models/spree/order/checkout.rb
|
||||
- app/models/spree/order_decorator.rb
|
||||
- app/models/spree/order_contents.rb
|
||||
- app/models/spree/order_inventory.rb
|
||||
- app/models/spree/order.rb
|
||||
- app/models/spree/payment_method.rb
|
||||
- app/models/spree/payment/processing.rb
|
||||
- app/models/spree/preference.rb
|
||||
- app/models/spree/preferences/preferable_class_methods.rb
|
||||
- app/models/spree/preferences/preferable.rb
|
||||
- app/models/spree/preferences/store.rb
|
||||
- app/models/spree/product_decorator.rb
|
||||
- app/models/spree/return_authorization.rb
|
||||
- app/models/spree/shipment.rb
|
||||
- app/models/spree/taxon.rb
|
||||
- app/models/spree/tax_rate.rb
|
||||
@@ -782,6 +752,8 @@ Metrics/ClassLength:
|
||||
- app/models/spree/ability.rb
|
||||
- app/models/spree/address.rb
|
||||
- app/models/spree/credit_card.rb
|
||||
- app/models/spree/line_item.rb
|
||||
- app/models/spree/order.rb
|
||||
- app/models/spree/payment.rb
|
||||
- app/models/spree/shipment.rb
|
||||
- app/models/spree/user.rb
|
||||
@@ -811,40 +783,18 @@ Metrics/ModuleLength:
|
||||
- app/helpers/spree/admin/navigation_helper.rb
|
||||
- app/models/spree/order/checkout.rb
|
||||
- app/models/spree/payment/processing.rb
|
||||
- engines/order_management/spec/services/order_management/order/updater_spec.rb
|
||||
- engines/order_management/spec/services/order_management/stock/package_spec.rb
|
||||
- engines/order_management/spec/services/order_management/subscriptions/estimator_spec.rb
|
||||
- engines/order_management/spec/services/order_management/subscriptions/form_spec.rb
|
||||
- engines/order_management/spec/services/order_management/subscriptions/proxy_order_syncer_spec.rb
|
||||
- engines/order_management/spec/services/order_management/subscriptions/summarizer_spec.rb
|
||||
- engines/order_management/spec/services/order_management/subscriptions/validator_spec.rb
|
||||
- engines/order_management/spec/services/order_management/subscriptions/variants_list_spec.rb
|
||||
- lib/open_food_network/column_preference_defaults.rb
|
||||
- spec/controllers/admin/order_cycles_controller_spec.rb
|
||||
- spec/controllers/api/order_cycles_controller_spec.rb
|
||||
- spec/controllers/api/orders_controller_spec.rb
|
||||
- spec/controllers/spree/admin/payment_methods_controller_spec.rb
|
||||
- spec/lib/open_food_network/address_finder_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/order_cycle_form_applicator_spec.rb
|
||||
- spec/lib/open_food_network/order_cycle_permissions_spec.rb
|
||||
- spec/lib/open_food_network/order_grouper_spec.rb
|
||||
- spec/lib/open_food_network/packing_report_spec.rb
|
||||
- spec/lib/open_food_network/permissions_spec.rb
|
||||
- spec/lib/open_food_network/products_and_inventory_report_spec.rb
|
||||
- spec/lib/open_food_network/scope_variant_to_hub_spec.rb
|
||||
- spec/lib/open_food_network/tag_rule_applicator_spec.rb
|
||||
- spec/lib/open_food_network/user_balance_calculator_spec.rb
|
||||
- spec/lib/open_food_network/users_and_enterprises_report_spec.rb
|
||||
- spec/models/spree/adjustment_spec.rb
|
||||
- spec/models/spree/credit_card_spec.rb
|
||||
- spec/models/spree/line_item_spec.rb
|
||||
- spec/models/spree/product_spec.rb
|
||||
- spec/models/spree/shipping_method_spec.rb
|
||||
- spec/models/spree/variant_spec.rb
|
||||
- spec/services/permissions/order_spec.rb
|
||||
- spec/services/variant_units/option_value_namer_spec.rb
|
||||
|
||||
Metrics/ParameterLists:
|
||||
Max: 5
|
||||
@@ -853,3 +803,9 @@ Metrics/ParameterLists:
|
||||
- app/models/product_import/entry_processor.rb
|
||||
- lib/open_food_network/xero_invoices_report.rb
|
||||
- spec/features/admin/reports_spec.rb
|
||||
|
||||
Lint/UselessAssignment:
|
||||
Exclude:
|
||||
- 'spec/**/*'
|
||||
- 'app/models/spree/taxon.rb'
|
||||
- 'lib/spree/core/controller_helpers/common.rb'
|
||||
|
||||
7
.rubocop_specs.yml
Normal file
7
.rubocop_specs.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
inherit_from:
|
||||
- .rubocop.yml
|
||||
|
||||
# This rubocop config file is only used for specs
|
||||
# Here we allow specs to be 300 lines long
|
||||
Metrics/ModuleLength:
|
||||
Max: 300
|
||||
@@ -1,144 +1,11 @@
|
||||
# This configuration was generated by
|
||||
# `rubocop --auto-gen-config --exclude-limit 1400`
|
||||
# on 2020-10-14 09:49:36 +0100 using RuboCop version 0.81.0.
|
||||
# on 2020-10-30 17:18:53 +0000 using RuboCop version 0.81.0.
|
||||
# The point is for the user to remove these configuration records
|
||||
# one by one as the offenses are removed from the code base.
|
||||
# Note that changes in the inspected code, or installation of new
|
||||
# versions of RuboCop, may require this file to be generated again.
|
||||
|
||||
# Offense count: 3
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, IndentationWidth.
|
||||
# SupportedStyles: with_first_argument, with_fixed_indentation
|
||||
Layout/ArgumentAlignment:
|
||||
Exclude:
|
||||
- 'spec/models/spree/address_spec.rb'
|
||||
- 'spec/models/spree/order/checkout_spec.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyleAlignWith.
|
||||
# SupportedStylesAlignWith: either, start_of_block, start_of_line
|
||||
Layout/BlockAlignment:
|
||||
Exclude:
|
||||
- 'spec/models/spree/order/checkout_spec.rb'
|
||||
|
||||
# Offense count: 3
|
||||
# Cop supports --auto-correct.
|
||||
Layout/EmptyLines:
|
||||
Exclude:
|
||||
- 'spec/features/admin/variants_spec.rb'
|
||||
- 'spec/models/spree/payment_spec.rb'
|
||||
|
||||
# Offense count: 4
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle.
|
||||
# SupportedStyles: empty_lines, no_empty_lines
|
||||
Layout/EmptyLinesAroundBlockBody:
|
||||
Exclude:
|
||||
- 'spec/models/spree/payment_spec.rb'
|
||||
- 'spec/models/spree/zone_spec.rb'
|
||||
|
||||
# Offense count: 3
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment.
|
||||
Layout/ExtraSpacing:
|
||||
Exclude:
|
||||
- 'spec/models/spree/payment_spec.rb'
|
||||
- 'spec/requests/api/orders_spec.rb'
|
||||
|
||||
# Offense count: 2
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, IndentationWidth.
|
||||
# SupportedStyles: special_inside_parentheses, consistent, align_brackets
|
||||
Layout/FirstArrayElementIndentation:
|
||||
Exclude:
|
||||
- 'spec/views/spree/admin/payment_methods/index.html.haml_spec.rb'
|
||||
|
||||
# Offense count: 3
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, IndentationWidth.
|
||||
# SupportedStyles: special_inside_parentheses, consistent, align_braces
|
||||
Layout/FirstHashElementIndentation:
|
||||
Exclude:
|
||||
- 'spec/models/spree/payment_spec.rb'
|
||||
- 'spec/swagger_helper.rb'
|
||||
|
||||
# Offense count: 8
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle.
|
||||
# SupportedHashRocketStyles: key, separator, table
|
||||
# SupportedColonStyles: key, separator, table
|
||||
# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
|
||||
Layout/HashAlignment:
|
||||
Exclude:
|
||||
- 'spec/lib/open_food_network/packing_report_spec.rb'
|
||||
- 'spec/models/spree/payment_spec.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle.
|
||||
# SupportedStyles: normal, indented_internal_methods
|
||||
Layout/IndentationConsistency:
|
||||
Exclude:
|
||||
- 'spec/models/spree/order/checkout_spec.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle.
|
||||
# SupportedStyles: symmetrical, new_line, same_line
|
||||
Layout/MultilineHashBraceLayout:
|
||||
Exclude:
|
||||
- 'spec/models/spree/payment_spec.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator.
|
||||
# SupportedStylesForExponentOperator: space, no_space
|
||||
Layout/SpaceAroundOperators:
|
||||
Exclude:
|
||||
- 'spec/models/spree/payment_spec.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
|
||||
# SupportedStyles: space, no_space
|
||||
# SupportedStylesForEmptyBraces: space, no_space
|
||||
Layout/SpaceInsideBlockBraces:
|
||||
Exclude:
|
||||
- 'spec/models/spree/payment_spec.rb'
|
||||
|
||||
# Offense count: 11
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
|
||||
# SupportedStyles: space, no_space, compact
|
||||
# SupportedStylesForEmptyBraces: space, no_space
|
||||
Layout/SpaceInsideHashLiteralBraces:
|
||||
Exclude:
|
||||
- 'spec/models/spree/payment_spec.rb'
|
||||
- 'spec/requests/api/orders_spec.rb'
|
||||
- 'spec/services/checkout/form_data_adapter_spec.rb'
|
||||
- 'spec/services/user_locale_setter_spec.rb'
|
||||
|
||||
# Offense count: 3
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle.
|
||||
# SupportedStyles: final_newline, final_blank_line
|
||||
Layout/TrailingEmptyLines:
|
||||
Exclude:
|
||||
- 'spec/factories.rb'
|
||||
- 'spec/factories/address_factory.rb'
|
||||
- 'spec/support/request/stripe_helper.rb'
|
||||
|
||||
# Offense count: 6
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: AllowInHeredoc.
|
||||
Layout/TrailingWhitespace:
|
||||
Exclude:
|
||||
- 'spec/features/consumer/shopping/shopping_spec.rb'
|
||||
- 'spec/lib/open_food_network/orders_and_fulfillments_report/customer_totals_report_spec.rb'
|
||||
- 'spec/requests/api/orders_spec.rb'
|
||||
|
||||
# Offense count: 2
|
||||
Lint/DuplicateMethods:
|
||||
Exclude:
|
||||
@@ -152,20 +19,6 @@ Lint/IneffectiveAccessModifier:
|
||||
- 'app/services/mail_configuration.rb'
|
||||
- 'lib/open_food_network/feature_toggle.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
|
||||
Lint/UnusedBlockArgument:
|
||||
Exclude:
|
||||
- 'spec/factories/stock_location_factory.rb'
|
||||
|
||||
# Offense count: 4
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods.
|
||||
Lint/UnusedMethodArgument:
|
||||
Exclude:
|
||||
- 'spec/views/spree/admin/payment_methods/index.html.haml_spec.rb'
|
||||
|
||||
# Offense count: 3
|
||||
# Configuration parameters: ContextCreatingMethods, MethodCreatingMethods.
|
||||
Lint/UselessAccessModifier:
|
||||
@@ -174,19 +27,20 @@ Lint/UselessAccessModifier:
|
||||
- 'app/services/mail_configuration.rb'
|
||||
- 'lib/open_food_network/feature_toggle.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Offense count: 2
|
||||
Lint/UselessAssignment:
|
||||
Exclude:
|
||||
- 'spec/**/*'
|
||||
- 'lib/spree/core/controller_helpers/common.rb'
|
||||
- 'app/models/spree/taxon.rb'
|
||||
- 'lib/spree/core/controller_helpers/common.rb'
|
||||
|
||||
# Offense count: 9
|
||||
# Offense count: 10
|
||||
Naming/AccessorMethodName:
|
||||
Exclude:
|
||||
- 'app/controllers/spree/admin/taxonomies_controller.rb'
|
||||
- 'app/models/spree/adjustment.rb'
|
||||
- 'app/models/spree/order_decorator.rb'
|
||||
- 'app/models/spree/order.rb'
|
||||
- 'app/services/checkout/post_checkout_actions.rb'
|
||||
- 'lib/spree/core/controller_helpers/common.rb'
|
||||
- 'spec/support/request/shop_workflow.rb'
|
||||
- 'spec/support/request/web_helper.rb'
|
||||
@@ -206,7 +60,7 @@ Naming/MemoizedInstanceVariableName:
|
||||
- 'app/mailers/producer_mailer.rb'
|
||||
- 'lib/open_food_network/address_finder.rb'
|
||||
|
||||
# Offense count: 20
|
||||
# Offense count: 24
|
||||
# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros.
|
||||
# NamePrefix: is_, has_, have_
|
||||
# ForbiddenPrefixes: is_, has_, have_
|
||||
@@ -220,10 +74,11 @@ Naming/PredicateName:
|
||||
- 'app/models/order_cycle.rb'
|
||||
- 'app/models/spree/adjustment.rb'
|
||||
- 'app/models/spree/credit_card.rb'
|
||||
- 'app/models/spree/line_item_decorator.rb'
|
||||
- 'app/models/spree/order_decorator.rb'
|
||||
- 'app/models/spree/line_item.rb'
|
||||
- 'app/models/spree/order.rb'
|
||||
- 'app/models/spree/payment_method.rb'
|
||||
- 'app/models/spree/preferences/file_configuration.rb'
|
||||
- 'app/models/spree/preferences/preferable.rb'
|
||||
- 'app/models/spree/shipping_method.rb'
|
||||
- 'app/models/spree/user.rb'
|
||||
- 'lib/open_food_network/customers_report.rb'
|
||||
@@ -262,21 +117,14 @@ Rails/Date:
|
||||
- 'app/models/order_cycle.rb'
|
||||
- 'app/models/spree/credit_card.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Offense count: 2
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforceForPrefixed.
|
||||
Rails/Delegate:
|
||||
Exclude:
|
||||
- 'app/models/spree/line_item.rb'
|
||||
- 'engines/order_management/app/services/order_management/reports/bulk_coop/renderers/html_renderer.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: Whitelist.
|
||||
# Whitelist: find_by_sql
|
||||
Rails/DynamicFindBy:
|
||||
Exclude:
|
||||
- 'spec/factories/state_factory.rb'
|
||||
|
||||
# Offense count: 16
|
||||
# Configuration parameters: EnforcedStyle.
|
||||
# SupportedStyles: slashes, arguments
|
||||
@@ -307,13 +155,12 @@ Rails/FindBy:
|
||||
- 'app/models/product_import/spreadsheet_data.rb'
|
||||
- 'app/models/spree/user.rb'
|
||||
|
||||
# Offense count: 2
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: Include.
|
||||
# Include: app/models/**/*.rb
|
||||
Rails/FindEach:
|
||||
Exclude:
|
||||
- 'app/models/spree/order_decorator.rb'
|
||||
- 'app/models/spree/shipment.rb'
|
||||
|
||||
# Offense count: 9
|
||||
@@ -324,13 +171,13 @@ Rails/HasAndBelongsToMany:
|
||||
- 'app/models/concerns/payment_method_distributors.rb'
|
||||
- 'app/models/enterprise.rb'
|
||||
- 'app/models/enterprise_group.rb'
|
||||
- 'app/models/spree/line_item_decorator.rb'
|
||||
- 'app/models/spree/line_item.rb'
|
||||
- 'app/models/spree/role.rb'
|
||||
- 'app/models/spree/shipping_method.rb'
|
||||
- 'app/models/spree/user.rb'
|
||||
- 'app/models/spree/zone.rb'
|
||||
|
||||
# Offense count: 35
|
||||
# Offense count: 38
|
||||
# Configuration parameters: Include.
|
||||
# Include: app/models/**/*.rb
|
||||
Rails/HasManyOrHasOneDependent:
|
||||
@@ -341,9 +188,10 @@ Rails/HasManyOrHasOneDependent:
|
||||
- 'app/models/spree/address.rb'
|
||||
- 'app/models/spree/adjustment.rb'
|
||||
- 'app/models/spree/credit_card.rb'
|
||||
- 'app/models/spree/order_decorator.rb'
|
||||
- 'app/models/spree/order.rb'
|
||||
- 'app/models/spree/payment_method.rb'
|
||||
- 'app/models/spree/property.rb'
|
||||
- 'app/models/spree/return_authorization.rb'
|
||||
- 'app/models/spree/shipment.rb'
|
||||
- 'app/models/spree/shipping_category.rb'
|
||||
- 'app/models/spree/shipping_method.rb'
|
||||
@@ -392,7 +240,7 @@ Rails/LexicallyScopedActionFilter:
|
||||
- 'app/controllers/spree/users_controller.rb'
|
||||
- 'app/controllers/user_passwords_controller.rb'
|
||||
|
||||
# Offense count: 13
|
||||
# Offense count: 14
|
||||
Rails/OutputSafety:
|
||||
Exclude:
|
||||
- 'app/controllers/spree/admin/reports_controller.rb'
|
||||
@@ -415,15 +263,16 @@ Rails/RakeEnvironment:
|
||||
- 'lib/capistrano/tasks/**/*.rake'
|
||||
- 'lib/tasks/specs.rake'
|
||||
|
||||
# Offense count: 9
|
||||
# Offense count: 11
|
||||
Rails/ReflectionClassName:
|
||||
Exclude:
|
||||
- 'app/models/customer.rb'
|
||||
- 'app/models/distributor_shipping_method.rb'
|
||||
- 'app/models/enterprise_role.rb'
|
||||
- 'app/models/spree/order.rb'
|
||||
- 'app/models/subscription.rb'
|
||||
|
||||
# Offense count: 243
|
||||
# Offense count: 247
|
||||
# Configuration parameters: Blacklist, Whitelist.
|
||||
# Blacklist: decrement!, decrement_counter, increment!, increment_counter, toggle!, touch, update_all, update_attribute, update_column, update_columns, update_counters
|
||||
Rails/SkipsModelValidations:
|
||||
@@ -442,7 +291,8 @@ Rails/SkipsModelValidations:
|
||||
- 'app/models/spree/address.rb'
|
||||
- 'app/models/spree/adjustment.rb'
|
||||
- 'app/models/spree/credit_card.rb'
|
||||
- 'app/models/spree/order_decorator.rb'
|
||||
- 'app/models/spree/inventory_unit.rb'
|
||||
- 'app/models/spree/order.rb'
|
||||
- 'app/models/spree/payment.rb'
|
||||
- 'app/models/spree/shipment.rb'
|
||||
- 'app/models/spree/shipping_method.rb'
|
||||
@@ -480,7 +330,6 @@ Rails/SkipsModelValidations:
|
||||
- 'spec/features/admin/order_cycles/complex_editing_spec.rb'
|
||||
- 'spec/features/admin/order_cycles/simple_spec.rb'
|
||||
- 'spec/features/admin/order_spec.rb'
|
||||
- 'spec/features/admin/payments_spec.rb'
|
||||
- 'spec/features/admin/reports_spec.rb'
|
||||
- 'spec/features/consumer/caching/shops_caching_spec.rb'
|
||||
- 'spec/features/consumer/shopping/checkout_spec.rb'
|
||||
@@ -501,6 +350,7 @@ Rails/SkipsModelValidations:
|
||||
- 'spec/models/spree/adjustment_spec.rb'
|
||||
- 'spec/models/spree/asset_spec.rb'
|
||||
- 'spec/models/spree/line_item_spec.rb'
|
||||
- 'spec/models/spree/order_inventory_spec.rb'
|
||||
- 'spec/models/spree/order_spec.rb'
|
||||
- 'spec/models/spree/tax_category_spec.rb'
|
||||
- 'spec/models/spree/variant_spec.rb'
|
||||
@@ -533,7 +383,7 @@ Rails/UniqueValidationWithoutIndex:
|
||||
# Environments: development, test, production
|
||||
Rails/UnknownEnv:
|
||||
Exclude:
|
||||
- 'app/models/spree/app_configuration_decorator.rb'
|
||||
- 'app/models/spree/app_configuration.rb'
|
||||
- 'lib/spree/core/controller_helpers/ssl.rb'
|
||||
|
||||
# Offense count: 2
|
||||
@@ -542,7 +392,7 @@ Style/CaseEquality:
|
||||
- 'app/helpers/angular_form_helper.rb'
|
||||
- 'spec/models/spree/payment_spec.rb'
|
||||
|
||||
# Offense count: 64
|
||||
# Offense count: 29
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: AutoCorrect, EnforcedStyle.
|
||||
# SupportedStyles: nested, compact
|
||||
@@ -557,40 +407,6 @@ Style/ClassAndModuleChildren:
|
||||
- 'app/models/tag_rule/filter_payment_methods.rb'
|
||||
- 'app/models/tag_rule/filter_shipping_methods.rb'
|
||||
- 'app/serializers/api/address_serializer.rb'
|
||||
- 'app/serializers/api/admin/basic_enterprise_fee_serializer.rb'
|
||||
- 'app/serializers/api/admin/basic_enterprise_serializer.rb'
|
||||
- 'app/serializers/api/admin/basic_order_cycle_serializer.rb'
|
||||
- 'app/serializers/api/admin/calculator/flat_percent_item_total_serializer.rb'
|
||||
- 'app/serializers/api/admin/calculator_serializer.rb'
|
||||
- 'app/serializers/api/admin/column_preference_serializer.rb'
|
||||
- 'app/serializers/api/admin/customer_serializer.rb'
|
||||
- 'app/serializers/api/admin/enterprise_fee_serializer.rb'
|
||||
- 'app/serializers/api/admin/enterprise_relationship_permission_serializer.rb'
|
||||
- 'app/serializers/api/admin/enterprise_relationship_serializer.rb'
|
||||
- 'app/serializers/api/admin/enterprise_role_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/for_order_cycle/supplied_product_serializer.rb'
|
||||
- 'app/serializers/api/admin/id_name_serializer.rb'
|
||||
- 'app/serializers/api/admin/id_serializer.rb'
|
||||
- 'app/serializers/api/admin/index_enterprise_serializer.rb'
|
||||
- 'app/serializers/api/admin/inventory_item_serializer.rb'
|
||||
- 'app/serializers/api/admin/line_item_serializer.rb'
|
||||
- 'app/serializers/api/admin/order_cycle_serializer.rb'
|
||||
- 'app/serializers/api/admin/order_serializer.rb'
|
||||
- 'app/serializers/api/admin/payment_method/base_serializer.rb'
|
||||
- 'app/serializers/api/admin/payment_method/stripe_serializer.rb'
|
||||
- 'app/serializers/api/admin/product_serializer.rb'
|
||||
- 'app/serializers/api/admin/shipping_method_serializer.rb'
|
||||
- 'app/serializers/api/admin/tag_rule_serializer.rb'
|
||||
- 'app/serializers/api/admin/tax_category_serializer.rb'
|
||||
- 'app/serializers/api/admin/taxon_serializer.rb'
|
||||
- 'app/serializers/api/admin/units_product_serializer.rb'
|
||||
- 'app/serializers/api/admin/units_variant_serializer.rb'
|
||||
- 'app/serializers/api/admin/user_serializer.rb'
|
||||
- 'app/serializers/api/admin/variant_override_serializer.rb'
|
||||
- 'app/serializers/api/admin/variant_serializer.rb'
|
||||
- 'app/serializers/api/country_serializer.rb'
|
||||
- 'app/serializers/api/currency_config_serializer.rb'
|
||||
- 'app/serializers/api/current_order_serializer.rb'
|
||||
@@ -624,7 +440,7 @@ Style/FormatStringToken:
|
||||
- 'lib/open_food_network/sales_tax_report.rb'
|
||||
- 'spec/features/admin/bulk_order_management_spec.rb'
|
||||
|
||||
# Offense count: 818
|
||||
# Offense count: 765
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle.
|
||||
# SupportedStyles: always, always_true, never
|
||||
@@ -816,13 +632,10 @@ Style/FrozenStringLiteralComment:
|
||||
- 'app/models/product_import/unit_converter.rb'
|
||||
- 'app/models/proxy_order.rb'
|
||||
- 'app/models/schedule.rb'
|
||||
- 'app/models/spree/app_configuration_decorator.rb'
|
||||
- 'app/models/spree/gateway/migs.rb'
|
||||
- 'app/models/spree/gateway/pin.rb'
|
||||
- 'app/models/spree/gateway/stripe_connect.rb'
|
||||
- 'app/models/spree/line_item_decorator.rb'
|
||||
- 'app/models/spree/option_type_decorator.rb'
|
||||
- 'app/models/spree/order_decorator.rb'
|
||||
- 'app/models/spree/preferences/file_configuration.rb'
|
||||
- 'app/models/spree/price_decorator.rb'
|
||||
- 'app/models/spree/product_decorator.rb'
|
||||
@@ -845,48 +658,6 @@ Style/FrozenStringLiteralComment:
|
||||
- 'app/models/variant_override_set.rb'
|
||||
- 'app/serializers/api/address_serializer.rb'
|
||||
- 'app/serializers/api/adjustment_serializer.rb'
|
||||
- 'app/serializers/api/admin/basic_enterprise_fee_serializer.rb'
|
||||
- 'app/serializers/api/admin/basic_enterprise_serializer.rb'
|
||||
- 'app/serializers/api/admin/basic_order_cycle_serializer.rb'
|
||||
- 'app/serializers/api/admin/calculator/flat_percent_item_total_serializer.rb'
|
||||
- 'app/serializers/api/admin/calculator_serializer.rb'
|
||||
- 'app/serializers/api/admin/column_preference_serializer.rb'
|
||||
- 'app/serializers/api/admin/customer_serializer.rb'
|
||||
- 'app/serializers/api/admin/enterprise_fee_serializer.rb'
|
||||
- 'app/serializers/api/admin/enterprise_relationship_permission_serializer.rb'
|
||||
- 'app/serializers/api/admin/enterprise_relationship_serializer.rb'
|
||||
- 'app/serializers/api/admin/enterprise_role_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/for_order_cycle/supplied_product_serializer.rb'
|
||||
- 'app/serializers/api/admin/id_email_serializer.rb'
|
||||
- 'app/serializers/api/admin/id_name_serializer.rb'
|
||||
- 'app/serializers/api/admin/id_serializer.rb'
|
||||
- 'app/serializers/api/admin/index_enterprise_serializer.rb'
|
||||
- 'app/serializers/api/admin/index_order_cycle_serializer.rb'
|
||||
- 'app/serializers/api/admin/inventory_item_serializer.rb'
|
||||
- 'app/serializers/api/admin/line_item_serializer.rb'
|
||||
- 'app/serializers/api/admin/order_cycle_serializer.rb'
|
||||
- 'app/serializers/api/admin/order_serializer.rb'
|
||||
- 'app/serializers/api/admin/payment_method/base_serializer.rb'
|
||||
- 'app/serializers/api/admin/payment_method/stripe_serializer.rb'
|
||||
- 'app/serializers/api/admin/payment_method_serializer.rb'
|
||||
- 'app/serializers/api/admin/product_serializer.rb'
|
||||
- 'app/serializers/api/admin/proxy_order_serializer.rb'
|
||||
- 'app/serializers/api/admin/schedule_serializer.rb'
|
||||
- 'app/serializers/api/admin/shipping_method_serializer.rb'
|
||||
- 'app/serializers/api/admin/subscription_customer_serializer.rb'
|
||||
- 'app/serializers/api/admin/subscription_line_item_serializer.rb'
|
||||
- 'app/serializers/api/admin/subscription_serializer.rb'
|
||||
- 'app/serializers/api/admin/tag_rule_serializer.rb'
|
||||
- 'app/serializers/api/admin/tax_category_serializer.rb'
|
||||
- 'app/serializers/api/admin/taxon_serializer.rb'
|
||||
- 'app/serializers/api/admin/units_product_serializer.rb'
|
||||
- 'app/serializers/api/admin/units_variant_serializer.rb'
|
||||
- 'app/serializers/api/admin/user_serializer.rb'
|
||||
- 'app/serializers/api/admin/variant_override_serializer.rb'
|
||||
- 'app/serializers/api/admin/variant_serializer.rb'
|
||||
- 'app/serializers/api/cached_enterprise_serializer.rb'
|
||||
- 'app/serializers/api/country_serializer.rb'
|
||||
- 'app/serializers/api/credit_card_serializer.rb'
|
||||
@@ -1053,7 +824,6 @@ Style/FrozenStringLiteralComment:
|
||||
- 'lib/spree/authentication_helpers.rb'
|
||||
- 'lib/spree/localized_number.rb'
|
||||
- 'lib/spree/money_decorator.rb'
|
||||
- 'lib/spree/product_filters.rb'
|
||||
- 'lib/stripe/account_connector.rb'
|
||||
- 'lib/stripe/profile_storer.rb'
|
||||
- 'lib/stripe/webhook_handler.rb'
|
||||
@@ -1121,6 +891,7 @@ Style/FrozenStringLiteralComment:
|
||||
- 'spec/controllers/shops_controller_spec.rb'
|
||||
- 'spec/controllers/spree/admin/adjustments_controller_spec.rb'
|
||||
- 'spec/controllers/spree/admin/base_controller_spec.rb'
|
||||
- 'spec/controllers/spree/admin/general_settings_controller_spec.rb'
|
||||
- 'spec/controllers/spree/admin/invoices_controller_spec.rb'
|
||||
- 'spec/controllers/spree/admin/mail_methods_controller_spec.rb'
|
||||
- 'spec/controllers/spree/admin/orders/customer_details_controller_spec.rb'
|
||||
@@ -1274,7 +1045,6 @@ Style/FrozenStringLiteralComment:
|
||||
- 'spec/lib/open_food_network/users_and_enterprises_report_spec.rb'
|
||||
- 'spec/lib/open_food_network/xero_invoices_report_spec.rb'
|
||||
- 'spec/lib/spree/localized_number_spec.rb'
|
||||
- 'spec/lib/spree/product_filters_spec.rb'
|
||||
- 'spec/lib/stripe/account_connector_spec.rb'
|
||||
- 'spec/lib/stripe/webhook_handler_spec.rb'
|
||||
- 'spec/lib/tasks/enterprises_rake_spec.rb'
|
||||
@@ -1318,7 +1088,6 @@ Style/FrozenStringLiteralComment:
|
||||
- 'spec/models/spree/classification_spec.rb'
|
||||
- 'spec/models/spree/credit_card_spec.rb'
|
||||
- 'spec/models/spree/gateway/stripe_connect_spec.rb'
|
||||
- 'spec/models/spree/image_spec.rb'
|
||||
- 'spec/models/spree/line_item_spec.rb'
|
||||
- 'spec/models/spree/order/checkout_spec.rb'
|
||||
- 'spec/models/spree/order_spec.rb'
|
||||
@@ -1425,7 +1194,6 @@ Style/FrozenStringLiteralComment:
|
||||
- 'spec/support/products_helper.rb'
|
||||
- 'spec/support/request/admin_helper.rb'
|
||||
- 'spec/support/request/authentication_helper.rb'
|
||||
- 'spec/support/request/checkout_helper.rb'
|
||||
- 'spec/support/request/cookie_helper.rb'
|
||||
- 'spec/support/request/distribution_helper.rb'
|
||||
- 'spec/support/request/menu_helper.rb'
|
||||
@@ -1444,7 +1212,7 @@ Style/FrozenStringLiteralComment:
|
||||
- 'spec/views/spree/admin/payment_methods/index.html.haml_spec.rb'
|
||||
- 'spec/views/spree/admin/shared/_order_links.html.haml_spec.rb'
|
||||
|
||||
# Offense count: 48
|
||||
# Offense count: 44
|
||||
# Configuration parameters: MinBodyLength.
|
||||
Style/GuardClause:
|
||||
Exclude:
|
||||
@@ -1460,7 +1228,7 @@ Style/GuardClause:
|
||||
- 'app/models/enterprise.rb'
|
||||
- 'app/models/enterprise_group.rb'
|
||||
- 'app/models/producer_property.rb'
|
||||
- 'app/models/spree/order_decorator.rb'
|
||||
- 'app/models/spree/preferences/preferable_class_methods.rb'
|
||||
- 'app/models/spree/price_decorator.rb'
|
||||
- 'app/models/spree/product_decorator.rb'
|
||||
- 'app/services/order_syncer.rb'
|
||||
@@ -1469,25 +1237,15 @@ Style/GuardClause:
|
||||
- 'lib/open_food_network/order_cycle_form_applicator.rb'
|
||||
- 'lib/open_food_network/rack_request_blocker.rb'
|
||||
- 'spec/support/delayed_job_helper.rb'
|
||||
- 'spec/support/request/checkout_helper.rb'
|
||||
- 'spec/support/request/distribution_helper.rb'
|
||||
- 'spec/support/request/shop_workflow.rb'
|
||||
|
||||
# Offense count: 66
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
|
||||
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
|
||||
Style/HashSyntax:
|
||||
Exclude:
|
||||
- 'spec/factories/stock_location_factory.rb'
|
||||
- 'spec/models/spree/credit_card_spec.rb'
|
||||
- 'spec/models/spree/payment_spec.rb'
|
||||
|
||||
# Offense count: 2
|
||||
# Offense count: 3
|
||||
Style/MissingRespondToMissing:
|
||||
Exclude:
|
||||
- 'app/helpers/application_helper.rb'
|
||||
- 'app/models/spree/gateway.rb'
|
||||
- 'app/models/spree/preferences/configuration.rb'
|
||||
|
||||
# Offense count: 2
|
||||
Style/MixinUsage:
|
||||
@@ -1495,7 +1253,7 @@ Style/MixinUsage:
|
||||
- 'lib/open_food_network/orders_and_fulfillments_report.rb'
|
||||
- 'spec/lib/open_food_network/packing_report_spec.rb'
|
||||
|
||||
# Offense count: 36
|
||||
# Offense count: 43
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods.
|
||||
# SupportedStyles: predicate, comparison
|
||||
@@ -1509,8 +1267,11 @@ Style/NumericPredicate:
|
||||
- 'app/models/product_import/product_importer.rb'
|
||||
- 'app/models/product_import/spreadsheet_entry.rb'
|
||||
- 'app/models/spree/gateway/stripe_connect.rb'
|
||||
- 'app/models/spree/line_item_decorator.rb'
|
||||
- 'app/models/spree/order_decorator.rb'
|
||||
- 'app/models/spree/line_item.rb'
|
||||
- 'app/models/spree/order.rb'
|
||||
- 'app/models/spree/order_contents.rb'
|
||||
- 'app/models/spree/order_inventory.rb'
|
||||
- 'app/models/spree/preferences/preferable.rb'
|
||||
- 'app/models/spree/user.rb'
|
||||
- 'app/models/variant_override.rb'
|
||||
- 'app/services/cart_service.rb'
|
||||
@@ -1523,37 +1284,7 @@ Style/NumericPredicate:
|
||||
- 'lib/spree/money_decorator.rb'
|
||||
- 'lib/tasks/sample_data.rake'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle.
|
||||
# SupportedStyles: compact, exploded
|
||||
Style/RaiseArgs:
|
||||
Exclude:
|
||||
- 'spec/controllers/checkout_controller_spec.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
Style/RandomWithOffset:
|
||||
Exclude:
|
||||
- 'spec/factories.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, AllowInnerSlashes.
|
||||
# SupportedStyles: slashes, percent_r, mixed
|
||||
Style/RegexpLiteral:
|
||||
Exclude:
|
||||
- 'lib/spree/core/controller_helpers/auth.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle.
|
||||
# SupportedStyles: implicit, explicit
|
||||
Style/RescueStandardError:
|
||||
Exclude:
|
||||
- 'lib/spree/core/delegate_belongs_to.rb'
|
||||
|
||||
# Offense count: 231
|
||||
# Offense count: 241
|
||||
Style/Send:
|
||||
Exclude:
|
||||
- 'spec/controllers/admin/subscriptions_controller_spec.rb'
|
||||
@@ -1578,8 +1309,10 @@ Style/Send:
|
||||
- 'spec/models/enterprise_spec.rb'
|
||||
- 'spec/models/exchange_spec.rb'
|
||||
- 'spec/models/spree/gateway/stripe_connect_spec.rb'
|
||||
- 'spec/models/spree/order_inventory_spec.rb'
|
||||
- 'spec/models/spree/order_spec.rb'
|
||||
- 'spec/models/spree/payment_spec.rb'
|
||||
- 'spec/models/spree/return_authorization_spec.rb'
|
||||
- 'spec/models/spree/tax_rate_spec.rb'
|
||||
- 'spec/models/tag_rule/discount_order_spec.rb'
|
||||
- 'spec/models/tag_rule/filter_order_cycles_spec.rb'
|
||||
@@ -1597,3 +1330,11 @@ Style/Send:
|
||||
Style/StructInheritance:
|
||||
Exclude:
|
||||
- 'lib/open_food_network/enterprise_fee_applicator.rb'
|
||||
|
||||
# Offense count: 2
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: IgnoredMethods.
|
||||
# IgnoredMethods: respond_to, define_method
|
||||
Style/SymbolProc:
|
||||
Exclude:
|
||||
- 'app/models/spree/preferences/preferable.rb'
|
||||
|
||||
13
Gemfile
13
Gemfile
@@ -18,18 +18,11 @@ gem 'web', path: './engines/web'
|
||||
gem 'activerecord-postgresql-adapter'
|
||||
gem 'pg', '~> 0.21.0'
|
||||
|
||||
# OFN-maintained and patched version of Spree v2.0.4. See
|
||||
# https://github.com/openfoodfoundation/openfoodnetwork/wiki/Tech-Doc:-OFN's-Spree-fork%F0%9F%8D%B4
|
||||
# for details.
|
||||
gem 'spree_core', github: 'openfoodfoundation/spree', branch: '2-1-0-stable'
|
||||
|
||||
### Dependencies brought from spree core
|
||||
gem 'acts_as_list', '= 0.2.0'
|
||||
gem 'acts_as_list', '= 0.3.0'
|
||||
gem 'awesome_nested_set', '~> 3.0.0.rc.1'
|
||||
gem 'cancan', '~> 1.6.10'
|
||||
gem 'ffaker', '~> 1.16'
|
||||
gem 'highline', '= 1.6.18' # Necessary for the install generator
|
||||
gem 'httparty', '~> 0.18' # Used to check alerts in spree_core, this is not used in OFN.
|
||||
gem 'json', '>= 1.7.7'
|
||||
gem 'money', '5.1.1'
|
||||
gem 'paranoia', '~> 2.0'
|
||||
@@ -37,7 +30,7 @@ gem 'ransack', '~> 1.8.10'
|
||||
gem 'state_machine', '1.2.0'
|
||||
gem 'stringex', '~> 1.5.1'
|
||||
|
||||
gem 'spree_i18n', github: 'spree/spree_i18n', branch: '1-3-stable'
|
||||
gem 'spree_i18n', github: 'openfoodfoundation/spree_i18n', branch: '1-3-stable'
|
||||
|
||||
# Our branch contains the following changes:
|
||||
# - Pass customer email and phone number to PayPal (merged to upstream master)
|
||||
@@ -61,8 +54,6 @@ gem 'daemons'
|
||||
gem 'delayed_job_active_record'
|
||||
gem 'delayed_job_web'
|
||||
|
||||
# Spree's default pagination gem (locked to the current version used by Spree)
|
||||
# We use it's methods in OFN code as well, so this is a direct dependency
|
||||
gem 'kaminari', '~> 0.14.1'
|
||||
|
||||
gem 'andand'
|
||||
|
||||
44
Gemfile.lock
44
Gemfile.lock
@@ -6,12 +6,11 @@ GIT
|
||||
|
||||
GIT
|
||||
remote: https://github.com/openfoodfoundation/better_spree_paypal_express.git
|
||||
revision: 1736e3268239a841576d2719a1f276cf9b74c5c5
|
||||
revision: 1a477e9f7763297944cc99b6f4dd3d962aa963e9
|
||||
branch: 2-1-0-stable
|
||||
specs:
|
||||
spree_paypal_express (2.0.3)
|
||||
paypal-sdk-merchant (= 1.106.1)
|
||||
spree_core (~> 2.1.0)
|
||||
|
||||
GIT
|
||||
remote: https://github.com/openfoodfoundation/ofn-qz.git
|
||||
@@ -21,39 +20,13 @@ GIT
|
||||
ofn-qz (0.1.0)
|
||||
|
||||
GIT
|
||||
remote: https://github.com/openfoodfoundation/spree.git
|
||||
revision: cbb24a6ed701166ffaf2ab60a402154100d74766
|
||||
branch: 2-1-0-stable
|
||||
specs:
|
||||
spree_core (2.1.0)
|
||||
activemerchant (= 1.78.0)
|
||||
acts_as_list (= 0.2.0)
|
||||
awesome_nested_set (~> 3.0.0.rc.1)
|
||||
aws-sdk (= 1.11.1)
|
||||
cancan (~> 1.6.10)
|
||||
ffaker (~> 1.16)
|
||||
highline (= 1.6.18)
|
||||
httparty (~> 0.11)
|
||||
json (>= 1.7.7)
|
||||
kaminari (~> 0.14.1)
|
||||
money (= 5.1.1)
|
||||
paperclip (~> 3.4.1)
|
||||
paranoia (~> 2.0)
|
||||
rails (~> 4.0)
|
||||
ransack (~> 1.0)
|
||||
state_machine (= 1.2.0)
|
||||
stringex (~> 1.5.1)
|
||||
truncate_html (= 0.9.2)
|
||||
|
||||
GIT
|
||||
remote: https://github.com/spree/spree_i18n.git
|
||||
revision: 752eb67204e9c5a4e22b62591a8fd55fe2285e43
|
||||
remote: https://github.com/openfoodfoundation/spree_i18n.git
|
||||
revision: 12f18312232f0ce70270d47859d2951d12f7791c
|
||||
branch: 1-3-stable
|
||||
specs:
|
||||
spree_i18n (1.0.0)
|
||||
i18n (~> 0.5)
|
||||
rails-i18n
|
||||
spree_core (>= 1.1)
|
||||
|
||||
PATH
|
||||
remote: engines/catalog
|
||||
@@ -127,7 +100,7 @@ GEM
|
||||
tzinfo (~> 0.3.37)
|
||||
acts-as-taggable-on (4.0.0)
|
||||
activerecord (>= 4.0)
|
||||
acts_as_list (0.2.0)
|
||||
acts_as_list (0.3.0)
|
||||
activerecord (>= 3.0)
|
||||
addressable (2.7.0)
|
||||
public_suffix (>= 2.0.2, < 5.0)
|
||||
@@ -149,7 +122,7 @@ GEM
|
||||
nokogiri (>= 1.4.4)
|
||||
uuidtools (~> 2.1)
|
||||
bcrypt (3.1.13)
|
||||
bugsnag (6.17.0)
|
||||
bugsnag (6.18.0)
|
||||
concurrent-ruby (~> 1.0)
|
||||
builder (3.1.4)
|
||||
byebug (11.0.1)
|
||||
@@ -417,9 +390,6 @@ GEM
|
||||
hashdiff (1.0.1)
|
||||
highline (1.6.18)
|
||||
hike (1.2.3)
|
||||
httparty (0.18.1)
|
||||
mime-types (~> 3.0)
|
||||
multi_xml (>= 0.5.2)
|
||||
i18n (0.6.11)
|
||||
i18n-js (3.8.0)
|
||||
i18n (>= 0.6.6)
|
||||
@@ -710,7 +680,7 @@ DEPENDENCIES
|
||||
activerecord-postgresql-adapter
|
||||
activerecord-session_store
|
||||
acts-as-taggable-on (~> 4.0)
|
||||
acts_as_list (= 0.2.0)
|
||||
acts_as_list (= 0.3.0)
|
||||
andand
|
||||
angular-rails-templates (~> 0.3.0)
|
||||
angularjs-file-upload-rails (~> 2.4.1)
|
||||
@@ -752,7 +722,6 @@ DEPENDENCIES
|
||||
gmaps4rails
|
||||
haml
|
||||
highline (= 1.6.18)
|
||||
httparty (~> 0.18)
|
||||
i18n (~> 0.6.11)
|
||||
i18n-js (~> 3.8.0)
|
||||
immigrant
|
||||
@@ -799,7 +768,6 @@ DEPENDENCIES
|
||||
selenium-webdriver
|
||||
shoulda-matchers
|
||||
simplecov
|
||||
spree_core!
|
||||
spree_i18n!
|
||||
spree_paypal_express!
|
||||
spring
|
||||
|
||||
@@ -16,7 +16,7 @@ We're part of global movement - get involved!
|
||||
|
||||
## Contributing
|
||||
|
||||
If you are interested in contributing to the OFN in any capacity, please introduce yourself [on Slack][slack-invite], and have a look through our [Contributor Guide][contributor-guide].
|
||||
If you are interested in contributing to the OFN in any capacity, please introduce yourself [on Slack][slack-invite], and have a look through the [OFN Handbook][ofn-handbook].
|
||||
|
||||
Our [GETTING_STARTED](GETTING_STARTED.md) and [CONTRIBUTING](CONTRIBUTING.md) guides are the best place to start for developers looking to set up a development environment and make contributions to the codebase.
|
||||
|
||||
@@ -41,7 +41,7 @@ Copyright (c) 2012 - 2020 Open Food Foundation, released under the AGPL licence.
|
||||
|
||||
[survey]: https://docs.google.com/a/eaterprises.com.au/forms/d/1zxR5vSiU9CigJ9cEaC8-eJLgYid8CR8er7PPH9Mc-30/edit#
|
||||
[slack-invite]: https://join.slack.com/t/openfoodnetwork/shared_invite/zt-9sjkjdlu-r02kUMP1zbrTgUhZhYPF~A
|
||||
[contributor-guide]: https://ofn-user-guide.gitbook.io/ofn-contributor-guide/who-are-we
|
||||
[ofn-handbook]: https://ofn-user-guide.gitbook.io/ofn-handbook/
|
||||
[ofn-install]: https://github.com/openfoodfoundation/ofn-install
|
||||
[super-admin-guide]: https://ofn-user-guide.gitbook.io/ofn-super-admin-guide
|
||||
[welcome-dev]: https://github.com/openfoodfoundation/openfoodnetwork/projects/27
|
||||
|
||||
BIN
app/assets/images/logo/spree_50.png
Normal file
BIN
app/assets/images/logo/spree_50.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
@@ -34,7 +34,7 @@
|
||||
//= require css_browser_selector_dev
|
||||
//= require responsive-tables
|
||||
//= require admin/spree_paypal_express
|
||||
//= require handlebars
|
||||
//= require admin/spree/handlebar_extensions
|
||||
|
||||
// OFN specific
|
||||
//= require_tree ../templates/admin
|
||||
|
||||
@@ -104,7 +104,7 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", ($scope, $timeout
|
||||
$scope.$watch 'sortOptions', (sort) ->
|
||||
return unless sort && sort.predicate != ""
|
||||
|
||||
$scope.sorting = sort.getSortingExpr()
|
||||
$scope.q.sorting = sort.getSortingExpr()
|
||||
$scope.fetchProducts()
|
||||
, true
|
||||
|
||||
|
||||
@@ -47,3 +47,8 @@ angular.module("admin.customers").controller "customersCtrl", ($scope, $q, $filt
|
||||
tag.text.toLowerCase().indexOf(query.toLowerCase()) != -1
|
||||
defer.resolve filtered
|
||||
defer.promise
|
||||
|
||||
$scope.displayBalanceStatus = (customer) ->
|
||||
return unless customer.balance_status
|
||||
|
||||
t('admin.customers.index.' + customer.balance_status)
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
angular.module("admin.enterprises").directive 'termsAndConditionsWarning', ($compile, $templateCache, DialogDefaults, $timeout) ->
|
||||
restrict: 'A'
|
||||
scope: true
|
||||
|
||||
link: (scope, element, attr) ->
|
||||
# This file input click handler will hold the browser file input dialog and show a warning modal
|
||||
scope.hold_file_input_and_show_warning_modal = (event) ->
|
||||
event.preventDefault()
|
||||
scope.template = $compile($templateCache.get('admin/modals/terms_and_conditions_warning.html'))(scope)
|
||||
if scope.template.dialog
|
||||
scope.template.dialog(DialogDefaults)
|
||||
scope.template.dialog('open')
|
||||
scope.$apply()
|
||||
|
||||
element.bind 'click', scope.hold_file_input_and_show_warning_modal
|
||||
|
||||
# When the user presses continue in the warning modal, we open the browser file input dialog
|
||||
scope.continue = ->
|
||||
scope.template.dialog('close')
|
||||
|
||||
# unbind warning modal handler and click file input again to open the browser file input dialog
|
||||
element.unbind('click').trigger('click')
|
||||
# afterwards, bind warning modal handler again so that the warning is shown the next time
|
||||
$timeout ->
|
||||
element.bind 'click', scope.hold_file_input_and_show_warning_modal
|
||||
return
|
||||
|
||||
scope.close = ->
|
||||
scope.template.dialog('close')
|
||||
return
|
||||
@@ -1,4 +1,4 @@
|
||||
angular.module("admin.products").factory "VariantUnitManager", ->
|
||||
angular.module("admin.products").factory "VariantUnitManager", (availableUnits) ->
|
||||
class VariantUnitManager
|
||||
@units:
|
||||
'weight':
|
||||
@@ -29,12 +29,13 @@ angular.module("admin.products").factory "VariantUnitManager", ->
|
||||
system: 'metric'
|
||||
|
||||
@variantUnitOptions: ->
|
||||
available = availableUnits.split(",")
|
||||
options = for unit_type, _ of @units
|
||||
for scale in @unitScales(unit_type)
|
||||
for scale in @unitScales(unit_type, available)
|
||||
name = @getUnitName(scale, unit_type)
|
||||
["#{I18n.t(unit_type)} (#{name})", "#{unit_type}_#{scale}"]
|
||||
options.push [[I18n.t('items'), 'items']]
|
||||
[].concat options...
|
||||
options = [].concat options...
|
||||
|
||||
@getScale: (value, unitType) ->
|
||||
scaledValue = null
|
||||
@@ -53,8 +54,13 @@ angular.module("admin.products").factory "VariantUnitManager", ->
|
||||
else
|
||||
''
|
||||
|
||||
@unitScales: (unitType) ->
|
||||
(parseFloat(scale) for scale in Object.keys(@units[unitType])).sort (a, b) ->
|
||||
@unitScales: (unitType, availableUnits = null) ->
|
||||
scales = Object.keys(@units[unitType])
|
||||
if availableUnits
|
||||
scales = scales.filter (scale) ->
|
||||
availableUnits.includes(VariantUnitManager.getUnitName(scale, unitType))
|
||||
|
||||
(parseFloat(scale) for scale in scales).sort (a, b) ->
|
||||
a - b
|
||||
|
||||
@compatibleUnitScales: (scale, unitType) ->
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
//= require_self
|
||||
//= require admin/handlebar_extensions
|
||||
//= require admin/spree/orders/variant_autocomplete
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
//= require handlebars
|
||||
|
||||
Handlebars.registerHelper("t", function(key) {
|
||||
if (Spree.translations[key]) {
|
||||
return Spree.translations[key]
|
||||
} else {
|
||||
console.error("No translation found for " + key + ". Does it exist within spree/admin/shared/_translations.html.erb?")
|
||||
}
|
||||
});
|
||||
@@ -95,6 +95,10 @@ Darkswarm.factory 'Checkout', ($injector, CurrentOrder, ShippingMethods, StripeE
|
||||
last_name: @order.bill_address.lastname
|
||||
save_requested_by_customer: @secrets.save_requested_by_customer
|
||||
}
|
||||
|
||||
if @terms_and_conditions_accepted()
|
||||
munged_order["terms_and_conditions_accepted"] = true
|
||||
|
||||
munged_order
|
||||
|
||||
shippingMethod: ->
|
||||
@@ -114,3 +118,7 @@ Darkswarm.factory 'Checkout', ($injector, CurrentOrder, ShippingMethods, StripeE
|
||||
|
||||
cartTotal: ->
|
||||
@order.display_total + @shippingPrice() + @paymentPrice()
|
||||
|
||||
terms_and_conditions_accepted: ->
|
||||
terms_and_conditions_checkbox = angular.element("#accept_terms")[0]
|
||||
terms_and_conditions_checkbox? && terms_and_conditions_checkbox.checked
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
%div
|
||||
.margin-bottom-30.text-center
|
||||
.text-big
|
||||
{{ 'js.admin.modals.terms_and_conditions_info.title' | t }}
|
||||
.margin-bottom-30
|
||||
%p
|
||||
{{ 'js.admin.modals.terms_and_conditions_info.message_1' | t }}
|
||||
.margin-bottom-30
|
||||
%p
|
||||
{{ 'js.admin.modals.terms_and_conditions_info.message_2' | t }}
|
||||
|
||||
.text-center
|
||||
%input.button.red.icon-plus{ type: 'button', value: t('js.admin.modals.got_it'), ng: { click: 'close()' } }
|
||||
@@ -0,0 +1,14 @@
|
||||
%div
|
||||
.margin-bottom-30.text-center
|
||||
.text-big
|
||||
{{ 'js.admin.modals.terms_and_conditions_warning.title' | t }}
|
||||
.margin-bottom-30
|
||||
%p
|
||||
{{ 'js.admin.modals.terms_and_conditions_warning.message_1' | t }}
|
||||
.margin-bottom-30
|
||||
%p
|
||||
{{ 'js.admin.modals.terms_and_conditions_warning.message_2' | t }}
|
||||
|
||||
.text-center
|
||||
%input.button.red{ type: 'button', value: t('js.admin.modals.close'), ng: { click: 'close()' } }
|
||||
%input.button.red{ type: 'button', value: t('js.admin.modals.continue'), ng: { click: 'continue()' } }
|
||||
@@ -121,3 +121,10 @@ form#image_upload {
|
||||
}
|
||||
}
|
||||
|
||||
form.edit_image {
|
||||
.field {
|
||||
img {
|
||||
max-width: 150px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,3 +154,7 @@ input.text-big {
|
||||
.pad-top {
|
||||
padding-top: 1em;
|
||||
}
|
||||
|
||||
.white-space-nowrap {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
@@ -181,10 +181,10 @@ module Admin
|
||||
enterprise_payment_methods = @enterprise.payment_methods.to_a
|
||||
enterprise_shipping_methods = @enterprise.shipping_methods.to_a
|
||||
# rubocop:disable Style/TernaryParentheses
|
||||
@payment_methods = Spree::PaymentMethod.managed_by(spree_current_user).sort_by! do |pm|
|
||||
@payment_methods = Spree::PaymentMethod.managed_by(spree_current_user).to_a.sort_by! do |pm|
|
||||
[(enterprise_payment_methods.include? pm) ? 0 : 1, pm.name]
|
||||
end
|
||||
@shipping_methods = Spree::ShippingMethod.managed_by(spree_current_user).sort_by! do |sm|
|
||||
@shipping_methods = Spree::ShippingMethod.managed_by(spree_current_user).to_a.sort_by! do |sm|
|
||||
[(enterprise_shipping_methods.include? sm) ? 0 : 1, sm.name]
|
||||
end
|
||||
# rubocop:enable Style/TernaryParentheses
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
require 'open_food_network/permissions'
|
||||
require 'spree/core/product_duplicator'
|
||||
|
||||
module Api
|
||||
class ProductsController < Api::BaseController
|
||||
|
||||
@@ -10,6 +10,7 @@ module Spree
|
||||
end
|
||||
|
||||
def update
|
||||
merge_available_units_params unless params[:available_units].nil?
|
||||
params.each do |name, value|
|
||||
next unless Spree::Config.has_preference? name
|
||||
|
||||
@@ -19,6 +20,13 @@ module Spree
|
||||
|
||||
redirect_to spree.edit_admin_general_settings_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def merge_available_units_params
|
||||
params[:available_units] =
|
||||
params[:available_units].select { |_unit, checked| checked == "1" }.keys.join(",")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -25,7 +25,7 @@ module Spree
|
||||
@object.attributes = permitted_resource_params
|
||||
if @object.save
|
||||
flash[:success] = flash_message_for(@object, :successfully_created)
|
||||
redirect_to admin_product_images_url(params[:product_id], @url_filters)
|
||||
redirect_to spree.admin_product_images_url(params[:product_id], @url_filters)
|
||||
else
|
||||
respond_with(@object)
|
||||
end
|
||||
@@ -41,7 +41,7 @@ module Spree
|
||||
|
||||
if @object.update(permitted_resource_params)
|
||||
flash[:success] = flash_message_for(@object, :successfully_updated)
|
||||
redirect_to admin_product_images_url(params[:product_id], @url_filters)
|
||||
redirect_to spree.admin_product_images_url(params[:product_id], @url_filters)
|
||||
else
|
||||
respond_with(@object)
|
||||
end
|
||||
@@ -55,7 +55,7 @@ module Spree
|
||||
flash[:success] = flash_message_for(@object, :successfully_removed)
|
||||
end
|
||||
|
||||
redirect_to admin_product_images_url(params[:product_id], @url_filters)
|
||||
redirect_to spree.admin_product_images_url(params[:product_id], @url_filters)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -127,7 +127,7 @@ module Spree
|
||||
|
||||
def load_hubs
|
||||
# rubocop:disable Style/TernaryParentheses
|
||||
@hubs = Enterprise.managed_by(spree_current_user).is_distributor.sort_by! do |d|
|
||||
@hubs = Enterprise.managed_by(spree_current_user).is_distributor.to_a.sort_by! do |d|
|
||||
[(@payment_method.has_distributor? d) ? 0 : 1, d.name]
|
||||
end
|
||||
# rubocop:enable Style/TernaryParentheses
|
||||
|
||||
@@ -16,7 +16,7 @@ module Spree
|
||||
flash[:success] = flash_message_for(@object, :successfully_removed)
|
||||
end
|
||||
# if destroy fails it won't show any errors to the user
|
||||
redirect_to admin_product_product_properties_url(params[:product_id], @url_filters)
|
||||
redirect_to spree.admin_product_product_properties_url(params[:product_id], @url_filters)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -294,7 +294,7 @@ module Spree
|
||||
if report_in_order_management_engine?(report)
|
||||
main_app.public_send("new_order_management_reports_#{report}_url".to_sym)
|
||||
else
|
||||
public_send("#{report}_admin_reports_url".to_sym)
|
||||
spree.public_send("#{report}_admin_reports_url".to_sym)
|
||||
end
|
||||
rescue NoMethodError
|
||||
url_for([:new, :admin, :reports, report.to_s.singularize])
|
||||
|
||||
@@ -50,7 +50,7 @@ module Spree
|
||||
|
||||
def load_hubs
|
||||
# rubocop:disable Style/TernaryParentheses
|
||||
@hubs = Enterprise.managed_by(spree_current_user).is_distributor.sort_by! do |d|
|
||||
@hubs = Enterprise.managed_by(spree_current_user).is_distributor.to_a.sort_by! do |d|
|
||||
[(@shipping_method.has_distributor? d) ? 0 : 1, d.name]
|
||||
end
|
||||
# rubocop:enable Style/TernaryParentheses
|
||||
|
||||
@@ -21,9 +21,9 @@ module Spree
|
||||
|
||||
if @object.update(permitted_resource_params)
|
||||
flash[:success] = flash_message_for(@object, :successfully_updated)
|
||||
redirect_to admin_product_variants_url(params[:product_id], @url_filters)
|
||||
redirect_to spree.admin_product_variants_url(params[:product_id], @url_filters)
|
||||
else
|
||||
redirect_to edit_admin_product_variant_url(params[:product_id], @object, @url_filters)
|
||||
redirect_to spree.edit_admin_product_variant_url(params[:product_id], @object, @url_filters)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -40,9 +40,9 @@ module Spree
|
||||
@object.attributes = permitted_resource_params
|
||||
if @object.save
|
||||
flash[:success] = flash_message_for(@object, :successfully_created)
|
||||
redirect_to admin_product_variants_url(params[:product_id], @url_filters)
|
||||
redirect_to spree.admin_product_variants_url(params[:product_id], @url_filters)
|
||||
else
|
||||
redirect_to new_admin_product_variant_url(params[:product_id], @url_filters)
|
||||
redirect_to spree.new_admin_product_variant_url(params[:product_id], @url_filters)
|
||||
end
|
||||
|
||||
return unless @object.present? && @object.valid?
|
||||
|
||||
@@ -6,6 +6,51 @@ Spree::PaypalController.class_eval do
|
||||
after_action :reset_order_when_complete, only: :confirm
|
||||
before_action :permit_parameters!
|
||||
|
||||
def express
|
||||
order = current_order || raise(ActiveRecord::RecordNotFound)
|
||||
items = order.line_items.map(&method(:line_item))
|
||||
|
||||
tax_adjustments = order.adjustments.tax
|
||||
# TODO: Remove in Spree 2.2
|
||||
tax_adjustments = tax_adjustments.additional if tax_adjustments.respond_to?(:additional)
|
||||
shipping_adjustments = order.adjustments.shipping
|
||||
|
||||
order.adjustments.eligible.each do |adjustment|
|
||||
next if (tax_adjustments + shipping_adjustments).include?(adjustment)
|
||||
|
||||
items << {
|
||||
Name: adjustment.label,
|
||||
Quantity: 1,
|
||||
Amount: {
|
||||
currencyID: order.currency,
|
||||
value: adjustment.amount
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
# Because PayPal doesn't accept $0 items at all.
|
||||
# See #10
|
||||
# https://cms.paypal.com/uk/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ECCustomizing
|
||||
# "It can be a positive or negative value but not zero."
|
||||
items.reject! do |item|
|
||||
item[:Amount][:value].zero?
|
||||
end
|
||||
pp_request = provider.build_set_express_checkout(express_checkout_request_details(order, items))
|
||||
|
||||
begin
|
||||
pp_response = provider.set_express_checkout(pp_request)
|
||||
if pp_response.success?
|
||||
redirect_to provider.express_checkout_url(pp_response, useraction: 'commit')
|
||||
else
|
||||
flash[:error] = Spree.t('flash.generic_error', scope: 'paypal', reasons: pp_response.errors.map(&:long_message).join(" "))
|
||||
redirect_to spree.checkout_state_path(:payment)
|
||||
end
|
||||
rescue SocketError
|
||||
flash[:error] = Spree.t('flash.connection_failed', scope: 'paypal')
|
||||
redirect_to spree.checkout_state_path(:payment)
|
||||
end
|
||||
end
|
||||
|
||||
def cancel
|
||||
flash[:notice] = Spree.t('flash.cancel', scope: 'paypal')
|
||||
redirect_to main_app.checkout_path
|
||||
@@ -49,4 +94,24 @@ Spree::PaypalController.class_eval do
|
||||
orphaned_payments = current_order.payments.where(payment_method_id: payment_method.id, source_id: nil)
|
||||
orphaned_payments.each(&:destroy)
|
||||
end
|
||||
|
||||
def completion_route(order)
|
||||
spree.order_path(order, token: order.token)
|
||||
end
|
||||
|
||||
def express_checkout_request_details(order, items)
|
||||
{
|
||||
SetExpressCheckoutRequestDetails: {
|
||||
InvoiceID: order.number,
|
||||
BuyerEmail: order.email,
|
||||
ReturnURL: spree.confirm_paypal_url(payment_method_id: params[:payment_method_id], utm_nooverride: 1),
|
||||
CancelURL: spree.cancel_paypal_url,
|
||||
SolutionType: payment_method.preferred_solution.presence || "Mark",
|
||||
LandingPage: payment_method.preferred_landing_page.presence || "Billing",
|
||||
cppheaderimage: payment_method.preferred_logourl.presence || "",
|
||||
NoShipping: 1,
|
||||
PaymentDetails: [payment_details(items)]
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -184,6 +184,12 @@ module Admin
|
||||
json: "'#{@spree_api_key}'" }
|
||||
end
|
||||
|
||||
def admin_inject_available_units
|
||||
admin_inject_json "admin.products",
|
||||
"availableUnits",
|
||||
Spree::Config.available_units
|
||||
end
|
||||
|
||||
def admin_inject_json(ng_module, name, data)
|
||||
json = data.to_json
|
||||
render partial: "admin/json/injection_ams",
|
||||
|
||||
@@ -7,6 +7,8 @@ module CheckoutHelper
|
||||
adjustments = order.adjustments.eligible
|
||||
exclude = opts[:exclude] || {}
|
||||
|
||||
adjustments = adjustments.to_a
|
||||
|
||||
# Remove empty tax adjustments and (optionally) shipping fees
|
||||
adjustments.reject! { |a| a.originator_type == 'Spree::TaxRate' && a.amount == 0 }
|
||||
adjustments.reject! { |a| a.originator_type == 'Spree::ShippingMethod' } if exclude.include? :shipping
|
||||
|
||||
@@ -4,7 +4,7 @@ module InjectionHelper
|
||||
include SerializerHelper
|
||||
|
||||
def inject_enterprises(enterprises = nil)
|
||||
inject_json_ams(
|
||||
inject_json_array(
|
||||
"enterprises",
|
||||
enterprises || default_enterprise_query,
|
||||
Api::EnterpriseSerializer,
|
||||
@@ -15,7 +15,7 @@ module InjectionHelper
|
||||
def inject_groups
|
||||
select_only = required_attributes EnterpriseGroup, Api::GroupListSerializer
|
||||
|
||||
inject_json_ams(
|
||||
inject_json_array(
|
||||
"groups",
|
||||
EnterpriseGroup.on_front_page.by_position.select(select_only).
|
||||
includes(enterprises: [:shipping_methods, { address: [:state, :country] }],
|
||||
@@ -26,7 +26,7 @@ module InjectionHelper
|
||||
end
|
||||
|
||||
def inject_enterprise_shopfront(enterprise)
|
||||
inject_json_ams(
|
||||
inject_json(
|
||||
"shopfront",
|
||||
enterprise,
|
||||
Api::EnterpriseShopfrontSerializer
|
||||
@@ -36,7 +36,7 @@ module InjectionHelper
|
||||
def inject_enterprise_shopfront_list
|
||||
select_only = required_attributes Enterprise, Api::EnterpriseShopfrontListSerializer
|
||||
|
||||
inject_json_ams(
|
||||
inject_json_array(
|
||||
"enterprises",
|
||||
Enterprise.activated.visible.select(select_only).includes(address: [:state, :country]).all,
|
||||
Api::EnterpriseShopfrontListSerializer
|
||||
@@ -50,13 +50,13 @@ module InjectionHelper
|
||||
includes(:properties, address: [:state, :country], supplied_products: :properties).
|
||||
all
|
||||
|
||||
inject_json_ams "enterprises",
|
||||
enterprises_and_relatives,
|
||||
Api::EnterpriseSerializer, enterprise_injection_data
|
||||
inject_json_array "enterprises",
|
||||
enterprises_and_relatives,
|
||||
Api::EnterpriseSerializer, enterprise_injection_data
|
||||
end
|
||||
|
||||
def inject_group_enterprises
|
||||
inject_json_ams(
|
||||
inject_json_array(
|
||||
"enterprises",
|
||||
@group.enterprises.activated.all,
|
||||
Api::EnterpriseSerializer,
|
||||
@@ -65,11 +65,18 @@ module InjectionHelper
|
||||
end
|
||||
|
||||
def inject_current_hub
|
||||
inject_json_ams "currentHub", current_distributor, Api::EnterpriseSerializer, enterprise_injection_data
|
||||
inject_json "currentHub",
|
||||
current_distributor,
|
||||
Api::EnterpriseSerializer,
|
||||
enterprise_injection_data
|
||||
end
|
||||
|
||||
def inject_current_order
|
||||
inject_json_ams "currentOrder", current_order, Api::CurrentOrderSerializer, current_distributor: current_distributor, current_order_cycle: current_order_cycle
|
||||
inject_json "currentOrder",
|
||||
current_order,
|
||||
Api::CurrentOrderSerializer,
|
||||
current_distributor: current_distributor,
|
||||
current_order_cycle: current_order_cycle
|
||||
end
|
||||
|
||||
def inject_current_order_cycle
|
||||
@@ -79,73 +86,78 @@ module InjectionHelper
|
||||
end
|
||||
|
||||
def inject_available_shipping_methods
|
||||
inject_json_ams "shippingMethods", available_shipping_methods,
|
||||
Api::ShippingMethodSerializer, current_order: current_order
|
||||
inject_json_array "shippingMethods", available_shipping_methods,
|
||||
Api::ShippingMethodSerializer, current_order: current_order
|
||||
end
|
||||
|
||||
def inject_available_payment_methods
|
||||
inject_json_ams "paymentMethods", available_payment_methods,
|
||||
Api::PaymentMethodSerializer, current_order: current_order
|
||||
inject_json_array "paymentMethods", available_payment_methods,
|
||||
Api::PaymentMethodSerializer, current_order: current_order
|
||||
end
|
||||
|
||||
def inject_taxons
|
||||
inject_json_ams "taxons", Spree::Taxon.all.to_a, Api::TaxonSerializer
|
||||
inject_json_array "taxons", Spree::Taxon.all.to_a, Api::TaxonSerializer
|
||||
end
|
||||
|
||||
def inject_properties
|
||||
inject_json_ams "properties", Spree::Property.all.to_a, Api::PropertySerializer
|
||||
inject_json_array "properties", Spree::Property.all.to_a, Api::PropertySerializer
|
||||
end
|
||||
|
||||
def inject_currency_config
|
||||
inject_json_ams "currencyConfig", {}, Api::CurrencyConfigSerializer
|
||||
inject_json "currencyConfig", {}, Api::CurrencyConfigSerializer
|
||||
end
|
||||
|
||||
def inject_open_street_map_config
|
||||
inject_json_ams "openStreetMapConfig", {}, Api::OpenStreetMapConfigSerializer
|
||||
inject_json "openStreetMapConfig", {}, Api::OpenStreetMapConfigSerializer
|
||||
end
|
||||
|
||||
def inject_spree_api_key
|
||||
render partial: "json/injection_ams", locals: { name: 'spreeApiKey', json: "'#{@spree_api_key}'" }
|
||||
render partial: "json/injection_ams",
|
||||
locals: { name: 'spreeApiKey', json: "'#{@spree_api_key}'" }
|
||||
end
|
||||
|
||||
def inject_available_countries
|
||||
inject_json_ams "availableCountries", available_countries, Api::CountrySerializer
|
||||
inject_json_array "availableCountries", available_countries, Api::CountrySerializer
|
||||
end
|
||||
|
||||
def inject_enterprise_attributes
|
||||
render partial: "json/injection_ams", locals: { name: 'enterpriseAttributes', json: @enterprise_attributes.to_json.to_s }
|
||||
render partial: "json/injection_ams",
|
||||
locals: { name: 'enterpriseAttributes', json: @enterprise_attributes.to_json.to_s }
|
||||
end
|
||||
|
||||
def inject_orders
|
||||
inject_json_ams "orders", @orders.all, Api::OrderSerializer
|
||||
inject_json_array "orders", @orders.all, Api::OrderSerializer
|
||||
end
|
||||
|
||||
def inject_shops
|
||||
customers = spree_current_user.customers
|
||||
shops = Enterprise.where(id: @orders.pluck(:distributor_id).uniq | customers.pluck(:enterprise_id))
|
||||
inject_json_ams "shops", shops.all, Api::ShopForOrdersSerializer
|
||||
shops = Enterprise.where(id: @orders.pluck(:distributor_id).uniq |
|
||||
customers.pluck(:enterprise_id))
|
||||
inject_json_array "shops", shops.all, Api::ShopForOrdersSerializer
|
||||
end
|
||||
|
||||
def inject_saved_credit_cards
|
||||
data = spree_current_user ? spree_current_user.credit_cards.with_payment_profile.all : []
|
||||
|
||||
inject_json_ams "savedCreditCards", data, Api::CreditCardSerializer
|
||||
inject_json_array "savedCreditCards", data, Api::CreditCardSerializer
|
||||
end
|
||||
|
||||
def inject_current_user
|
||||
inject_json_ams "user", spree_current_user, Api::UserSerializer
|
||||
inject_json "user", spree_current_user, Api::UserSerializer
|
||||
end
|
||||
|
||||
def inject_rails_flash
|
||||
inject_json_ams "railsFlash", OpenStruct.new(flash.to_hash), Api::RailsFlashSerializer
|
||||
inject_json "railsFlash", OpenStruct.new(flash.to_hash), Api::RailsFlashSerializer
|
||||
end
|
||||
|
||||
def inject_json_ams(name, data, serializer, opts = {})
|
||||
if data.is_a?(Array)
|
||||
opts = { each_serializer: serializer }.merge(opts)
|
||||
serializer = ActiveModel::ArraySerializer
|
||||
end
|
||||
def inject_json_array(name, data, serializer, opts = {})
|
||||
opts = { each_serializer: serializer }.merge(opts)
|
||||
serializer = ActiveModel::ArraySerializer
|
||||
|
||||
inject_json(name, data, serializer, opts)
|
||||
end
|
||||
|
||||
def inject_json(name, data, serializer, opts = {})
|
||||
serializer_instance = serializer.new(data, opts)
|
||||
json = serializer_instance.to_json
|
||||
render partial: "json/injection_ams", locals: { name: name, json: json }
|
||||
|
||||
@@ -8,6 +8,10 @@ module Spree
|
||||
end
|
||||
options_from_collection_for_select(currencies, :first, :last, Spree::Config[:currency])
|
||||
end
|
||||
|
||||
def all_units
|
||||
["g", "oz", "lb", "kg", "T", "mL", "L", "kL"]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -86,9 +86,9 @@ module Spree
|
||||
|
||||
def link_to_delete(resource, options = {})
|
||||
url = options[:url] || object_url(resource)
|
||||
name = options[:name] || Spree.t(:delete)
|
||||
name = options[:name] || I18n.t(:delete)
|
||||
options[:class] = "delete-resource"
|
||||
options[:data] = { confirm: Spree.t(:are_you_sure), action: 'remove' }
|
||||
options[:data] = { confirm: I18n.t(:are_you_sure), action: 'remove' }
|
||||
link_to_with_icon 'icon-trash', name, url, options
|
||||
end
|
||||
|
||||
|
||||
@@ -113,11 +113,12 @@ module Spree
|
||||
end
|
||||
|
||||
def event_link(event)
|
||||
button_link_to(Spree.t(event),
|
||||
event_label = I18n.t(event, scope: "actions")
|
||||
confirm_message = I18n.t("admin.orders.edit.order_sure_want_to", event: event_label)
|
||||
button_link_to(event_label,
|
||||
fire_admin_order_url(@order, e: event),
|
||||
method: :put,
|
||||
icon: "icon-#{event}",
|
||||
data: { confirm: Spree.t(:order_sure_want_to, event: Spree.t(event)) })
|
||||
method: :put, icon: "icon-#{event}",
|
||||
data: { confirm: confirm_message })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
16
app/helpers/terms_and_conditions_helper.rb
Normal file
16
app/helpers/terms_and_conditions_helper.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module TermsAndConditionsHelper
|
||||
def terms_and_conditions_activated?
|
||||
current_order.distributor.terms_and_conditions.file?
|
||||
end
|
||||
|
||||
def terms_and_conditions_already_accepted?
|
||||
customer_terms_and_conditions_accepted_at = spree_current_user&.
|
||||
customer_of(current_order.distributor)&.terms_and_conditions_accepted_at
|
||||
|
||||
customer_terms_and_conditions_accepted_at.present? &&
|
||||
(customer_terms_and_conditions_accepted_at >
|
||||
current_order.distributor.terms_and_conditions_updated_at)
|
||||
end
|
||||
end
|
||||
@@ -60,11 +60,11 @@ class ProducerMailer < Spree::BaseMailer
|
||||
end
|
||||
|
||||
def total_from_line_items(line_items)
|
||||
Spree::Money.new line_items.sum(&:total)
|
||||
Spree::Money.new line_items.to_a.sum(&:total)
|
||||
end
|
||||
|
||||
def tax_total_from_line_items(line_items)
|
||||
Spree::Money.new line_items.sum(&:included_tax)
|
||||
Spree::Money.new line_items.to_a.sum(&:included_tax)
|
||||
end
|
||||
|
||||
# This hack makes ActiveRecord skip the default_scope (deleted_at IS NULL)
|
||||
|
||||
@@ -8,10 +8,12 @@ module Spree
|
||||
def reset_password_instructions(user, token, _opts = {})
|
||||
@edit_password_reset_url = spree.
|
||||
edit_spree_user_password_url(reset_password_token: token)
|
||||
subject = "#{Spree::Config[:site_name]} " \
|
||||
"#{I18n.t('spree.user_mailer.reset_password_instructions.subject')}"
|
||||
|
||||
mail(to: user.email, from: from_address,
|
||||
subject: Spree::Config[:site_name] + ' ' +
|
||||
I18n.t(:subject, scope: [:devise, :mailer, :reset_password_instructions]))
|
||||
I18n.with_locale valid_locale(user) do
|
||||
mail(to: user.email, from: from_address, subject: subject)
|
||||
end
|
||||
end
|
||||
|
||||
# This is a OFN specific email, not from Devise::Mailer
|
||||
|
||||
@@ -49,7 +49,7 @@ module Calculator
|
||||
# Finds relevant fees for each line_item,
|
||||
# calculates the tax on them, and returns the total tax
|
||||
def per_item_fees_total(order, calculator)
|
||||
order.line_items.sum do |line_item|
|
||||
order.line_items.to_a.sum do |line_item|
|
||||
calculator.per_item_enterprise_fee_applicators_for(line_item.variant)
|
||||
.select { |applicator| applicable_rate?(applicator, line_item) }
|
||||
.sum { |applicator| applicator.enterprise_fee.compute_amount(line_item) }
|
||||
|
||||
@@ -18,7 +18,7 @@ class Calculator::FlatPercentPerItem < Spree::Calculator
|
||||
end
|
||||
|
||||
def compute(object)
|
||||
line_items_for(object).sum do |li|
|
||||
line_items_for(object).to_a.sum do |li|
|
||||
unless li.price.present? && li.quantity.present?
|
||||
raise ArgumentError, "object must respond to #price and #quantity"
|
||||
end
|
||||
|
||||
@@ -32,7 +32,7 @@ module Calculator
|
||||
private
|
||||
|
||||
def total_weight(line_items)
|
||||
line_items.sum do |line_item|
|
||||
line_items.to_a.sum do |line_item|
|
||||
line_item_weight(line_item)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,7 +4,7 @@ module ProductStock
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def on_demand
|
||||
if has_variants?
|
||||
if variants?
|
||||
raise 'Cannot determine product on_demand value of product with multiple variants' if variants.size > 1
|
||||
|
||||
variants.first.on_demand
|
||||
@@ -14,7 +14,7 @@ module ProductStock
|
||||
end
|
||||
|
||||
def on_hand
|
||||
if has_variants?
|
||||
if variants?
|
||||
variants.map(&:on_hand).reduce(:+)
|
||||
else
|
||||
master.on_hand
|
||||
|
||||
@@ -470,6 +470,8 @@ class Enterprise < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def initialize_permalink
|
||||
return unless name
|
||||
|
||||
self.permalink = Enterprise.find_available_permalink(name)
|
||||
end
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ class ModelSet
|
||||
# Remove all elements to be deleted from collection and return them
|
||||
# Allows us to render @model_set.collection without deleted elements
|
||||
deleted = []
|
||||
@collection = collection.to_a
|
||||
collection.delete_if { |e| deleted << e if @delete_if.andand.call(e.attributes) }
|
||||
deleted
|
||||
end
|
||||
|
||||
@@ -47,7 +47,7 @@ module Spree
|
||||
end
|
||||
|
||||
add_shopping_abilities user
|
||||
add_base_abilities user if new_user? user
|
||||
add_base_abilities user if is_new_user? user
|
||||
add_enterprise_management_abilities user if can_manage_enterprises? user
|
||||
add_group_management_abilities user if can_manage_groups? user
|
||||
add_product_management_abilities user if can_manage_products? user
|
||||
@@ -57,7 +57,7 @@ module Spree
|
||||
end
|
||||
|
||||
# New users have no enterprises.
|
||||
def new_user?(user)
|
||||
def is_new_user?(user)
|
||||
user.enterprises.blank?
|
||||
end
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
# a.get :color
|
||||
# a.preferred_color
|
||||
#
|
||||
require 'spree/core/mail_settings'
|
||||
|
||||
module Spree
|
||||
class AppConfiguration < Preferences::Configuration
|
||||
# Should state/state_name be required
|
||||
@@ -144,5 +146,8 @@ module Spree
|
||||
# Enable cache
|
||||
preference :enable_products_cache?, :boolean,
|
||||
default: (Rails.env.production? || Rails.env.staging?)
|
||||
|
||||
# Available units
|
||||
preference :available_units, :string, default: "g,kg,T,mL,L,kL"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'spree/core/s3_support'
|
||||
|
||||
module Spree
|
||||
class Image < Asset
|
||||
validates_attachment_presence :attachment
|
||||
|
||||
@@ -192,7 +192,7 @@ module Spree
|
||||
|
||||
line_item_adjustments = OrderAdjustmentsFetcher.new(order).line_item_adjustments(self)
|
||||
|
||||
(price + line_item_adjustments.sum(&:amount) / quantity).round(2)
|
||||
(price + line_item_adjustments.to_a.sum(&:amount) / quantity).round(2)
|
||||
end
|
||||
|
||||
def single_display_amount_with_adjustments
|
||||
|
||||
18
app/models/spree/option_type.rb
Normal file
18
app/models/spree/option_type.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Spree
|
||||
class OptionType < ActiveRecord::Base
|
||||
has_many :products, through: :product_option_types
|
||||
has_many :option_values, -> { order(:position) }, dependent: :destroy
|
||||
has_many :product_option_types, dependent: :destroy
|
||||
|
||||
validates :name, :presentation, presence: true
|
||||
default_scope -> { order("#{table_name}.position") }
|
||||
|
||||
accepts_nested_attributes_for :option_values,
|
||||
reject_if: lambda { |ov|
|
||||
ov[:name].blank? || ov[:presentation].blank?
|
||||
},
|
||||
allow_destroy: true
|
||||
end
|
||||
end
|
||||
@@ -1,5 +0,0 @@
|
||||
module Spree
|
||||
OptionType.class_eval do
|
||||
has_many :products, through: :product_option_types
|
||||
end
|
||||
end
|
||||
12
app/models/spree/option_value.rb
Normal file
12
app/models/spree/option_value.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Spree
|
||||
class OptionValue < ActiveRecord::Base
|
||||
belongs_to :option_type
|
||||
acts_as_list scope: :option_type
|
||||
has_and_belongs_to_many :variants, join_table: 'spree_option_values_variants',
|
||||
class_name: "Spree::Variant"
|
||||
|
||||
validates :name, :presentation, presence: true
|
||||
end
|
||||
end
|
||||
@@ -10,6 +10,9 @@
|
||||
# inherited hook will assign a new hash for the subclass definitions
|
||||
# and copy all the definitions allowing the subclass to add
|
||||
# additional defintions without affecting the base
|
||||
|
||||
require 'spree/preferences/store'
|
||||
|
||||
module Spree
|
||||
module Preferences
|
||||
module Preferable
|
||||
|
||||
57
app/models/spree/price.rb
Normal file
57
app/models/spree/price.rb
Normal file
@@ -0,0 +1,57 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Spree
|
||||
class Price < ActiveRecord::Base
|
||||
acts_as_paranoid without_default_scope: true
|
||||
|
||||
belongs_to :variant, class_name: 'Spree::Variant'
|
||||
|
||||
validate :check_price
|
||||
validates :amount, numericality: { greater_than_or_equal_to: 0 }, allow_nil: true
|
||||
|
||||
def display_amount
|
||||
money
|
||||
end
|
||||
alias :display_price :display_amount
|
||||
|
||||
def money
|
||||
Spree::Money.new(amount || 0, currency: currency)
|
||||
end
|
||||
|
||||
def price
|
||||
amount
|
||||
end
|
||||
|
||||
def price=(price)
|
||||
self[:amount] = parse_price(price)
|
||||
end
|
||||
|
||||
# Allow prices to access associated soft-deleted variants.
|
||||
def variant
|
||||
Spree::Variant.unscoped { super }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_price
|
||||
return unless currency.nil?
|
||||
|
||||
self.currency = Spree::Config[:currency]
|
||||
end
|
||||
|
||||
# strips all non-price-like characters from the price, taking into account locale settings
|
||||
def parse_price(price)
|
||||
return price unless price.is_a?(String)
|
||||
|
||||
separator, _delimiter = I18n.t([:'number.currency.format.separator',
|
||||
:'number.currency.format.delimiter'])
|
||||
non_price_characters = /[^0-9\-#{separator}]/
|
||||
# Strip everything else first
|
||||
price.gsub!(non_price_characters, '')
|
||||
# Then replace the locale-specific decimal separator with the standard separator if necessary
|
||||
price.gsub!(separator, '.') unless separator == '.'
|
||||
|
||||
price.to_d
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,18 +0,0 @@
|
||||
module Spree
|
||||
Price.class_eval do
|
||||
acts_as_paranoid without_default_scope: true
|
||||
|
||||
# Allow prices to access associated soft-deleted variants.
|
||||
def variant
|
||||
Spree::Variant.unscoped { super }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_price
|
||||
if currency.nil?
|
||||
self.currency = Spree::Config[:currency]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
485
app/models/spree/product.rb
Executable file
485
app/models/spree/product.rb
Executable file
@@ -0,0 +1,485 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'open_food_network/permalink_generator'
|
||||
require 'open_food_network/property_merge'
|
||||
require 'concerns/product_stock'
|
||||
|
||||
# PRODUCTS
|
||||
# Products represent an entity for sale in a store.
|
||||
# Products can have variations, called variants
|
||||
# Products properties include description, permalink, availability,
|
||||
# shipping category, etc. that do not change by variant.
|
||||
#
|
||||
# MASTER VARIANT
|
||||
# Every product has one master variant, which stores master price and sku, size and weight, etc.
|
||||
# The master variant does not have option values associated with it.
|
||||
# Price, SKU, size, weight, etc. are all delegated to the master variant.
|
||||
# Contains on_hand inventory levels only when there are no variants for the product.
|
||||
#
|
||||
# VARIANTS
|
||||
# All variants can access the product properties directly (via reverse delegation).
|
||||
# Inventory units are tied to Variant.
|
||||
# The master variant can have inventory units, but not option values.
|
||||
# All other variants have option values and may have inventory units.
|
||||
# Sum of on_hand each variant's inventory level determine "on_hand" level for the product.
|
||||
#
|
||||
module Spree
|
||||
class Product < ActiveRecord::Base
|
||||
include PermalinkGenerator
|
||||
include ProductStock
|
||||
|
||||
acts_as_paranoid
|
||||
|
||||
has_many :product_option_types, dependent: :destroy
|
||||
# We have an after_destroy callback on Spree::ProductOptionType. However, if we
|
||||
# don't specify dependent => destroy on this association, it is not called. See:
|
||||
# https://github.com/rails/rails/issues/7618
|
||||
has_many :option_types, through: :product_option_types, dependent: :destroy
|
||||
has_many :product_properties, dependent: :destroy
|
||||
has_many :properties, through: :product_properties
|
||||
|
||||
has_many :classifications, dependent: :delete_all
|
||||
has_many :taxons, through: :classifications
|
||||
|
||||
belongs_to :tax_category, class_name: 'Spree::TaxCategory'
|
||||
belongs_to :shipping_category, class_name: 'Spree::ShippingCategory'
|
||||
belongs_to :supplier, class_name: 'Enterprise', touch: true
|
||||
belongs_to :primary_taxon, class_name: 'Spree::Taxon', touch: true
|
||||
|
||||
has_one :master,
|
||||
-> { where is_master: true },
|
||||
class_name: 'Spree::Variant',
|
||||
dependent: :destroy
|
||||
|
||||
has_many :variants, -> {
|
||||
where(is_master: false).order("#{::Spree::Variant.quoted_table_name}.position ASC")
|
||||
}, class_name: 'Spree::Variant'
|
||||
|
||||
has_many :variants_including_master,
|
||||
-> { order("#{::Spree::Variant.quoted_table_name}.position ASC") },
|
||||
class_name: 'Spree::Variant',
|
||||
dependent: :destroy
|
||||
|
||||
has_many :prices, -> {
|
||||
order('spree_variants.position, spree_variants.id, currency')
|
||||
}, through: :variants
|
||||
|
||||
has_many :stock_items, through: :variants
|
||||
|
||||
delegate_belongs_to :master, :sku, :price, :currency, :display_amount, :display_price, :weight,
|
||||
:height, :width, :depth, :is_master, :default_price?, :cost_currency,
|
||||
:price_in, :amount_in, :unit_value, :unit_description
|
||||
delegate_belongs_to :master, :cost_price if Variant.table_exists? &&
|
||||
Variant.column_names.include?('cost_price')
|
||||
delegate :images_attributes=, :display_as=, to: :master
|
||||
|
||||
after_create :set_master_variant_defaults
|
||||
after_create :build_variants_from_option_values_hash, if: :option_values_hash
|
||||
after_save :save_master
|
||||
|
||||
delegate :images, to: :master, prefix: true
|
||||
alias_method :images, :master_images
|
||||
|
||||
has_many :variant_images, -> { order(:position) }, source: :images,
|
||||
through: :variants_including_master
|
||||
|
||||
accepts_nested_attributes_for :variants, allow_destroy: true
|
||||
|
||||
validates :name, presence: true
|
||||
validates :permalink, presence: true
|
||||
validates :price, presence: true, if: proc { Spree::Config[:require_master_price] }
|
||||
validates :shipping_category_id, presence: true
|
||||
|
||||
validates :supplier, presence: true
|
||||
validates :primary_taxon, presence: true
|
||||
validates :tax_category_id, presence: true, if: "Spree::Config.products_require_tax_category"
|
||||
|
||||
validates :variant_unit, presence: true
|
||||
validates :variant_unit_scale,
|
||||
presence: { if: ->(p) { %w(weight volume).include? p.variant_unit } }
|
||||
validates :variant_unit_name,
|
||||
presence: { if: ->(p) { p.variant_unit == 'items' } }
|
||||
|
||||
attr_accessor :option_values_hash
|
||||
|
||||
accepts_nested_attributes_for :product_properties,
|
||||
allow_destroy: true,
|
||||
reject_if: lambda { |pp| pp[:property_name].blank? }
|
||||
|
||||
make_permalink order: :name
|
||||
|
||||
alias :options :product_option_types
|
||||
|
||||
after_initialize :ensure_master
|
||||
after_initialize :set_available_on_to_now, if: :new_record?
|
||||
|
||||
before_validation :sanitize_permalink
|
||||
before_save :add_primary_taxon_to_taxons
|
||||
after_save :remove_previous_primary_taxon_from_taxons
|
||||
after_save :ensure_standard_variant
|
||||
after_save :update_units
|
||||
|
||||
before_destroy :punch_permalink
|
||||
|
||||
# -- Joins
|
||||
scope :with_order_cycles_outer, -> {
|
||||
joins("
|
||||
LEFT OUTER JOIN spree_variants AS o_spree_variants
|
||||
ON (o_spree_variants.product_id = spree_products.id)").
|
||||
joins("
|
||||
LEFT OUTER JOIN exchange_variants AS o_exchange_variants
|
||||
ON (o_exchange_variants.variant_id = o_spree_variants.id)").
|
||||
joins("
|
||||
LEFT OUTER JOIN exchanges AS o_exchanges
|
||||
ON (o_exchanges.id = o_exchange_variants.exchange_id)").
|
||||
joins("
|
||||
LEFT OUTER JOIN order_cycles AS o_order_cycles
|
||||
ON (o_order_cycles.id = o_exchanges.order_cycle_id)")
|
||||
}
|
||||
|
||||
scope :imported_on, lambda { |import_date|
|
||||
import_date = Time.zone.parse import_date if import_date.is_a? String
|
||||
import_date = import_date.to_date
|
||||
joins(:variants).merge(Spree::Variant.
|
||||
where(import_date: import_date.beginning_of_day..import_date.end_of_day))
|
||||
}
|
||||
|
||||
scope :with_order_cycles_inner, -> {
|
||||
joins(variants_including_master: { exchanges: :order_cycle })
|
||||
}
|
||||
|
||||
scope :visible_for, lambda { |enterprise|
|
||||
joins('
|
||||
LEFT OUTER JOIN spree_variants AS o_spree_variants
|
||||
ON (o_spree_variants.product_id = spree_products.id)').
|
||||
joins('
|
||||
LEFT OUTER JOIN inventory_items AS o_inventory_items
|
||||
ON (o_spree_variants.id = o_inventory_items.variant_id)').
|
||||
where('o_inventory_items.enterprise_id = (?) AND visible = (?)', enterprise, true)
|
||||
}
|
||||
|
||||
# -- Scopes
|
||||
scope :in_supplier, lambda { |supplier| where(supplier_id: supplier) }
|
||||
|
||||
# Products distributed via the given distributor through an OC
|
||||
scope :in_distributor, lambda { |distributor|
|
||||
distributor = distributor.respond_to?(:id) ? distributor.id : distributor.to_i
|
||||
|
||||
with_order_cycles_outer.
|
||||
where('(o_exchanges.incoming = ? AND o_exchanges.receiver_id = ?)', false, distributor).
|
||||
select('distinct spree_products.*')
|
||||
}
|
||||
|
||||
scope :in_distributors, lambda { |distributors|
|
||||
with_order_cycles_outer.
|
||||
where('(o_exchanges.incoming = ? AND o_exchanges.receiver_id IN (?))', false, distributors).
|
||||
uniq
|
||||
}
|
||||
|
||||
# Products supplied by a given enterprise or distributed via that enterprise through an OC
|
||||
scope :in_supplier_or_distributor, lambda { |enterprise|
|
||||
enterprise = enterprise.respond_to?(:id) ? enterprise.id : enterprise.to_i
|
||||
|
||||
with_order_cycles_outer.
|
||||
where("
|
||||
spree_products.supplier_id = ?
|
||||
OR (o_exchanges.incoming = ? AND o_exchanges.receiver_id = ?)
|
||||
", enterprise, false, enterprise).
|
||||
select('distinct spree_products.*')
|
||||
}
|
||||
|
||||
# Products distributed by the given order cycle
|
||||
scope :in_order_cycle, lambda { |order_cycle|
|
||||
with_order_cycles_inner.
|
||||
merge(Exchange.outgoing).
|
||||
where('order_cycles.id = ?', order_cycle)
|
||||
}
|
||||
|
||||
scope :in_an_active_order_cycle, lambda {
|
||||
with_order_cycles_inner.
|
||||
merge(OrderCycle.active).
|
||||
merge(Exchange.outgoing).
|
||||
where('order_cycles.id IS NOT NULL')
|
||||
}
|
||||
|
||||
scope :by_producer, -> { joins(:supplier).order('enterprises.name') }
|
||||
scope :by_name, -> { order('name') }
|
||||
|
||||
scope :managed_by, lambda { |user|
|
||||
if user.has_spree_role?('admin')
|
||||
where(nil)
|
||||
else
|
||||
where('supplier_id IN (?)', user.enterprises.select("enterprises.id"))
|
||||
end
|
||||
}
|
||||
|
||||
scope :stockable_by, lambda { |enterprise|
|
||||
return where('1=0') if enterprise.blank?
|
||||
|
||||
permitted_producer_ids = EnterpriseRelationship.joins(:parent).permitting(enterprise.id)
|
||||
.with_permission(:add_to_order_cycle)
|
||||
.where(enterprises: { is_primary_producer: true })
|
||||
.pluck(:parent_id)
|
||||
return where('spree_products.supplier_id IN (?)', [enterprise.id] | permitted_producer_ids)
|
||||
}
|
||||
|
||||
scope :active, lambda {
|
||||
where("spree_products.deleted_at IS NULL AND spree_products.available_on <= ?", Time.zone.now)
|
||||
}
|
||||
|
||||
def self.group_by_products_id
|
||||
group(column_names.map { |col_name| "#{table_name}.#{col_name}" })
|
||||
end
|
||||
|
||||
def to_param
|
||||
permalink.present? ? permalink : (permalink_was || name.to_s.to_url)
|
||||
end
|
||||
|
||||
# the master variant is not a member of the variants array
|
||||
def variants?
|
||||
variants.any?
|
||||
end
|
||||
|
||||
def tax_category
|
||||
if self[:tax_category_id].nil?
|
||||
TaxCategory.find_by(is_default: true)
|
||||
else
|
||||
TaxCategory.find(self[:tax_category_id])
|
||||
end
|
||||
end
|
||||
|
||||
# Ensures option_types and product_option_types exist for keys in option_values_hash
|
||||
def ensure_option_types_exist_for_values_hash
|
||||
return if option_values_hash.nil?
|
||||
|
||||
option_values_hash.keys.map(&:to_i).each do |id|
|
||||
option_type_ids << id unless option_type_ids.include?(id)
|
||||
unless product_option_types.pluck(:option_type_id).include?(id)
|
||||
product_option_types.create(option_type_id: id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# for adding products which are closely related to existing ones
|
||||
def duplicate
|
||||
duplicator = Spree::Core::ProductDuplicator.new(self)
|
||||
duplicator.duplicate
|
||||
end
|
||||
|
||||
# use deleted? rather than checking the attribute directly. this
|
||||
# allows extensions to override deleted? if they want to provide
|
||||
# their own definition.
|
||||
def deleted?
|
||||
!!deleted_at
|
||||
end
|
||||
|
||||
def available?
|
||||
!(available_on.nil? || available_on.future?)
|
||||
end
|
||||
|
||||
# split variants list into hash which shows mapping of opt value onto matching variants
|
||||
# eg categorise_variants_from_option(color) => {"red" -> [...], "blue" -> [...]}
|
||||
def categorise_variants_from_option(opt_type)
|
||||
return {} unless option_types.include?(opt_type)
|
||||
|
||||
variants.active.group_by { |v| v.option_values.detect { |o| o.option_type == opt_type } }
|
||||
end
|
||||
|
||||
def self.like_any(fields, values)
|
||||
where fields.map { |field|
|
||||
values.map { |value|
|
||||
arel_table[field].matches("%#{value}%")
|
||||
}.inject(:or)
|
||||
}.inject(:or)
|
||||
end
|
||||
|
||||
def empty_option_values?
|
||||
options.empty? || options.any? do |opt|
|
||||
opt.option_type.option_values.empty?
|
||||
end
|
||||
end
|
||||
|
||||
def property(property_name)
|
||||
return nil unless prop = properties.find_by(name: property_name)
|
||||
|
||||
product_properties.find_by(property: prop).try(:value)
|
||||
end
|
||||
|
||||
def set_property(property_name, property_value)
|
||||
ActiveRecord::Base.transaction do
|
||||
property = Property.where(name: property_name).first_or_create!(presentation: property_name)
|
||||
product_property = ProductProperty.where(product: self,
|
||||
property: property).first_or_initialize
|
||||
product_property.value = property_value
|
||||
product_property.save!
|
||||
end
|
||||
end
|
||||
|
||||
def total_on_hand
|
||||
stock_items.sum(&:count_on_hand)
|
||||
end
|
||||
|
||||
# Master variant may be deleted (i.e. when the product is deleted)
|
||||
# which would make AR's default finder return nil.
|
||||
# This is a stopgap for that little problem.
|
||||
def master
|
||||
super || variants_including_master.with_deleted.find_by(is_master: true)
|
||||
end
|
||||
|
||||
def properties_including_inherited
|
||||
# Product properties override producer properties
|
||||
ps = product_properties.all
|
||||
|
||||
if inherits_properties
|
||||
ps = OpenFoodNetwork::PropertyMerge.merge(ps, supplier.producer_properties)
|
||||
end
|
||||
|
||||
ps.
|
||||
sort_by(&:position).
|
||||
map { |pp| { id: pp.property.id, name: pp.property.presentation, value: pp.value } }
|
||||
end
|
||||
|
||||
def in_distributor?(distributor)
|
||||
self.class.in_distributor(distributor).include? self
|
||||
end
|
||||
|
||||
def in_order_cycle?(order_cycle)
|
||||
self.class.in_order_cycle(order_cycle).include? self
|
||||
end
|
||||
|
||||
def variants_distributed_by(order_cycle, distributor)
|
||||
order_cycle.variants_distributed_by(distributor).where(product_id: self)
|
||||
end
|
||||
|
||||
# Get the most recent import_date of a product's variants
|
||||
def import_date
|
||||
variants.map(&:import_date).compact.max
|
||||
end
|
||||
|
||||
def variant_unit_option_type
|
||||
return if variant_unit.blank?
|
||||
|
||||
option_type_name = "unit_#{variant_unit}"
|
||||
option_type_presentation = variant_unit.capitalize
|
||||
|
||||
Spree::OptionType.find_by(name: option_type_name) ||
|
||||
Spree::OptionType.create!(name: option_type_name,
|
||||
presentation: option_type_presentation)
|
||||
end
|
||||
|
||||
def self.all_variant_unit_option_types
|
||||
Spree::OptionType.where('name LIKE ?', 'unit_%%')
|
||||
end
|
||||
|
||||
def destroy_with_delete_from_order_cycles
|
||||
transaction do
|
||||
touch_distributors
|
||||
|
||||
ExchangeVariant.
|
||||
where('exchange_variants.variant_id IN (?)', variants_including_master.with_deleted.
|
||||
select(:id)).destroy_all
|
||||
|
||||
destroy_without_delete_from_order_cycles
|
||||
end
|
||||
end
|
||||
alias_method_chain :destroy, :delete_from_order_cycles
|
||||
|
||||
private
|
||||
|
||||
# Builds variants from a hash of option types & values
|
||||
def build_variants_from_option_values_hash
|
||||
ensure_option_types_exist_for_values_hash
|
||||
values = option_values_hash.values
|
||||
values = values.inject(values.shift) { |memo, value| memo.product(value).map(&:flatten) }
|
||||
|
||||
values.each do |ids|
|
||||
variants.create(
|
||||
option_value_ids: ids,
|
||||
price: master.price
|
||||
)
|
||||
end
|
||||
save
|
||||
end
|
||||
|
||||
# ensures the master variant is flagged as such
|
||||
def set_master_variant_defaults
|
||||
master.is_master = true
|
||||
end
|
||||
|
||||
# Here we rescue errors when saving master variants (without the need for a
|
||||
# validates_associated on master) and we get more specific data about the errors
|
||||
def save_master
|
||||
if master && (
|
||||
master.changed? || master.new_record? || (
|
||||
master.default_price && (
|
||||
master.default_price.changed? || master.default_price.new_record?
|
||||
)
|
||||
)
|
||||
)
|
||||
master.save!
|
||||
end
|
||||
|
||||
# If the master cannot be saved, the Product object will get its errors
|
||||
# and will be destroyed
|
||||
rescue ActiveRecord::RecordInvalid
|
||||
master.errors.each do |att, error|
|
||||
errors.add(att, error)
|
||||
end
|
||||
raise
|
||||
end
|
||||
|
||||
def ensure_master
|
||||
return unless new_record?
|
||||
|
||||
self.master ||= Variant.new
|
||||
end
|
||||
|
||||
def punch_permalink
|
||||
# Punch permalink with date prefix
|
||||
update_attribute :permalink, "#{Time.now.to_i}_#{permalink}"
|
||||
end
|
||||
|
||||
def set_available_on_to_now
|
||||
self.available_on ||= Time.zone.now
|
||||
end
|
||||
|
||||
def update_units
|
||||
return unless variant_unit_changed?
|
||||
|
||||
option_types.delete self.class.all_variant_unit_option_types
|
||||
option_types << variant_unit_option_type if variant_unit.present?
|
||||
variants_including_master.each(&:update_units)
|
||||
end
|
||||
|
||||
def touch_distributors
|
||||
Enterprise.distributing_products(id).each(&:touch)
|
||||
end
|
||||
|
||||
def add_primary_taxon_to_taxons
|
||||
taxons << primary_taxon unless taxons.include? primary_taxon
|
||||
end
|
||||
|
||||
def remove_previous_primary_taxon_from_taxons
|
||||
return unless primary_taxon_id_changed? && primary_taxon_id_was
|
||||
|
||||
taxons.destroy(primary_taxon_id_was)
|
||||
end
|
||||
|
||||
def ensure_standard_variant
|
||||
return unless master.valid? && variants.empty?
|
||||
|
||||
variant = master.dup
|
||||
variant.product = self
|
||||
variant.is_master = false
|
||||
variants << variant
|
||||
end
|
||||
|
||||
# Spree creates a permalink already but our implementation fixes an edge case.
|
||||
def sanitize_permalink
|
||||
return unless permalink.blank? || permalink_changed?
|
||||
|
||||
requested = permalink.presence || permalink_was.presence || name.presence || 'product'
|
||||
self.permalink = create_unique_permalink(requested.parameterize)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,265 +0,0 @@
|
||||
require 'open_food_network/permalink_generator'
|
||||
require 'open_food_network/property_merge'
|
||||
require 'concerns/product_stock'
|
||||
|
||||
Spree::Product.class_eval do
|
||||
include PermalinkGenerator
|
||||
include ProductStock
|
||||
|
||||
# We have an after_destroy callback on Spree::ProductOptionType. However, if we
|
||||
# don't specify dependent => destroy on this association, it is not called. See:
|
||||
# https://github.com/rails/rails/issues/7618
|
||||
has_many :option_types, through: :product_option_types, dependent: :destroy
|
||||
|
||||
belongs_to :supplier, class_name: 'Enterprise', touch: true
|
||||
belongs_to :primary_taxon, class_name: 'Spree::Taxon', touch: true
|
||||
|
||||
delegate_belongs_to :master, :unit_value, :unit_description
|
||||
delegate :images_attributes=, :display_as=, to: :master
|
||||
|
||||
validates :supplier, presence: true
|
||||
validates :primary_taxon, presence: true
|
||||
validates :tax_category_id, presence: true, if: "Spree::Config.products_require_tax_category"
|
||||
|
||||
validates :variant_unit, presence: true
|
||||
validates :variant_unit_scale,
|
||||
presence: { if: ->(p) { %w(weight volume).include? p.variant_unit } }
|
||||
validates :variant_unit_name,
|
||||
presence: { if: ->(p) { p.variant_unit == 'items' } }
|
||||
|
||||
after_initialize :set_available_on_to_now, if: :new_record?
|
||||
before_validation :sanitize_permalink
|
||||
before_save :add_primary_taxon_to_taxons
|
||||
after_save :remove_previous_primary_taxon_from_taxons
|
||||
after_save :ensure_standard_variant
|
||||
after_save :update_units
|
||||
|
||||
# -- Joins
|
||||
scope :with_order_cycles_outer, -> {
|
||||
joins("
|
||||
LEFT OUTER JOIN spree_variants AS o_spree_variants
|
||||
ON (o_spree_variants.product_id = spree_products.id)").
|
||||
joins("
|
||||
LEFT OUTER JOIN exchange_variants AS o_exchange_variants
|
||||
ON (o_exchange_variants.variant_id = o_spree_variants.id)").
|
||||
joins("
|
||||
LEFT OUTER JOIN exchanges AS o_exchanges
|
||||
ON (o_exchanges.id = o_exchange_variants.exchange_id)").
|
||||
joins("
|
||||
LEFT OUTER JOIN order_cycles AS o_order_cycles
|
||||
ON (o_order_cycles.id = o_exchanges.order_cycle_id)")
|
||||
}
|
||||
|
||||
scope :imported_on, lambda { |import_date|
|
||||
import_date = Time.zone.parse import_date if import_date.is_a? String
|
||||
import_date = import_date.to_date
|
||||
joins(:variants).merge(Spree::Variant.where(import_date: import_date.beginning_of_day..import_date.end_of_day))
|
||||
}
|
||||
|
||||
scope :with_order_cycles_inner, -> {
|
||||
joins(variants_including_master: { exchanges: :order_cycle })
|
||||
}
|
||||
|
||||
scope :visible_for, lambda { |enterprise|
|
||||
joins('LEFT OUTER JOIN spree_variants AS o_spree_variants ON (o_spree_variants.product_id = spree_products.id)').
|
||||
joins('LEFT OUTER JOIN inventory_items AS o_inventory_items ON (o_spree_variants.id = o_inventory_items.variant_id)').
|
||||
where('o_inventory_items.enterprise_id = (?) AND visible = (?)', enterprise, true)
|
||||
}
|
||||
|
||||
# -- Scopes
|
||||
scope :in_supplier, lambda { |supplier| where(supplier_id: supplier) }
|
||||
|
||||
# Products distributed via the given distributor through an OC
|
||||
scope :in_distributor, lambda { |distributor|
|
||||
distributor = distributor.respond_to?(:id) ? distributor.id : distributor.to_i
|
||||
|
||||
with_order_cycles_outer.
|
||||
where('(o_exchanges.incoming = ? AND o_exchanges.receiver_id = ?)', false, distributor).
|
||||
select('distinct spree_products.*')
|
||||
}
|
||||
|
||||
scope :in_distributors, lambda { |distributors|
|
||||
with_order_cycles_outer.
|
||||
where('(o_exchanges.incoming = ? AND o_exchanges.receiver_id IN (?))', false, distributors).
|
||||
uniq
|
||||
}
|
||||
|
||||
# Products supplied by a given enterprise or distributed via that enterprise through an OC
|
||||
scope :in_supplier_or_distributor, lambda { |enterprise|
|
||||
enterprise = enterprise.respond_to?(:id) ? enterprise.id : enterprise.to_i
|
||||
|
||||
with_order_cycles_outer.
|
||||
where("
|
||||
spree_products.supplier_id = ?
|
||||
OR (o_exchanges.incoming = ? AND o_exchanges.receiver_id = ?)
|
||||
", enterprise, false, enterprise).
|
||||
select('distinct spree_products.*')
|
||||
}
|
||||
|
||||
# Products distributed by the given order cycle
|
||||
scope :in_order_cycle, lambda { |order_cycle|
|
||||
with_order_cycles_inner.
|
||||
merge(Exchange.outgoing).
|
||||
where('order_cycles.id = ?', order_cycle)
|
||||
}
|
||||
|
||||
scope :in_an_active_order_cycle, lambda {
|
||||
with_order_cycles_inner.
|
||||
merge(OrderCycle.active).
|
||||
merge(Exchange.outgoing).
|
||||
where('order_cycles.id IS NOT NULL')
|
||||
}
|
||||
|
||||
scope :by_producer, -> { joins(:supplier).order('enterprises.name') }
|
||||
scope :by_name, -> { order('name') }
|
||||
|
||||
scope :managed_by, lambda { |user|
|
||||
if user.has_spree_role?('admin')
|
||||
where(nil)
|
||||
else
|
||||
where('supplier_id IN (?)', user.enterprises.select("enterprises.id"))
|
||||
end
|
||||
}
|
||||
|
||||
scope :stockable_by, lambda { |enterprise|
|
||||
return where('1=0') if enterprise.blank?
|
||||
|
||||
permitted_producer_ids = EnterpriseRelationship.joins(:parent).permitting(enterprise.id)
|
||||
.with_permission(:add_to_order_cycle).where(enterprises: { is_primary_producer: true }).pluck(:parent_id)
|
||||
return where('spree_products.supplier_id IN (?)', [enterprise.id] | permitted_producer_ids)
|
||||
}
|
||||
|
||||
# -- Methods
|
||||
|
||||
# Called by Spree::Product::duplicate before saving.
|
||||
def duplicate_extra(_parent)
|
||||
# Spree sets the SKU to "COPY OF #{parent sku}".
|
||||
master.sku = ''
|
||||
end
|
||||
|
||||
def properties_including_inherited
|
||||
# Product properties override producer properties
|
||||
ps = product_properties.all
|
||||
|
||||
if inherits_properties
|
||||
ps = OpenFoodNetwork::PropertyMerge.merge(ps, supplier.producer_properties)
|
||||
end
|
||||
|
||||
ps.
|
||||
sort_by(&:position).
|
||||
map { |pp| { id: pp.property.id, name: pp.property.presentation, value: pp.value } }
|
||||
end
|
||||
|
||||
def in_distributor?(distributor)
|
||||
self.class.in_distributor(distributor).include? self
|
||||
end
|
||||
|
||||
def in_order_cycle?(order_cycle)
|
||||
self.class.in_order_cycle(order_cycle).include? self
|
||||
end
|
||||
|
||||
def variants_distributed_by(order_cycle, distributor)
|
||||
order_cycle.variants_distributed_by(distributor).where(product_id: self)
|
||||
end
|
||||
|
||||
# Get the most recent import_date of a product's variants
|
||||
def import_date
|
||||
variants.map(&:import_date).compact.max
|
||||
end
|
||||
|
||||
def variant_unit_option_type
|
||||
if variant_unit.present?
|
||||
option_type_name = "unit_#{variant_unit}"
|
||||
option_type_presentation = variant_unit.capitalize
|
||||
|
||||
Spree::OptionType.find_by(name: option_type_name) ||
|
||||
Spree::OptionType.create!(name: option_type_name,
|
||||
presentation: option_type_presentation)
|
||||
end
|
||||
end
|
||||
|
||||
def destroy_with_delete_from_order_cycles
|
||||
transaction do
|
||||
touch_distributors
|
||||
|
||||
ExchangeVariant.
|
||||
where('exchange_variants.variant_id IN (?)', variants_including_master.with_deleted.
|
||||
select(:id)).destroy_all
|
||||
|
||||
destroy_without_delete_from_order_cycles
|
||||
end
|
||||
end
|
||||
alias_method_chain :destroy, :delete_from_order_cycles
|
||||
|
||||
private
|
||||
|
||||
def set_available_on_to_now
|
||||
self.available_on ||= Time.zone.now
|
||||
end
|
||||
|
||||
def update_units
|
||||
if variant_unit_changed?
|
||||
option_types.delete self.class.all_variant_unit_option_types
|
||||
option_types << variant_unit_option_type if variant_unit.present?
|
||||
variants_including_master.each(&:update_units)
|
||||
end
|
||||
end
|
||||
|
||||
def touch_distributors
|
||||
Enterprise.distributing_products(id).each(&:touch)
|
||||
end
|
||||
|
||||
def add_primary_taxon_to_taxons
|
||||
taxons << primary_taxon unless taxons.include? primary_taxon
|
||||
end
|
||||
|
||||
def remove_previous_primary_taxon_from_taxons
|
||||
return unless primary_taxon_id_changed? && primary_taxon_id_was
|
||||
|
||||
taxons.destroy(primary_taxon_id_was)
|
||||
end
|
||||
|
||||
def self.all_variant_unit_option_types
|
||||
Spree::OptionType.where('name LIKE ?', 'unit_%%')
|
||||
end
|
||||
|
||||
def ensure_standard_variant
|
||||
if master.valid? && variants.empty?
|
||||
variant = master.dup
|
||||
variant.product = self
|
||||
variant.is_master = false
|
||||
variants << variant
|
||||
end
|
||||
end
|
||||
|
||||
# Override Spree's old save_master method and replace it with the most recent method from spree repository
|
||||
# This fixes any problems arising from failing master saves, without the need for a validates_associated on
|
||||
# master, while giving us more specific errors as to why saving failed
|
||||
def save_master
|
||||
if master && (
|
||||
master.changed? || master.new_record? || (
|
||||
master.default_price && (
|
||||
master.default_price.changed? || master.default_price.new_record?
|
||||
)
|
||||
)
|
||||
)
|
||||
master.save!
|
||||
end
|
||||
|
||||
# If the master cannot be saved, the Product object will get its errors
|
||||
# and will be destroyed
|
||||
rescue ActiveRecord::RecordInvalid
|
||||
master.errors.each do |att, error|
|
||||
errors.add(att, error)
|
||||
end
|
||||
raise
|
||||
end
|
||||
|
||||
# Spree creates a permalink already but our implementation fixes an edge case.
|
||||
def sanitize_permalink
|
||||
if permalink.blank? || permalink_changed?
|
||||
requested = permalink.presence || permalink_was.presence || name.presence || 'product'
|
||||
self.permalink = create_unique_permalink(requested.parameterize)
|
||||
end
|
||||
end
|
||||
end
|
||||
18
app/models/spree/product_option_type.rb
Normal file
18
app/models/spree/product_option_type.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Spree
|
||||
class ProductOptionType < ActiveRecord::Base
|
||||
after_destroy :remove_option_values
|
||||
|
||||
belongs_to :product, class_name: 'Spree::Product'
|
||||
belongs_to :option_type, class_name: 'Spree::OptionType'
|
||||
acts_as_list scope: :product
|
||||
|
||||
def remove_option_values
|
||||
product.variants_including_master.each do |variant|
|
||||
option_values = variant.option_values.where(option_type_id: option_type)
|
||||
variant.option_values.destroy(*option_values)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,10 +0,0 @@
|
||||
Spree::ProductOptionType.class_eval do
|
||||
after_destroy :remove_option_values
|
||||
|
||||
def remove_option_values
|
||||
product.variants_including_master.each do |variant|
|
||||
option_values = variant.option_values.where(option_type_id: option_type)
|
||||
variant.option_values.destroy(*option_values)
|
||||
end
|
||||
end
|
||||
end
|
||||
27
app/models/spree/product_property.rb
Normal file
27
app/models/spree/product_property.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Spree
|
||||
class ProductProperty < ActiveRecord::Base
|
||||
belongs_to :product, class_name: "Spree::Product", touch: true
|
||||
belongs_to :property, class_name: 'Spree::Property'
|
||||
|
||||
validates :property, presence: true
|
||||
validates :value, length: { maximum: 255 }
|
||||
|
||||
default_scope -> { order("#{table_name}.position") }
|
||||
|
||||
# virtual attributes for use with AJAX completion stuff
|
||||
def property_name
|
||||
property&.name
|
||||
end
|
||||
|
||||
def property_name=(name)
|
||||
return if name.blank?
|
||||
|
||||
unless property = Property.find_by(name: name)
|
||||
property = Property.create(name: name, presentation: name)
|
||||
end
|
||||
self.property = property
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,5 +0,0 @@
|
||||
module Spree
|
||||
ProductProperty.class_eval do
|
||||
belongs_to :product, class_name: "Spree::Product", touch: true
|
||||
end
|
||||
end
|
||||
@@ -30,7 +30,7 @@ module Spree
|
||||
|
||||
def fetch_stock_items
|
||||
# Don't re-fetch associated stock items from the DB if we've already eager-loaded them
|
||||
return @variant.stock_items.to_a if @variant.stock_items.loaded?
|
||||
return @variant.stock_items if @variant.stock_items.loaded?
|
||||
|
||||
Spree::StockItem.joins(:stock_location).
|
||||
where(:variant_id => @variant, Spree::StockLocation.table_name => { active: true })
|
||||
|
||||
301
app/models/spree/variant.rb
Normal file
301
app/models/spree/variant.rb
Normal file
@@ -0,0 +1,301 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'open_food_network/enterprise_fee_calculator'
|
||||
require 'variant_units/variant_and_line_item_naming'
|
||||
require 'concerns/variant_stock'
|
||||
require 'spree/localized_number'
|
||||
|
||||
module Spree
|
||||
class Variant < ActiveRecord::Base
|
||||
extend Spree::LocalizedNumber
|
||||
include VariantUnits::VariantAndLineItemNaming
|
||||
include VariantStock
|
||||
|
||||
acts_as_paranoid
|
||||
|
||||
belongs_to :product, touch: true, class_name: 'Spree::Product'
|
||||
delegate_belongs_to :product, :name, :description, :permalink, :available_on,
|
||||
:tax_category_id, :shipping_category_id, :meta_description,
|
||||
:meta_keywords, :tax_category, :shipping_category
|
||||
|
||||
has_many :inventory_units
|
||||
has_many :line_items
|
||||
|
||||
has_many :stock_items, dependent: :destroy
|
||||
has_many :stock_locations, through: :stock_items
|
||||
has_many :stock_movements
|
||||
|
||||
has_and_belongs_to_many :option_values, join_table: :spree_option_values_variants
|
||||
|
||||
has_many :images, -> { order(:position) }, as: :viewable,
|
||||
dependent: :destroy,
|
||||
class_name: "Spree::Image"
|
||||
accepts_nested_attributes_for :images
|
||||
|
||||
has_one :default_price,
|
||||
-> { where currency: Spree::Config[:currency] },
|
||||
class_name: 'Spree::Price',
|
||||
dependent: :destroy
|
||||
has_many :prices,
|
||||
class_name: 'Spree::Price',
|
||||
dependent: :destroy
|
||||
delegate_belongs_to :default_price, :display_price, :display_amount,
|
||||
:price, :price=, :currency
|
||||
|
||||
has_many :exchange_variants
|
||||
has_many :exchanges, through: :exchange_variants
|
||||
has_many :variant_overrides
|
||||
has_many :inventory_items
|
||||
|
||||
localize_number :price, :cost_price, :weight
|
||||
|
||||
validate :check_price
|
||||
validates :price, numericality: { greater_than_or_equal_to: 0 },
|
||||
presence: true,
|
||||
if: proc { Spree::Config[:require_master_price] }
|
||||
validates :cost_price, numericality: { greater_than_or_equal_to: 0, allow_nil: true }
|
||||
|
||||
validates :unit_value, presence: true, if: ->(variant) {
|
||||
%w(weight volume).include?(variant.product.andand.variant_unit)
|
||||
}
|
||||
|
||||
validates :unit_description, presence: true, if: ->(variant) {
|
||||
variant.product.andand.variant_unit.present? && variant.unit_value.nil?
|
||||
}
|
||||
|
||||
before_validation :set_cost_currency
|
||||
before_validation :update_weight_from_unit_value, if: ->(v) { v.product.present? }
|
||||
|
||||
after_save :save_default_price
|
||||
after_save :update_units
|
||||
|
||||
after_create :create_stock_items
|
||||
after_create :set_position
|
||||
|
||||
around_destroy :destruction
|
||||
|
||||
# default variant scope only lists non-deleted variants
|
||||
scope :deleted, lambda { where('deleted_at IS NOT NULL') }
|
||||
|
||||
scope :with_order_cycles_inner, -> { joins(exchanges: :order_cycle) }
|
||||
|
||||
scope :not_master, -> { where(is_master: false) }
|
||||
scope :in_order_cycle, lambda { |order_cycle|
|
||||
with_order_cycles_inner.
|
||||
merge(Exchange.outgoing).
|
||||
where('order_cycles.id = ?', order_cycle).
|
||||
select('DISTINCT spree_variants.*')
|
||||
}
|
||||
|
||||
scope :in_schedule, lambda { |schedule|
|
||||
joins(exchanges: { order_cycle: :schedules }).
|
||||
merge(Exchange.outgoing).
|
||||
where(schedules: { id: schedule }).
|
||||
select('DISTINCT spree_variants.*')
|
||||
}
|
||||
|
||||
scope :for_distribution, lambda { |order_cycle, distributor|
|
||||
where('spree_variants.id IN (?)', order_cycle.variants_distributed_by(distributor).
|
||||
select(&:id))
|
||||
}
|
||||
|
||||
scope :visible_for, lambda { |enterprise|
|
||||
joins(:inventory_items).
|
||||
where(
|
||||
'inventory_items.enterprise_id = (?) AND inventory_items.visible = (?)',
|
||||
enterprise,
|
||||
true
|
||||
)
|
||||
}
|
||||
|
||||
scope :not_hidden_for, lambda { |enterprise|
|
||||
return where("1=0") if enterprise.blank?
|
||||
|
||||
joins("
|
||||
LEFT OUTER JOIN (SELECT *
|
||||
FROM inventory_items
|
||||
WHERE enterprise_id = #{sanitize enterprise.andand.id})
|
||||
AS o_inventory_items
|
||||
ON o_inventory_items.variant_id = spree_variants.id")
|
||||
.where("o_inventory_items.id IS NULL OR o_inventory_items.visible = (?)", true)
|
||||
}
|
||||
|
||||
scope :stockable_by, lambda { |enterprise|
|
||||
return where("1=0") if enterprise.blank?
|
||||
|
||||
joins(:product).
|
||||
where(spree_products: { id: Spree::Product.stockable_by(enterprise).pluck(:id) })
|
||||
}
|
||||
|
||||
# Define sope as class method to allow chaining with other scopes filtering id.
|
||||
# In Rails 3, merging two scopes on the same column will consider only the last scope.
|
||||
def self.in_distributor(distributor)
|
||||
where(id: ExchangeVariant.select(:variant_id).
|
||||
joins(:exchange).
|
||||
where('exchanges.incoming = ? AND exchanges.receiver_id = ?', false, distributor))
|
||||
end
|
||||
|
||||
def self.indexed
|
||||
scoped.index_by(&:id)
|
||||
end
|
||||
|
||||
def self.active(currency = nil)
|
||||
# "where(id:" is necessary so that the returned relation has no includes
|
||||
# The relation without includes will not be readonly and allow updates on it
|
||||
where("spree_variants.id in (?)", joins(:prices).
|
||||
where(deleted_at: nil).
|
||||
where('spree_prices.currency' =>
|
||||
currency || Spree::Config[:currency]).
|
||||
where('spree_prices.amount IS NOT NULL').
|
||||
select("spree_variants.id"))
|
||||
end
|
||||
|
||||
# Allow variant to access associated soft-deleted prices.
|
||||
def default_price
|
||||
Spree::Price.unscoped { super }
|
||||
end
|
||||
|
||||
def price_with_fees(distributor, order_cycle)
|
||||
price + fees_for(distributor, order_cycle)
|
||||
end
|
||||
|
||||
def fees_for(distributor, order_cycle)
|
||||
OpenFoodNetwork::EnterpriseFeeCalculator.new(distributor, order_cycle).fees_for self
|
||||
end
|
||||
|
||||
def fees_by_type_for(distributor, order_cycle)
|
||||
OpenFoodNetwork::EnterpriseFeeCalculator.new(distributor, order_cycle).fees_by_type_for self
|
||||
end
|
||||
|
||||
# returns number of units currently on backorder for this variant.
|
||||
def on_backorder
|
||||
inventory_units.with_state('backordered').size
|
||||
end
|
||||
|
||||
def gross_profit
|
||||
cost_price.nil? ? 0 : (price - cost_price)
|
||||
end
|
||||
|
||||
# use deleted? rather than checking the attribute directly. this
|
||||
# allows extensions to override deleted? if they want to provide
|
||||
# their own definition.
|
||||
def deleted?
|
||||
deleted_at
|
||||
end
|
||||
|
||||
def set_option_value(opt_name, opt_value)
|
||||
# no option values on master
|
||||
return if is_master
|
||||
|
||||
option_type = Spree::OptionType.where(name: opt_name).first_or_initialize do |o|
|
||||
o.presentation = opt_name
|
||||
o.save!
|
||||
end
|
||||
|
||||
current_value = option_values.detect { |o| o.option_type.name == opt_name }
|
||||
|
||||
if current_value.nil?
|
||||
# then we have to check to make sure that the product has the option type
|
||||
unless product.option_types.include? option_type
|
||||
product.option_types << option_type
|
||||
product.save
|
||||
end
|
||||
else
|
||||
return if current_value.name == opt_value
|
||||
|
||||
option_values.delete(current_value)
|
||||
end
|
||||
|
||||
option_value = Spree::OptionValue.where(option_type_id: option_type.id,
|
||||
name: opt_value).first_or_initialize do |o|
|
||||
o.presentation = opt_value
|
||||
o.save!
|
||||
end
|
||||
|
||||
option_values << option_value
|
||||
save
|
||||
end
|
||||
|
||||
def option_value(opt_name)
|
||||
option_values.detect { |o| o.option_type.name == opt_name }.try(:presentation)
|
||||
end
|
||||
|
||||
def default_price?
|
||||
!default_price.nil?
|
||||
end
|
||||
|
||||
def price_in(currency)
|
||||
prices.select{ |price| price.currency == currency }.first ||
|
||||
Spree::Price.new(variant_id: id, currency: currency)
|
||||
end
|
||||
|
||||
def amount_in(currency)
|
||||
price_in(currency).try(:amount)
|
||||
end
|
||||
|
||||
def name_and_sku
|
||||
"#{name} - #{sku}"
|
||||
end
|
||||
|
||||
# Product may be created with deleted_at already set,
|
||||
# which would make AR's default finder return nil.
|
||||
# This is a stopgap for that little problem.
|
||||
def product
|
||||
Spree::Product.unscoped { super }
|
||||
end
|
||||
|
||||
# can_supply? is implemented in VariantStock
|
||||
def in_stock?(quantity = 1)
|
||||
can_supply?(quantity)
|
||||
end
|
||||
|
||||
def total_on_hand
|
||||
Spree::Stock::Quantifier.new(self).total_on_hand
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Ensures a new variant takes the product master price when price is not supplied
|
||||
def check_price
|
||||
if price.nil? && Spree::Config[:require_master_price]
|
||||
raise 'No master variant found to infer price' unless product&.master
|
||||
raise 'Must supply price for variant or master.price for product.' if self == product.master
|
||||
|
||||
self.price = product.master.price
|
||||
end
|
||||
|
||||
return unless currency.nil?
|
||||
|
||||
self.currency = Spree::Config[:currency]
|
||||
end
|
||||
|
||||
def save_default_price
|
||||
default_price.save if default_price && (default_price.changed? || default_price.new_record?)
|
||||
end
|
||||
|
||||
def set_cost_currency
|
||||
self.cost_currency = Spree::Config[:currency] if cost_currency.blank?
|
||||
end
|
||||
|
||||
def create_stock_items
|
||||
StockLocation.all.find_each do |stock_location|
|
||||
stock_location.propagate_variant(self)
|
||||
end
|
||||
end
|
||||
|
||||
def set_position
|
||||
update_column(:position, product.variants.maximum(:position).to_i + 1)
|
||||
end
|
||||
|
||||
def update_weight_from_unit_value
|
||||
return unless product.variant_unit == 'weight' && unit_value.present?
|
||||
|
||||
self.weight = weight_from_unit_value
|
||||
end
|
||||
|
||||
def destruction
|
||||
exchange_variants(:reload).destroy_all
|
||||
yield
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,141 +0,0 @@
|
||||
require 'open_food_network/enterprise_fee_calculator'
|
||||
require 'variant_units/variant_and_line_item_naming'
|
||||
require 'concerns/variant_stock'
|
||||
|
||||
Spree::Variant.class_eval do
|
||||
extend Spree::LocalizedNumber
|
||||
# Remove method From Spree, so method from the naming module is used instead
|
||||
# This file may be double-loaded in delayed job environment, so we check before
|
||||
# removing the Spree method to prevent error.
|
||||
remove_method :options_text if instance_methods(false).include? :options_text
|
||||
include VariantUnits::VariantAndLineItemNaming
|
||||
include VariantStock
|
||||
|
||||
has_many :exchange_variants
|
||||
has_many :exchanges, through: :exchange_variants
|
||||
has_many :variant_overrides
|
||||
has_many :inventory_items
|
||||
|
||||
accepts_nested_attributes_for :images
|
||||
|
||||
validates :unit_value, presence: true, if: ->(variant) {
|
||||
%w(weight volume).include?(variant.product.andand.variant_unit)
|
||||
}
|
||||
|
||||
validates :unit_description, presence: true, if: ->(variant) {
|
||||
variant.product.andand.variant_unit.present? && variant.unit_value.nil?
|
||||
}
|
||||
|
||||
before_validation :update_weight_from_unit_value, if: ->(v) { v.product.present? }
|
||||
after_save :update_units
|
||||
around_destroy :destruction
|
||||
|
||||
scope :with_order_cycles_inner, -> { joins(exchanges: :order_cycle) }
|
||||
|
||||
scope :not_master, -> { where(is_master: false) }
|
||||
scope :in_order_cycle, lambda { |order_cycle|
|
||||
with_order_cycles_inner.
|
||||
merge(Exchange.outgoing).
|
||||
where('order_cycles.id = ?', order_cycle).
|
||||
select('DISTINCT spree_variants.*')
|
||||
}
|
||||
|
||||
scope :in_schedule, lambda { |schedule|
|
||||
joins(exchanges: { order_cycle: :schedules }).
|
||||
merge(Exchange.outgoing).
|
||||
where(schedules: { id: schedule }).
|
||||
select('DISTINCT spree_variants.*')
|
||||
}
|
||||
|
||||
scope :for_distribution, lambda { |order_cycle, distributor|
|
||||
where('spree_variants.id IN (?)', order_cycle.variants_distributed_by(distributor).select(&:id))
|
||||
}
|
||||
|
||||
scope :visible_for, lambda { |enterprise|
|
||||
joins(:inventory_items).
|
||||
where(
|
||||
'inventory_items.enterprise_id = (?) AND inventory_items.visible = (?)',
|
||||
enterprise,
|
||||
true
|
||||
)
|
||||
}
|
||||
|
||||
scope :not_hidden_for, lambda { |enterprise|
|
||||
return where("1=0") if enterprise.blank?
|
||||
|
||||
joins("
|
||||
LEFT OUTER JOIN (SELECT *
|
||||
FROM inventory_items
|
||||
WHERE enterprise_id = #{sanitize enterprise.andand.id})
|
||||
AS o_inventory_items
|
||||
ON o_inventory_items.variant_id = spree_variants.id")
|
||||
.where("o_inventory_items.id IS NULL OR o_inventory_items.visible = (?)", true)
|
||||
}
|
||||
|
||||
localize_number :price, :cost_price, :weight
|
||||
|
||||
scope :stockable_by, lambda { |enterprise|
|
||||
return where("1=0") if enterprise.blank?
|
||||
|
||||
joins(:product).
|
||||
where(spree_products: { id: Spree::Product.stockable_by(enterprise).pluck(:id) })
|
||||
}
|
||||
|
||||
# Define sope as class method to allow chaining with other scopes filtering id.
|
||||
# In Rails 3, merging two scopes on the same column will consider only the last scope.
|
||||
def self.in_distributor(distributor)
|
||||
where(id: ExchangeVariant.select(:variant_id).
|
||||
joins(:exchange).
|
||||
where('exchanges.incoming = ? AND exchanges.receiver_id = ?', false, distributor))
|
||||
end
|
||||
|
||||
def self.indexed
|
||||
scoped.index_by(&:id)
|
||||
end
|
||||
|
||||
def self.active(currency = nil)
|
||||
# "where(id:" is necessary so that the returned relation has no includes
|
||||
# The relation without includes will not be readonly and allow updates on it
|
||||
where("spree_variants.id in (?)", joins(:prices).
|
||||
where(deleted_at: nil).
|
||||
where('spree_prices.currency' =>
|
||||
currency || Spree::Config[:currency]).
|
||||
where('spree_prices.amount IS NOT NULL').
|
||||
select("spree_variants.id"))
|
||||
end
|
||||
|
||||
# We override in_stock? to avoid depending
|
||||
# on the non-overridable method Spree::Stock::Quantifier.can_supply?
|
||||
# VariantStock implements can_supply? itself which depends on overridable methods
|
||||
def in_stock?(quantity = 1)
|
||||
can_supply?(quantity)
|
||||
end
|
||||
|
||||
# Allow variant to access associated soft-deleted prices.
|
||||
def default_price
|
||||
Spree::Price.unscoped { super }
|
||||
end
|
||||
|
||||
def price_with_fees(distributor, order_cycle)
|
||||
price + fees_for(distributor, order_cycle)
|
||||
end
|
||||
|
||||
def fees_for(distributor, order_cycle)
|
||||
OpenFoodNetwork::EnterpriseFeeCalculator.new(distributor, order_cycle).fees_for self
|
||||
end
|
||||
|
||||
def fees_by_type_for(distributor, order_cycle)
|
||||
OpenFoodNetwork::EnterpriseFeeCalculator.new(distributor, order_cycle).fees_by_type_for self
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update_weight_from_unit_value
|
||||
self.weight = weight_from_unit_value if product.variant_unit == 'weight' && unit_value.present?
|
||||
end
|
||||
|
||||
def destruction
|
||||
exchange_variants(:reload).destroy_all
|
||||
yield
|
||||
end
|
||||
end
|
||||
@@ -1,3 +1,9 @@
|
||||
class Api::Admin::BasicEnterpriseFeeSerializer < ActiveModel::Serializer
|
||||
attributes :id, :enterprise_id
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module Admin
|
||||
class BasicEnterpriseFeeSerializer < ActiveModel::Serializer
|
||||
attributes :id, :enterprise_id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
class Api::Admin::BasicEnterpriseSerializer < ActiveModel::Serializer
|
||||
attributes :name, :id, :is_primary_producer, :is_distributor, :sells, :category,
|
||||
:payment_method_ids, :shipping_method_ids, :producer_profile_only, :permalink
|
||||
# frozen_string_literal: true
|
||||
|
||||
def payment_method_ids
|
||||
object.payment_methods.map(&:id)
|
||||
end
|
||||
module Api
|
||||
module Admin
|
||||
class BasicEnterpriseSerializer < ActiveModel::Serializer
|
||||
attributes :name, :id, :is_primary_producer, :is_distributor, :sells, :category,
|
||||
:payment_method_ids, :shipping_method_ids, :producer_profile_only, :permalink
|
||||
|
||||
def shipping_method_ids
|
||||
object.shipping_methods.map(&:id)
|
||||
def payment_method_ids
|
||||
object.payment_methods.map(&:id)
|
||||
end
|
||||
|
||||
def shipping_method_ids
|
||||
object.shipping_methods.map(&:id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,20 +1,26 @@
|
||||
class Api::Admin::BasicOrderCycleSerializer < ActiveModel::Serializer
|
||||
include OrderCyclesHelper
|
||||
# frozen_string_literal: true
|
||||
|
||||
attributes :id, :name, :status, :orders_open_at, :orders_close_at
|
||||
module Api
|
||||
module Admin
|
||||
class BasicOrderCycleSerializer < ActiveModel::Serializer
|
||||
include OrderCyclesHelper
|
||||
|
||||
has_many :suppliers, serializer: Api::Admin::IdNameSerializer
|
||||
has_many :distributors, serializer: Api::Admin::IdNameSerializer
|
||||
attributes :id, :name, :status, :orders_open_at, :orders_close_at
|
||||
|
||||
def status
|
||||
order_cycle_status_class object
|
||||
end
|
||||
has_many :suppliers, serializer: Api::Admin::IdNameSerializer
|
||||
has_many :distributors, serializer: Api::Admin::IdNameSerializer
|
||||
|
||||
def orders_open_at
|
||||
object.orders_open_at.andand.strftime("%F %T %z")
|
||||
end
|
||||
def status
|
||||
order_cycle_status_class object
|
||||
end
|
||||
|
||||
def orders_close_at
|
||||
object.orders_close_at.andand.strftime("%F %T %z")
|
||||
def orders_open_at
|
||||
object.orders_open_at.andand.strftime("%F %T %z")
|
||||
end
|
||||
|
||||
def orders_close_at
|
||||
object.orders_close_at.andand.strftime("%F %T %z")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
class Api::Admin::Calculator::FlatPercentItemTotalSerializer < ActiveModel::Serializer
|
||||
attributes :id, :preferred_flat_percent
|
||||
# frozen_string_literal: true
|
||||
|
||||
def preferred_flat_percent
|
||||
object.preferred_flat_percent.to_i
|
||||
module Api
|
||||
module Admin
|
||||
module Calculator
|
||||
class FlatPercentItemTotalSerializer < ActiveModel::Serializer
|
||||
attributes :id, :preferred_flat_percent
|
||||
|
||||
def preferred_flat_percent
|
||||
object.preferred_flat_percent.to_i
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
class Api::Admin::CalculatorSerializer < ActiveModel::Serializer
|
||||
attributes :name, :description
|
||||
# frozen_string_literal: true
|
||||
|
||||
delegate :name, to: :object
|
||||
module Api
|
||||
module Admin
|
||||
class CalculatorSerializer < ActiveModel::Serializer
|
||||
attributes :name, :description
|
||||
|
||||
delegate :description, to: :object
|
||||
delegate :name, to: :object
|
||||
|
||||
delegate :description, to: :object
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
class Api::Admin::ColumnPreferenceSerializer < ActiveModel::Serializer
|
||||
attributes :id, :user_id, :action_name, :column_name, :name, :visible
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module Admin
|
||||
class ColumnPreferenceSerializer < ActiveModel::Serializer
|
||||
attributes :id, :user_id, :action_name, :column_name, :name, :visible
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,36 +1,61 @@
|
||||
class Api::Admin::CustomerSerializer < ActiveModel::Serializer
|
||||
attributes :id, :email, :enterprise_id, :user_id, :code, :tags, :tag_list, :name,
|
||||
:allow_charges, :default_card_present?
|
||||
# frozen_string_literal: true
|
||||
|
||||
has_one :ship_address, serializer: Api::AddressSerializer
|
||||
has_one :bill_address, serializer: Api::AddressSerializer
|
||||
module Api
|
||||
module Admin
|
||||
class CustomerSerializer < ActiveModel::Serializer
|
||||
attributes :id, :email, :enterprise_id, :user_id, :code, :tags, :tag_list, :name,
|
||||
:allow_charges, :default_card_present?, :balance, :balance_status
|
||||
|
||||
def tag_list
|
||||
customer_tag_list.join(",")
|
||||
end
|
||||
has_one :ship_address, serializer: Api::AddressSerializer
|
||||
has_one :bill_address, serializer: Api::AddressSerializer
|
||||
|
||||
def name
|
||||
object.name.presence || object.bill_address.andand.full_name
|
||||
end
|
||||
def name
|
||||
object.name.presence || object.bill_address.andand.full_name
|
||||
end
|
||||
|
||||
def tags
|
||||
customer_tag_list.map do |tag|
|
||||
tag_rule_map = options[:tag_rule_mapping].andand[tag]
|
||||
tag_rule_map || { text: tag, rules: nil }
|
||||
def tag_list
|
||||
customer_tag_list.join(",")
|
||||
end
|
||||
|
||||
def balance
|
||||
Spree::Money.new(balance_value, currency: Spree::Config[:currency]).to_s
|
||||
end
|
||||
|
||||
def balance_status
|
||||
if balance_value.positive?
|
||||
"credit_owed"
|
||||
elsif balance_value.negative?
|
||||
"balance_due"
|
||||
else
|
||||
""
|
||||
end
|
||||
end
|
||||
|
||||
def tags
|
||||
customer_tag_list.map do |tag|
|
||||
tag_rule_map = options[:tag_rule_mapping].andand[tag]
|
||||
tag_rule_map || { text: tag, rules: nil }
|
||||
end
|
||||
end
|
||||
|
||||
def default_card_present?
|
||||
return unless object.user
|
||||
|
||||
object.user.default_card.present?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def customer_tag_list
|
||||
return object.tag_list unless options[:customer_tags]
|
||||
|
||||
options[:customer_tags].andand[object.id] || []
|
||||
end
|
||||
|
||||
def balance_value
|
||||
@balance_value ||=
|
||||
OpenFoodNetwork::UserBalanceCalculator.new(object.email, object.enterprise).balance
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def default_card_present?
|
||||
return unless object.user
|
||||
|
||||
object.user.default_card.present?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def customer_tag_list
|
||||
return object.tag_list unless options[:customer_tags]
|
||||
|
||||
options[:customer_tags].andand[object.id] || []
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,26 +1,32 @@
|
||||
class Api::Admin::EnterpriseFeeSerializer < ActiveModel::Serializer
|
||||
attributes :id, :enterprise_id, :fee_type, :name, :tax_category_id, :inherits_tax_category,
|
||||
:calculator_type, :enterprise_name, :calculator_description, :calculator_settings
|
||||
# frozen_string_literal: true
|
||||
|
||||
def enterprise_name
|
||||
object.enterprise.andand.name
|
||||
end
|
||||
module Api
|
||||
module Admin
|
||||
class EnterpriseFeeSerializer < ActiveModel::Serializer
|
||||
attributes :id, :enterprise_id, :fee_type, :name, :tax_category_id, :inherits_tax_category,
|
||||
:calculator_type, :enterprise_name, :calculator_description, :calculator_settings
|
||||
|
||||
def calculator_description
|
||||
object.calculator.andand.description
|
||||
end
|
||||
def enterprise_name
|
||||
object.enterprise.andand.name
|
||||
end
|
||||
|
||||
def calculator_settings
|
||||
return nil unless options[:include_calculators]
|
||||
def calculator_description
|
||||
object.calculator.andand.description
|
||||
end
|
||||
|
||||
result = nil
|
||||
def calculator_settings
|
||||
return nil unless options[:include_calculators]
|
||||
|
||||
options[:controller].__send__(:with_format, :html) do
|
||||
result = options[:controller].
|
||||
render_to_string(partial: 'admin/enterprise_fees/calculator_settings',
|
||||
locals: { enterprise_fee: object })
|
||||
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 })
|
||||
end
|
||||
|
||||
result.gsub('[0]', '[{{ $index }}]').gsub('_0_', '_{{ $index }}_')
|
||||
end
|
||||
end
|
||||
|
||||
result.gsub('[0]', '[{{ $index }}]').gsub('_0_', '_{{ $index }}_')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
class Api::Admin::EnterpriseRelationshipPermissionSerializer < ActiveModel::Serializer
|
||||
attributes :id, :name
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module Admin
|
||||
class EnterpriseRelationshipPermissionSerializer < ActiveModel::Serializer
|
||||
attributes :id, :name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
class Api::Admin::EnterpriseRelationshipSerializer < ActiveModel::Serializer
|
||||
attributes :id, :parent_id, :parent_name, :child_id, :child_name
|
||||
# frozen_string_literal: true
|
||||
|
||||
has_many :permissions
|
||||
module Api
|
||||
module Admin
|
||||
class EnterpriseRelationshipSerializer < ActiveModel::Serializer
|
||||
attributes :id, :parent_id, :parent_name, :child_id, :child_name
|
||||
|
||||
def parent_name
|
||||
object.parent.name
|
||||
end
|
||||
has_many :permissions
|
||||
|
||||
def child_name
|
||||
object.child.name
|
||||
def parent_name
|
||||
object.parent.name
|
||||
end
|
||||
|
||||
def child_name
|
||||
object.child.name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
class Api::Admin::EnterpriseRoleSerializer < ActiveModel::Serializer
|
||||
attributes :id, :user_id, :enterprise_id, :user_email, :enterprise_name
|
||||
# frozen_string_literal: true
|
||||
|
||||
def user_email
|
||||
object.user.email
|
||||
end
|
||||
module Api
|
||||
module Admin
|
||||
class EnterpriseRoleSerializer < ActiveModel::Serializer
|
||||
attributes :id, :user_id, :enterprise_id, :user_email, :enterprise_name
|
||||
|
||||
def enterprise_name
|
||||
object.enterprise.name
|
||||
def user_email
|
||||
object.user.email
|
||||
end
|
||||
|
||||
def enterprise_name
|
||||
object.enterprise.name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,77 +1,92 @@
|
||||
class Api::Admin::EnterpriseSerializer < ActiveModel::Serializer
|
||||
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,
|
||||
:preferred_show_customer_names_to_suppliers, :owner, :contact, :users, :tag_groups,
|
||||
:default_tag_group, :require_login, :allow_guest_orders, :allow_order_changes,
|
||||
:logo, :promo_image, :terms_and_conditions, :terms_and_conditions_file_name
|
||||
# frozen_string_literal: true
|
||||
|
||||
has_one :owner, serializer: Api::Admin::UserSerializer
|
||||
has_many :users, serializer: Api::Admin::UserSerializer
|
||||
has_one :address, serializer: Api::AddressSerializer
|
||||
module Api
|
||||
module Admin
|
||||
class EnterpriseSerializer < ActiveModel::Serializer
|
||||
attributes :name, :id, :is_primary_producer, :is_distributor, :sells, :category, :permalink,
|
||||
:payment_method_ids, :shipping_method_ids, :producer_profile_only,
|
||||
:long_description, :preferred_product_selection_from_inventory_only,
|
||||
:preferred_shopfront_message, :preferred_shopfront_closed_message,
|
||||
:preferred_shopfront_taxon_order, :preferred_shopfront_order_cycle_order,
|
||||
:preferred_show_customer_names_to_suppliers, :owner, :contact, :users, :tag_groups,
|
||||
:default_tag_group, :require_login, :allow_guest_orders, :allow_order_changes,
|
||||
:logo, :promo_image, :terms_and_conditions,
|
||||
:terms_and_conditions_file_name, :terms_and_conditions_updated_at
|
||||
|
||||
def logo
|
||||
attachment_urls(object.logo, [:thumb, :small, :medium])
|
||||
end
|
||||
has_one :owner, serializer: Api::Admin::UserSerializer
|
||||
has_many :users, serializer: Api::Admin::UserSerializer
|
||||
has_one :address, serializer: Api::AddressSerializer
|
||||
|
||||
def promo_image
|
||||
attachment_urls(object.promo_image, [:thumb, :medium, :large])
|
||||
end
|
||||
|
||||
def terms_and_conditions
|
||||
return unless @object.terms_and_conditions.file?
|
||||
|
||||
@object.terms_and_conditions.url
|
||||
end
|
||||
|
||||
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 } })
|
||||
if tag_group[:rules].blank?
|
||||
tag_groups << tag_group
|
||||
tag_group[:position] = tag_groups.count
|
||||
def logo
|
||||
attachment_urls(object.logo, [:thumb, :small, :medium])
|
||||
end
|
||||
tag_group[:rules] << Api::Admin::TagRuleSerializer.new(tag_rule).serializable_hash
|
||||
end
|
||||
end
|
||||
|
||||
def default_tag_group
|
||||
default_rules = object.tag_rules.select(&:is_default)
|
||||
serialized_rules =
|
||||
ActiveModel::ArraySerializer.new(default_rules,
|
||||
each_serializer: Api::Admin::TagRuleSerializer)
|
||||
{ tags: [], rules: serialized_rules }
|
||||
end
|
||||
def promo_image
|
||||
attachment_urls(object.promo_image, [:thumb, :medium, :large])
|
||||
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]
|
||||
end
|
||||
{ tags: tags, rules: [] }
|
||||
end
|
||||
def terms_and_conditions
|
||||
return unless object.terms_and_conditions.file?
|
||||
|
||||
private
|
||||
object.terms_and_conditions.url
|
||||
end
|
||||
|
||||
# Returns a hash of URLs for specified versions of an attachment.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# attachment_urls(object.logo, [:thumb, :small, :medium])
|
||||
# # {
|
||||
# # thumb: LOGO_THUMB_URL,
|
||||
# # small: LOGO_SMALL_URL,
|
||||
# # medium: LOGO_MEDIUM_URL
|
||||
# # }
|
||||
def attachment_urls(attachment, versions)
|
||||
return unless attachment.file?
|
||||
def terms_and_conditions_updated_at
|
||||
object.terms_and_conditions_updated_at&.to_s
|
||||
end
|
||||
|
||||
versions.each_with_object({}) do |version, urls|
|
||||
urls[version] = attachment.url(version)
|
||||
def tag_groups
|
||||
prioritized_tag_rules.each_with_object([]) do |tag_rule, tag_groups|
|
||||
tag_group = find_match(tag_groups, tag_rule.preferred_customer_tags.
|
||||
split(",").
|
||||
map{ |t| { text: t } })
|
||||
if tag_group[:rules].blank?
|
||||
tag_groups << tag_group
|
||||
tag_group[:position] = tag_groups.count
|
||||
end
|
||||
tag_group[:rules] << Api::Admin::TagRuleSerializer.new(tag_rule).serializable_hash
|
||||
end
|
||||
end
|
||||
|
||||
def default_tag_group
|
||||
default_rules = object.tag_rules.select(&:is_default)
|
||||
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]
|
||||
end
|
||||
{ tags: tags, rules: [] }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def prioritized_tag_rules
|
||||
object.tag_rules.prioritised.reject(&:is_default)
|
||||
end
|
||||
|
||||
# Returns a hash of URLs for specified versions of an attachment.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# attachment_urls(object.logo, [:thumb, :small, :medium])
|
||||
# # {
|
||||
# # thumb: LOGO_THUMB_URL,
|
||||
# # small: LOGO_SMALL_URL,
|
||||
# # medium: LOGO_MEDIUM_URL
|
||||
# # }
|
||||
def attachment_urls(attachment, versions)
|
||||
return unless attachment.file?
|
||||
|
||||
versions.each_with_object({}) do |version, urls|
|
||||
urls[version] = attachment.url(version)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,48 +1,54 @@
|
||||
class Api::Admin::ExchangeSerializer < ActiveModel::Serializer
|
||||
attributes :id, :sender_id, :receiver_id, :incoming, :variants,
|
||||
:receival_instructions, :pickup_time, :pickup_instructions,
|
||||
:tags, :tag_list
|
||||
# frozen_string_literal: true
|
||||
|
||||
has_many :enterprise_fees, serializer: Api::Admin::BasicEnterpriseFeeSerializer
|
||||
module Api
|
||||
module Admin
|
||||
class ExchangeSerializer < ActiveModel::Serializer
|
||||
attributes :id, :sender_id, :receiver_id, :incoming, :variants,
|
||||
:receival_instructions, :pickup_time, :pickup_instructions,
|
||||
:tags, :tag_list
|
||||
|
||||
def variants
|
||||
variants = object.incoming? ? visible_incoming_variants : visible_outgoing_variants
|
||||
Hash[object.variants.merge(variants).map { |v| [v.id, true] }]
|
||||
end
|
||||
has_many :enterprise_fees, serializer: Api::Admin::BasicEnterpriseFeeSerializer
|
||||
|
||||
private
|
||||
def variants
|
||||
variants = object.incoming? ? visible_incoming_variants : visible_outgoing_variants
|
||||
Hash[object.variants.merge(variants).map { |v| [v.id, true] }]
|
||||
end
|
||||
|
||||
def visible_incoming_variants
|
||||
if object.order_cycle.prefers_product_selection_from_coordinator_inventory_only?
|
||||
permitted_incoming_variants.visible_for(object.order_cycle.coordinator)
|
||||
else
|
||||
permitted_incoming_variants
|
||||
private
|
||||
|
||||
def visible_incoming_variants
|
||||
if object.order_cycle.prefers_product_selection_from_coordinator_inventory_only?
|
||||
permitted_incoming_variants.visible_for(object.order_cycle.coordinator)
|
||||
else
|
||||
permitted_incoming_variants
|
||||
end
|
||||
end
|
||||
|
||||
def visible_outgoing_variants
|
||||
if object.receiver.prefers_product_selection_from_inventory_only?
|
||||
permitted_outgoing_variants.visible_for(object.receiver)
|
||||
else
|
||||
permitted_outgoing_variants.not_hidden_for(object.receiver)
|
||||
end
|
||||
end
|
||||
|
||||
def permitted_incoming_variants
|
||||
OpenFoodNetwork::OrderCyclePermissions.new(options[:current_user], object.order_cycle).
|
||||
visible_variants_for_incoming_exchanges_from(object.sender)
|
||||
end
|
||||
|
||||
def permitted_outgoing_variants
|
||||
OpenFoodNetwork::OrderCyclePermissions.new(options[:current_user], object.order_cycle)
|
||||
.visible_variants_for_outgoing_exchanges_to(object.receiver)
|
||||
end
|
||||
|
||||
def tag_list
|
||||
object.tag_list.join(",")
|
||||
end
|
||||
|
||||
def tags
|
||||
object.tag_list.map{ |t| { text: t } }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def visible_outgoing_variants
|
||||
if object.receiver.prefers_product_selection_from_inventory_only?
|
||||
permitted_outgoing_variants.visible_for(object.receiver)
|
||||
else
|
||||
permitted_outgoing_variants.not_hidden_for(object.receiver)
|
||||
end
|
||||
end
|
||||
|
||||
def permitted_incoming_variants
|
||||
OpenFoodNetwork::OrderCyclePermissions.new(options[:current_user], object.order_cycle).
|
||||
visible_variants_for_incoming_exchanges_from(object.sender)
|
||||
end
|
||||
|
||||
def permitted_outgoing_variants
|
||||
OpenFoodNetwork::OrderCyclePermissions.new(options[:current_user], object.order_cycle)
|
||||
.visible_variants_for_outgoing_exchanges_to(object.receiver)
|
||||
end
|
||||
|
||||
def tag_list
|
||||
object.tag_list.join(",")
|
||||
end
|
||||
|
||||
def tags
|
||||
object.tag_list.map{ |t| { text: t } }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,46 +1,54 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'open_food_network/enterprise_issue_validator'
|
||||
|
||||
class Api::Admin::ForOrderCycle::EnterpriseSerializer < ActiveModel::Serializer
|
||||
attributes :id, :name, :managed,
|
||||
:issues_summary_supplier, :issues_summary_distributor,
|
||||
:is_primary_producer, :is_distributor, :sells
|
||||
module Api
|
||||
module Admin
|
||||
module ForOrderCycle
|
||||
class EnterpriseSerializer < ActiveModel::Serializer
|
||||
attributes :id, :name, :managed,
|
||||
: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)
|
||||
def issues_summary_supplier
|
||||
issues =
|
||||
OpenFoodNetwork::EnterpriseIssueValidator.
|
||||
new(object).
|
||||
issues_summary(confirmation_only: true)
|
||||
|
||||
if issues.nil? && products.empty?
|
||||
issues = "no products in inventory"
|
||||
if issues.nil? && products.empty?
|
||||
issues = "no products in inventory"
|
||||
end
|
||||
issues
|
||||
end
|
||||
|
||||
def issues_summary_distributor
|
||||
OpenFoodNetwork::EnterpriseIssueValidator.new(object).issues_summary
|
||||
end
|
||||
|
||||
def managed
|
||||
Enterprise.managed_by(options[:spree_current_user]).include? object
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def products_scope
|
||||
products_relation = object.supplied_products
|
||||
if order_cycle.prefers_product_selection_from_coordinator_inventory_only?
|
||||
products_relation = products_relation.
|
||||
visible_for(order_cycle.coordinator)
|
||||
end
|
||||
products_relation
|
||||
end
|
||||
|
||||
def products
|
||||
@products ||= products_scope
|
||||
end
|
||||
|
||||
def order_cycle
|
||||
options[:order_cycle]
|
||||
end
|
||||
end
|
||||
end
|
||||
issues
|
||||
end
|
||||
|
||||
def issues_summary_distributor
|
||||
OpenFoodNetwork::EnterpriseIssueValidator.new(object).issues_summary
|
||||
end
|
||||
|
||||
def managed
|
||||
Enterprise.managed_by(options[:spree_current_user]).include? object
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def products_scope
|
||||
products_relation = object.supplied_products
|
||||
if order_cycle.prefers_product_selection_from_coordinator_inventory_only?
|
||||
products_relation = products_relation.
|
||||
visible_for(order_cycle.coordinator)
|
||||
end
|
||||
products_relation
|
||||
end
|
||||
|
||||
def products
|
||||
@products ||= products_scope
|
||||
end
|
||||
|
||||
def order_cycle
|
||||
options[:order_cycle]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,31 +1,39 @@
|
||||
class Api::Admin::ForOrderCycle::SuppliedProductSerializer < ActiveModel::Serializer
|
||||
attributes :name, :supplier_name, :image_url, :master_id, :variants
|
||||
# frozen_string_literal: true
|
||||
|
||||
def supplier_name
|
||||
object.supplier.andand.name
|
||||
end
|
||||
module Api
|
||||
module Admin
|
||||
module ForOrderCycle
|
||||
class SuppliedProductSerializer < ActiveModel::Serializer
|
||||
attributes :name, :supplier_name, :image_url, :master_id, :variants
|
||||
|
||||
def image_url
|
||||
object.images.present? ? object.images.first.attachment.url(:mini) : nil
|
||||
end
|
||||
def supplier_name
|
||||
object.supplier.andand.name
|
||||
end
|
||||
|
||||
def master_id
|
||||
object.master.id
|
||||
end
|
||||
def image_url
|
||||
object.images.present? ? object.images.first.attachment.url(:mini) : nil
|
||||
end
|
||||
|
||||
def variants
|
||||
variants = if order_cycle.present? &&
|
||||
order_cycle.prefers_product_selection_from_coordinator_inventory_only?
|
||||
object.variants.visible_for(order_cycle.coordinator)
|
||||
else
|
||||
object.variants
|
||||
end
|
||||
variants.map { |variant| { id: variant.id, label: variant.full_name } }
|
||||
end
|
||||
def master_id
|
||||
object.master.id
|
||||
end
|
||||
|
||||
private
|
||||
def variants
|
||||
variants = if order_cycle.present? &&
|
||||
order_cycle.prefers_product_selection_from_coordinator_inventory_only?
|
||||
object.variants.visible_for(order_cycle.coordinator)
|
||||
else
|
||||
object.variants
|
||||
end
|
||||
variants.map { |variant| { id: variant.id, label: variant.full_name } }
|
||||
end
|
||||
|
||||
def order_cycle
|
||||
options[:order_cycle]
|
||||
private
|
||||
|
||||
def order_cycle
|
||||
options[:order_cycle]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module Admin
|
||||
class IdEmailSerializer < ActiveModel::Serializer
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
class Api::Admin::IdNameSerializer < ActiveModel::Serializer
|
||||
attributes :id, :name
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module Admin
|
||||
class IdNameSerializer < ActiveModel::Serializer
|
||||
attributes :id, :name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
class Api::Admin::IdSerializer < ActiveModel::Serializer
|
||||
attributes :id
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module Admin
|
||||
class IdSerializer < ActiveModel::Serializer
|
||||
attributes :id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,24 +1,30 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
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, :issues, :warnings
|
||||
module Api
|
||||
module Admin
|
||||
class IndexEnterpriseSerializer < ActiveModel::Serializer
|
||||
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?
|
||||
def owned
|
||||
return true if options[:spree_current_user].admin?
|
||||
|
||||
object.owner == options[:spree_current_user]
|
||||
end
|
||||
object.owner == options[:spree_current_user]
|
||||
end
|
||||
|
||||
def edit_path
|
||||
edit_admin_enterprise_path(object)
|
||||
end
|
||||
def edit_path
|
||||
edit_admin_enterprise_path(object)
|
||||
end
|
||||
|
||||
def issues
|
||||
OpenFoodNetwork::EnterpriseIssueValidator.new(object).issues
|
||||
end
|
||||
def issues
|
||||
OpenFoodNetwork::EnterpriseIssueValidator.new(object).issues
|
||||
end
|
||||
|
||||
def warnings
|
||||
OpenFoodNetwork::EnterpriseIssueValidator.new(object).warnings
|
||||
def warnings
|
||||
OpenFoodNetwork::EnterpriseIssueValidator.new(object).warnings
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'open_food_network/order_cycle_permissions'
|
||||
|
||||
module Api
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
class Api::Admin::InventoryItemSerializer < ActiveModel::Serializer
|
||||
attributes :id, :enterprise_id, :variant_id, :visible
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module Admin
|
||||
class InventoryItemSerializer < ActiveModel::Serializer
|
||||
attributes :id, :enterprise_id, :variant_id, :visible
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,29 +1,35 @@
|
||||
class Api::Admin::LineItemSerializer < ActiveModel::Serializer
|
||||
attributes :id, :quantity, :max_quantity, :price, :supplier, :final_weight_volume,
|
||||
:units_product, :units_variant
|
||||
# frozen_string_literal: true
|
||||
|
||||
has_one :order, serializer: Api::Admin::IdSerializer
|
||||
module Api
|
||||
module Admin
|
||||
class LineItemSerializer < ActiveModel::Serializer
|
||||
attributes :id, :quantity, :max_quantity, :price, :supplier, :final_weight_volume,
|
||||
:units_product, :units_variant
|
||||
|
||||
def supplier
|
||||
{ id: object.product.supplier_id }
|
||||
end
|
||||
has_one :order, serializer: Api::Admin::IdSerializer
|
||||
|
||||
def units_product
|
||||
Api::Admin::UnitsProductSerializer.new(object.product).serializable_hash
|
||||
end
|
||||
def supplier
|
||||
{ id: object.product.supplier_id }
|
||||
end
|
||||
|
||||
def units_variant
|
||||
Api::Admin::UnitsVariantSerializer.new(object.variant).serializable_hash
|
||||
end
|
||||
def units_product
|
||||
Api::Admin::UnitsProductSerializer.new(object.product).serializable_hash
|
||||
end
|
||||
|
||||
def final_weight_volume
|
||||
object.final_weight_volume.to_f
|
||||
end
|
||||
def units_variant
|
||||
Api::Admin::UnitsVariantSerializer.new(object.variant).serializable_hash
|
||||
end
|
||||
|
||||
def max_quantity
|
||||
return object.quantity unless object.max_quantity.present? &&
|
||||
object.max_quantity > object.quantity
|
||||
def final_weight_volume
|
||||
object.final_weight_volume.to_f
|
||||
end
|
||||
|
||||
object.max_quantity
|
||||
def max_quantity
|
||||
return object.quantity unless object.max_quantity.present? &&
|
||||
object.max_quantity > object.quantity
|
||||
|
||||
object.max_quantity
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,88 +1,95 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
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,
|
||||
:editable_variants_for_incoming_exchanges, :editable_variants_for_outgoing_exchanges,
|
||||
:visible_variants_for_outgoing_exchanges,
|
||||
:viewing_as_coordinator, :schedule_ids, :subscriptions_count
|
||||
module Api
|
||||
module Admin
|
||||
class OrderCycleSerializer < ActiveModel::Serializer
|
||||
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
|
||||
has_many :coordinator_fees, serializer: Api::IdSerializer
|
||||
|
||||
def orders_open_at
|
||||
object.orders_open_at.to_s
|
||||
end
|
||||
def orders_open_at
|
||||
object.orders_open_at.to_s
|
||||
end
|
||||
|
||||
def orders_close_at
|
||||
object.orders_close_at.to_s
|
||||
end
|
||||
def orders_close_at
|
||||
object.orders_close_at.to_s
|
||||
end
|
||||
|
||||
def viewing_as_coordinator
|
||||
Enterprise.managed_by(options[:current_user]).include? object.coordinator
|
||||
end
|
||||
def viewing_as_coordinator
|
||||
Enterprise.managed_by(options[:current_user]).include? object.coordinator
|
||||
end
|
||||
|
||||
def subscriptions_count
|
||||
ProxyOrder.not_canceled.where(order_cycle_id: object.id).count
|
||||
end
|
||||
def subscriptions_count
|
||||
ProxyOrder.not_canceled.where(order_cycle_id: object.id).count
|
||||
end
|
||||
|
||||
def exchanges
|
||||
scoped_exchanges = permissions.visible_exchanges.by_enterprise_name
|
||||
def exchanges
|
||||
scoped_exchanges = permissions.visible_exchanges.by_enterprise_name
|
||||
|
||||
ActiveModel::ArraySerializer.
|
||||
new(scoped_exchanges, each_serializer: Api::Admin::ExchangeSerializer,
|
||||
current_user: options[:current_user])
|
||||
end
|
||||
ActiveModel::ArraySerializer.
|
||||
new(scoped_exchanges, each_serializer: Api::Admin::ExchangeSerializer,
|
||||
current_user: options[:current_user])
|
||||
end
|
||||
|
||||
def editable_variants_for_incoming_exchanges
|
||||
variant_ids_by_supplier_id(permissions.all_incoming_editable_variants.all)
|
||||
end
|
||||
def editable_variants_for_incoming_exchanges
|
||||
variant_ids_by_supplier_id(permissions.all_incoming_editable_variants.all)
|
||||
end
|
||||
|
||||
def editable_variants_for_outgoing_exchanges
|
||||
# For each enterprise that the current user is able to see in this order cycle,
|
||||
# work out which variants should be editable within incoming exchanges from that enterprise
|
||||
editable = {}
|
||||
visible_enterprises.each do |enterprise|
|
||||
variants = permissions.editable_variants_for_outgoing_exchanges_to(enterprise).pluck(:id)
|
||||
editable[enterprise.id] = variants if variants.any?
|
||||
end
|
||||
editable
|
||||
end
|
||||
def editable_variants_for_outgoing_exchanges
|
||||
# For each enterprise that the current user is able to see in this order cycle,
|
||||
# work out which variants should be editable within incoming exchanges from that enterprise
|
||||
editable = {}
|
||||
visible_enterprises.each do |enterprise|
|
||||
variants = permissions.editable_variants_for_outgoing_exchanges_to(enterprise).pluck(:id)
|
||||
editable[enterprise.id] = variants if variants.any?
|
||||
end
|
||||
editable
|
||||
end
|
||||
|
||||
def visible_variants_for_outgoing_exchanges
|
||||
# For each enterprise that the current user is able to see in this order cycle,
|
||||
# work out which variants should be visible within outgoing exchanges from that enterprise
|
||||
visible = {}
|
||||
visible_enterprises.each do |enterprise|
|
||||
# This is hopefully a temporary measure, pending the arrival of multiple named inventories
|
||||
# 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)
|
||||
else
|
||||
permissions.
|
||||
visible_variants_for_outgoing_exchanges_to(enterprise).
|
||||
not_hidden_for(enterprise)
|
||||
end.pluck(:id)
|
||||
visible[enterprise.id] = variants if variants.any?
|
||||
end
|
||||
visible
|
||||
end
|
||||
def visible_variants_for_outgoing_exchanges
|
||||
# For each enterprise that the current user is able to see in this order cycle,
|
||||
# work out which variants should be visible within outgoing exchanges from that enterprise
|
||||
visible = {}
|
||||
visible_enterprises.each do |enterprise|
|
||||
# This is hopefully a temporary measure, pending the arrival of multiple named inventories
|
||||
# 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)
|
||||
else
|
||||
permissions.
|
||||
visible_variants_for_outgoing_exchanges_to(enterprise).
|
||||
not_hidden_for(enterprise)
|
||||
end.pluck(:id)
|
||||
visible[enterprise.id] = variants if variants.any?
|
||||
end
|
||||
visible
|
||||
end
|
||||
|
||||
private
|
||||
private
|
||||
|
||||
def permissions
|
||||
@permissions ||= OpenFoodNetwork::OrderCyclePermissions.new(options[:current_user], object)
|
||||
end
|
||||
def permissions
|
||||
@permissions ||= OpenFoodNetwork::OrderCyclePermissions.new(options[:current_user], object)
|
||||
end
|
||||
|
||||
def visible_enterprises
|
||||
@visible_enterprises ||= permissions.visible_enterprises
|
||||
end
|
||||
def visible_enterprises
|
||||
@visible_enterprises ||= permissions.visible_enterprises
|
||||
end
|
||||
|
||||
def variant_ids_by_supplier_id(variants)
|
||||
grouped_by_supplier = variants.group_by(&:supplier_id)
|
||||
grouped_by_supplier.each do |supplier_id, grouped_variants|
|
||||
grouped_by_supplier[supplier_id] = grouped_variants.map(&:id)
|
||||
def variant_ids_by_supplier_id(variants)
|
||||
grouped_by_supplier = variants.group_by(&:supplier_id)
|
||||
grouped_by_supplier.each do |supplier_id, grouped_variants|
|
||||
grouped_by_supplier[supplier_id] = grouped_variants.map(&:id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,71 +1,77 @@
|
||||
class Api::Admin::OrderSerializer < ActiveModel::Serializer
|
||||
attributes :id, :number, :user_id, :full_name, :email, :phone, :completed_at, :display_total,
|
||||
:edit_path, :state, :payment_state, :shipment_state,
|
||||
:payments_path, :ready_to_ship, :ready_to_capture, :created_at,
|
||||
:distributor_name, :special_instructions,
|
||||
:item_total, :adjustment_total, :payment_total, :total, :display_outstanding_balance
|
||||
# frozen_string_literal: true
|
||||
|
||||
has_one :distributor, serializer: Api::Admin::IdSerializer
|
||||
has_one :order_cycle, serializer: Api::Admin::IdSerializer
|
||||
module Api
|
||||
module Admin
|
||||
class OrderSerializer < ActiveModel::Serializer
|
||||
attributes :id, :number, :user_id, :full_name, :email, :phone, :completed_at, :display_total,
|
||||
:edit_path, :state, :payment_state, :shipment_state,
|
||||
:payments_path, :ready_to_ship, :ready_to_capture, :created_at,
|
||||
:distributor_name, :special_instructions, :display_outstanding_balance,
|
||||
:item_total, :adjustment_total, :payment_total, :total
|
||||
|
||||
def full_name
|
||||
object.billing_address.nil? ? "" : ( object.billing_address.full_name || "" )
|
||||
end
|
||||
has_one :distributor, serializer: Api::Admin::IdSerializer
|
||||
has_one :order_cycle, serializer: Api::Admin::IdSerializer
|
||||
|
||||
def distributor_name
|
||||
object.distributor.andand.name
|
||||
end
|
||||
def full_name
|
||||
object.billing_address.nil? ? "" : ( object.billing_address.full_name || "" )
|
||||
end
|
||||
|
||||
def display_outstanding_balance
|
||||
return "" if object.outstanding_balance.zero?
|
||||
def distributor_name
|
||||
object.distributor.andand.name
|
||||
end
|
||||
|
||||
object.display_outstanding_balance.to_s
|
||||
end
|
||||
def display_outstanding_balance
|
||||
return "" if object.outstanding_balance.zero?
|
||||
|
||||
def edit_path
|
||||
return '' unless object.id
|
||||
object.display_outstanding_balance.to_s
|
||||
end
|
||||
|
||||
spree_routes_helper.edit_admin_order_path(object)
|
||||
end
|
||||
def edit_path
|
||||
return '' unless object.id
|
||||
|
||||
def payments_path
|
||||
return '' unless object.payment_state
|
||||
spree_routes_helper.edit_admin_order_path(object)
|
||||
end
|
||||
|
||||
spree_routes_helper.admin_order_payments_path(object)
|
||||
end
|
||||
def payments_path
|
||||
return '' unless object.payment_state
|
||||
|
||||
def ready_to_capture
|
||||
pending_payment = object.pending_payments.first
|
||||
object.payment_required? && pending_payment
|
||||
end
|
||||
spree_routes_helper.admin_order_payments_path(object)
|
||||
end
|
||||
|
||||
def ready_to_ship
|
||||
object.ready_to_ship?
|
||||
end
|
||||
def ready_to_capture
|
||||
pending_payment = object.pending_payments.first
|
||||
object.payment_required? && pending_payment
|
||||
end
|
||||
|
||||
def display_total
|
||||
object.display_total.to_html
|
||||
end
|
||||
def ready_to_ship
|
||||
object.ready_to_ship?
|
||||
end
|
||||
|
||||
def email
|
||||
object.email || ""
|
||||
end
|
||||
def display_total
|
||||
object.display_total.to_html
|
||||
end
|
||||
|
||||
def phone
|
||||
object.billing_address.nil? ? "a" : ( object.billing_address.phone || "" )
|
||||
end
|
||||
def email
|
||||
object.email || ""
|
||||
end
|
||||
|
||||
def created_at
|
||||
object.created_at.blank? ? "" : I18n.l(object.created_at, format: '%B %d, %Y')
|
||||
end
|
||||
def phone
|
||||
object.billing_address.nil? ? "a" : ( object.billing_address.phone || "" )
|
||||
end
|
||||
|
||||
def completed_at
|
||||
object.completed_at.blank? ? "" : I18n.l(object.completed_at, format: '%B %d, %Y')
|
||||
end
|
||||
def created_at
|
||||
object.created_at.blank? ? "" : I18n.l(object.created_at, format: '%B %d, %Y')
|
||||
end
|
||||
|
||||
private
|
||||
def completed_at
|
||||
object.completed_at.blank? ? "" : I18n.l(object.completed_at, format: '%B %d, %Y')
|
||||
end
|
||||
|
||||
def spree_routes_helper
|
||||
Spree::Core::Engine.routes.url_helpers
|
||||
private
|
||||
|
||||
def spree_routes_helper
|
||||
Spree::Core::Engine.routes.url_helpers
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
module Api::Admin::PaymentMethod
|
||||
class BaseSerializer < ActiveModel::Serializer
|
||||
attributes :id, :name, :type, :tag_list, :tags
|
||||
# frozen_string_literal: true
|
||||
|
||||
def tag_list
|
||||
object.tag_list.join(",")
|
||||
end
|
||||
module Api
|
||||
module Admin
|
||||
module PaymentMethod
|
||||
class BaseSerializer < ActiveModel::Serializer
|
||||
attributes :id, :name, :type, :tag_list, :tags
|
||||
|
||||
def tags
|
||||
object.tag_list.map{ |t| { text: t } }
|
||||
def tag_list
|
||||
object.tag_list.join(",")
|
||||
end
|
||||
|
||||
def tags
|
||||
object.tag_list.map{ |t| { text: t } }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
module Api::Admin::PaymentMethod
|
||||
class StripeSerializer < BaseSerializer
|
||||
attributes :preferred_enterprise_id
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module Admin
|
||||
module PaymentMethod
|
||||
class StripeSerializer < BaseSerializer
|
||||
attributes :preferred_enterprise_id
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module Admin
|
||||
class PaymentMethodSerializer < ActiveModel::Serializer
|
||||
|
||||
@@ -1,44 +1,50 @@
|
||||
class Api::Admin::ProductSerializer < ActiveModel::Serializer
|
||||
attributes :id, :name, :sku, :variant_unit, :variant_unit_scale, :variant_unit_name,
|
||||
:inherits_properties, :on_hand, :price, :available_on, :permalink_live,
|
||||
:tax_category_id, :import_date, :image_url, :thumb_url
|
||||
# frozen_string_literal: true
|
||||
|
||||
has_one :supplier, key: :producer_id, embed: :id
|
||||
has_one :primary_taxon, key: :category_id, embed: :id
|
||||
has_many :variants, key: :variants, serializer: Api::Admin::VariantSerializer
|
||||
has_one :master, serializer: Api::Admin::VariantSerializer
|
||||
module Api
|
||||
module Admin
|
||||
class ProductSerializer < ActiveModel::Serializer
|
||||
attributes :id, :name, :sku, :variant_unit, :variant_unit_scale, :variant_unit_name,
|
||||
:inherits_properties, :on_hand, :price, :available_on, :permalink_live,
|
||||
:tax_category_id, :import_date, :image_url, :thumb_url
|
||||
|
||||
def image_url
|
||||
if object.images.present?
|
||||
object.images.first.attachment.url(:product)
|
||||
else
|
||||
"/noimage/product.png"
|
||||
has_one :supplier, key: :producer_id, embed: :id
|
||||
has_one :primary_taxon, key: :category_id, embed: :id
|
||||
has_many :variants, key: :variants, serializer: Api::Admin::VariantSerializer
|
||||
has_one :master, serializer: Api::Admin::VariantSerializer
|
||||
|
||||
def image_url
|
||||
if object.images.present?
|
||||
object.images.first.attachment.url(:product)
|
||||
else
|
||||
"/noimage/product.png"
|
||||
end
|
||||
end
|
||||
|
||||
def thumb_url
|
||||
if object.images.present?
|
||||
object.images.first.attachment.url(:mini)
|
||||
else
|
||||
"/noimage/mini.png"
|
||||
end
|
||||
end
|
||||
|
||||
def on_hand
|
||||
return 0 if object.on_hand.nil?
|
||||
|
||||
object.on_hand
|
||||
end
|
||||
|
||||
def price
|
||||
object.price.nil? ? '0.0' : object.price
|
||||
end
|
||||
|
||||
def available_on
|
||||
object.available_on.blank? ? "" : object.available_on.strftime("%F %T")
|
||||
end
|
||||
|
||||
def permalink_live
|
||||
object.permalink
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def thumb_url
|
||||
if object.images.present?
|
||||
object.images.first.attachment.url(:mini)
|
||||
else
|
||||
"/noimage/mini.png"
|
||||
end
|
||||
end
|
||||
|
||||
def on_hand
|
||||
return 0 if object.on_hand.nil?
|
||||
|
||||
object.on_hand
|
||||
end
|
||||
|
||||
def price
|
||||
object.price.nil? ? '0.0' : object.price
|
||||
end
|
||||
|
||||
def available_on
|
||||
object.available_on.blank? ? "" : object.available_on.strftime("%F %T")
|
||||
end
|
||||
|
||||
def permalink_live
|
||||
object.permalink
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module Admin
|
||||
class ProxyOrderSerializer < ActiveModel::Serializer
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module Admin
|
||||
class ScheduleSerializer < ActiveModel::Serializer
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
class Api::Admin::ShippingMethodSerializer < ActiveModel::Serializer
|
||||
attributes :id, :name, :tag_list, :tags
|
||||
# frozen_string_literal: true
|
||||
|
||||
def tag_list
|
||||
object.tag_list.join(",")
|
||||
end
|
||||
module Api
|
||||
module Admin
|
||||
class ShippingMethodSerializer < ActiveModel::Serializer
|
||||
attributes :id, :name, :tag_list, :tags
|
||||
|
||||
def tags
|
||||
object.tag_list.map{ |t| { text: t } }
|
||||
def tag_list
|
||||
object.tag_list.join(",")
|
||||
end
|
||||
|
||||
def tags
|
||||
object.tag_list.map{ |t| { text: t } }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module Admin
|
||||
# Used by admin subscription form
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module Admin
|
||||
class SubscriptionLineItemSerializer < ActiveModel::Serializer
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module Admin
|
||||
class SubscriptionSerializer < ActiveModel::Serializer
|
||||
|
||||
@@ -1,51 +1,63 @@
|
||||
class Api::Admin::TagRuleSerializer < ActiveModel::Serializer
|
||||
delegate :serializable_hash, to: :rule_specific_serializer
|
||||
# frozen_string_literal: true
|
||||
|
||||
def rule_specific_serializer
|
||||
"Api::Admin::#{object.class}Serializer".constantize.new(object)
|
||||
end
|
||||
end
|
||||
module Api
|
||||
module Admin
|
||||
class TagRuleSerializer < ActiveModel::Serializer
|
||||
delegate :serializable_hash, to: :rule_specific_serializer
|
||||
|
||||
module Api::Admin::TagRule
|
||||
class BaseSerializer < ActiveModel::Serializer
|
||||
attributes :id, :enterprise_id, :type, :is_default, :preferred_customer_tags
|
||||
end
|
||||
|
||||
class DiscountOrderSerializer < BaseSerializer
|
||||
has_one :calculator, serializer: Api::Admin::Calculator::FlatPercentItemTotalSerializer
|
||||
end
|
||||
|
||||
class FilterShippingMethodsSerializer < BaseSerializer
|
||||
attributes :preferred_matched_shipping_methods_visibility, :preferred_shipping_method_tags,
|
||||
:shipping_method_tags
|
||||
|
||||
def shipping_method_tags
|
||||
object.preferred_shipping_method_tags.split(",")
|
||||
end
|
||||
end
|
||||
|
||||
class FilterPaymentMethodsSerializer < BaseSerializer
|
||||
attributes :preferred_matched_payment_methods_visibility, :preferred_payment_method_tags,
|
||||
:payment_method_tags
|
||||
|
||||
def payment_method_tags
|
||||
object.preferred_payment_method_tags.split(",")
|
||||
end
|
||||
end
|
||||
|
||||
class FilterProductsSerializer < BaseSerializer
|
||||
attributes :preferred_matched_variants_visibility, :preferred_variant_tags, :variant_tags
|
||||
|
||||
def variant_tags
|
||||
object.preferred_variant_tags.split(",")
|
||||
end
|
||||
end
|
||||
|
||||
class FilterOrderCyclesSerializer < BaseSerializer
|
||||
attributes :preferred_matched_order_cycles_visibility, :preferred_exchange_tags, :exchange_tags
|
||||
|
||||
def exchange_tags
|
||||
object.preferred_exchange_tags.split(",")
|
||||
def rule_specific_serializer
|
||||
"Api::Admin::#{object.class}Serializer".constantize.new(object)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module Api
|
||||
module Admin
|
||||
module TagRule
|
||||
class BaseSerializer < ActiveModel::Serializer
|
||||
attributes :id, :enterprise_id, :type, :is_default, :preferred_customer_tags
|
||||
end
|
||||
|
||||
class DiscountOrderSerializer < BaseSerializer
|
||||
has_one :calculator, serializer: Api::Admin::Calculator::FlatPercentItemTotalSerializer
|
||||
end
|
||||
|
||||
class FilterShippingMethodsSerializer < BaseSerializer
|
||||
attributes :preferred_matched_shipping_methods_visibility, :preferred_shipping_method_tags,
|
||||
:shipping_method_tags
|
||||
|
||||
def shipping_method_tags
|
||||
object.preferred_shipping_method_tags.split(",")
|
||||
end
|
||||
end
|
||||
|
||||
class FilterPaymentMethodsSerializer < BaseSerializer
|
||||
attributes :preferred_matched_payment_methods_visibility, :preferred_payment_method_tags,
|
||||
:payment_method_tags
|
||||
|
||||
def payment_method_tags
|
||||
object.preferred_payment_method_tags.split(",")
|
||||
end
|
||||
end
|
||||
|
||||
class FilterProductsSerializer < BaseSerializer
|
||||
attributes :preferred_matched_variants_visibility, :preferred_variant_tags, :variant_tags
|
||||
|
||||
def variant_tags
|
||||
object.preferred_variant_tags.split(",")
|
||||
end
|
||||
end
|
||||
|
||||
class FilterOrderCyclesSerializer < BaseSerializer
|
||||
attributes :preferred_matched_order_cycles_visibility,
|
||||
:preferred_exchange_tags,
|
||||
:exchange_tags
|
||||
|
||||
def exchange_tags
|
||||
object.preferred_exchange_tags.split(",")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
class Api::Admin::TaxCategorySerializer < ActiveModel::Serializer
|
||||
attributes :id, :name
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module Admin
|
||||
class TaxCategorySerializer < ActiveModel::Serializer
|
||||
attributes :id, :name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
class Api::Admin::TaxonSerializer < ActiveModel::Serializer
|
||||
attributes :id, :name, :pretty_name
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module Admin
|
||||
class TaxonSerializer < ActiveModel::Serializer
|
||||
attributes :id, :name, :pretty_name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user