Compare commits

...

392 Commits

Author SHA1 Message Date
Matt-Yorkley
f7b3813fbe Defend against nils in variant serializer
If unit_price.denominator ever returns nil, the serializer won't explode now.
2021-03-30 15:26:48 +01:00
Pau Pérez Fabregat
6a4c7a462b Merge pull request #7222 from openfoodfoundation/transifex
Transifex
2021-03-29 16:13:02 +02:00
Matt-Yorkley
581217ea2d Merge pull request #7239 from Matt-Yorkley/paranoia-scopes
Update default scopes with acts_as_paranoid
2021-03-29 15:24:44 +02:00
Matt-Yorkley
e8ddbc0449 Merge pull request #7228 from andrewpbrett/freeze-canceled-orders
Remove UI for modifying line items on canceled orders
2021-03-29 15:24:24 +02:00
Pau Pérez Fabregat
325ccdd8d5 Merge pull request #7208 from mkllnk/7130-double-processing-payment
Avoid double processing payment
2021-03-29 13:36:21 +02:00
Transifex-Openfoodnetwork
5fc0b8d724 Updating translations for config/locales/es.yml 2021-03-29 21:26:13 +11:00
Transifex-Openfoodnetwork
56c2caf422 Updating translations for config/locales/ca.yml 2021-03-29 21:25:49 +11:00
Pau Pérez Fabregat
b041b9f537 Merge pull request #7252 from openfoodfoundation/dependabot/bundler/delayed_job_active_record-4.1.6
Bump delayed_job_active_record from 4.1.5 to 4.1.6
2021-03-29 12:24:10 +02:00
Pau Pérez Fabregat
478008ac0d Merge pull request #7249 from Matt-Yorkley/engine-issues
Engine issues
2021-03-29 12:23:03 +02:00
Pau Pérez Fabregat
b8815d2c56 Merge pull request #7159 from Matt-Yorkley/dead-code-adjustment
DCOTW: LineItemBasedAdjustmentHandling
2021-03-29 11:46:23 +02:00
Pau Pérez Fabregat
79dc75d1e4 Merge pull request #7251 from Matt-Yorkley/dead-code-checkout
Remove dead code in Order::Checkout module
2021-03-29 11:45:05 +02:00
Pau Pérez Fabregat
e5ca2e8b27 Merge pull request #7253 from openfoodfoundation/dependabot/bundler/webmock-3.12.2
Bump webmock from 3.12.1 to 3.12.2
2021-03-29 11:36:21 +02:00
Transifex-Openfoodnetwork
fa95334229 Updating translations for config/locales/en_GB.yml 2021-03-29 19:12:58 +11:00
Transifex-Openfoodnetwork
42147e13eb Updating translations for config/locales/en_FR.yml 2021-03-29 18:59:40 +11:00
Transifex-Openfoodnetwork
7be7fb3ddc Updating translations for config/locales/fr.yml 2021-03-29 18:59:29 +11:00
Maikel Linke
ba857cfce4 Move translation for lazy lookup in previous commit 2021-03-29 17:00:11 +11:00
dependabot[bot]
30daab7dc5 Bump webmock from 3.12.1 to 3.12.2
Bumps [webmock](https://github.com/bblimke/webmock) from 3.12.1 to 3.12.2.
- [Release notes](https://github.com/bblimke/webmock/releases)
- [Changelog](https://github.com/bblimke/webmock/blob/master/CHANGELOG.md)
- [Commits](https://github.com/bblimke/webmock/compare/v3.12.1...v3.12.2)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-29 05:50:07 +00:00
dependabot[bot]
bc8ca9f316 Bump delayed_job_active_record from 4.1.5 to 4.1.6
Bumps [delayed_job_active_record](https://github.com/collectiveidea/delayed_job_active_record) from 4.1.5 to 4.1.6.
- [Release notes](https://github.com/collectiveidea/delayed_job_active_record/releases)
- [Commits](https://github.com/collectiveidea/delayed_job_active_record/compare/v4.1.5...v4.1.6)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-29 05:49:22 +00:00
Transifex-Openfoodnetwork
40e8815b5f Updating translations for config/locales/en_US.yml 2021-03-29 15:46:31 +11:00
Transifex-Openfoodnetwork
13668628c4 Updating translations for config/locales/en_US.yml 2021-03-29 15:45:09 +11:00
Maikel
74b06d16b8 Merge pull request #7209 from openfoodfoundation/dependabot/bundler/rubocop-1.12.0
Bump rubocop from 1.11.0 to 1.12.0
2021-03-29 10:59:38 +11:00
Transifex-Openfoodnetwork
8072aeda9d Updating translations for config/locales/de_DE.yml 2021-03-29 10:28:26 +11:00
Matt-Yorkley
a46a0b609e Remove dead code in Order::Checkout module
🔥
2021-03-28 23:57:16 +01:00
Andy Brett
e85db1468f Merge pull request #7248 from drummer83/patch-1
Updated Ruby version, added link to Debian guide and more…
2021-03-28 11:25:20 -07:00
Matt-Yorkley
110d1ef015 Ensure error code on failing tests 2021-03-28 17:33:55 +01:00
Konrad
b1507f7b2e Updated Ruby version, added link to Debian guide and made requirements more clear. 2021-03-28 00:02:54 +01:00
Matt-Yorkley
28ee6a66a0 Update line item adjustments spec
The `adjustable` and `source` associations are basically the same now, and we'll be deleting the latter soon.
2021-03-27 18:59:50 +00:00
Matt-Yorkley
593764851f Remove LineItemBasedAdjustmentHandling 2021-03-27 18:59:49 +00:00
Andy Brett
718a3be9f4 Merge pull request #7241 from luisramos0/more_rspec
[rails 5-2] More fixes to rspec syntax
2021-03-27 07:44:14 -07:00
Luis Ramos
f6f9159430 Fix rspec syntax 2021-03-26 23:45:12 +00:00
Luis Ramos
d66a78ecce Add magic comment 2021-03-26 23:42:07 +00:00
Luis Ramos
3fe5f04fbc Fix rspec syntax 2021-03-26 23:04:32 +00:00
Luis Ramos
30ca608fb9 Fix rspec syntax 2021-03-26 23:03:27 +00:00
Luis Ramos
8f7025b8c6 Fix rspec syntax 2021-03-26 23:01:23 +00:00
Luis Ramos
396c379f37 Fix rspec syntax 2021-03-26 22:50:48 +00:00
Luis Ramos
60ae3a8a4f Fix rspec syntax 2021-03-26 22:37:54 +00:00
Luis Ramos
34771c89f9 Fix rspec syntax 2021-03-26 22:34:16 +00:00
Luis Ramos
f62f958a4c Fix rspec syntax 2021-03-26 22:29:50 +00:00
Luis Ramos
ad3745f032 Fix rspec syntax 2021-03-26 22:19:16 +00:00
Matt-Yorkley
69cdb85291 Remove #with_unscoped_products_and_variants. Thanks @andrewpbrett :)
🔥
2021-03-26 19:08:17 +00:00
Matt-Yorkley
1b19d4bdee Update default scopes with acts_as_paranoid
Fixes an issue where the LineItem :sorted_by_name_and_unit_value scope was not working with removal of the default scopes on line item and variant, which meant that the join in the scope was excluding soft-deleted items that should not have been excluded.
2021-03-26 18:22:05 +00:00
Andy Brett
d78517b6ed Update app/views/spree/admin/orders/_add_product.html.haml
Co-authored-by: Maikel <maikel@email.org.au>
2021-03-26 09:34:12 -07:00
Andy Brett
19c2c9c1c5 Merge pull request #7175 from openfoodfoundation/7130-notify-on-payment-intent-error
Record invalid payment states for debugging
2021-03-26 08:33:07 -07:00
Matt-Yorkley
902265c678 Merge pull request #7235 from jibees/7220-import-ofn-font-into-admin
Fix font import from Darkswarm to admin
2021-03-26 15:27:07 +01:00
Jean-Baptiste Bellet
ee4beb57db Do not import darkswarm file into admin, but only needed selector 2021-03-26 12:27:33 +01:00
Transifex-Openfoodnetwork
ad14a91eb2 Updating translations for config/locales/en_FR.yml 2021-03-26 22:00:33 +11:00
Transifex-Openfoodnetwork
09e0474069 Updating translations for config/locales/fr.yml 2021-03-26 21:57:16 +11:00
Transifex-Openfoodnetwork
59cf5aa3ec Updating translations for config/locales/ru.yml 2021-03-26 21:31:08 +11:00
Transifex-Openfoodnetwork
2e8178a33f Updating translations for config/locales/es.yml 2021-03-26 18:42:11 +11:00
Transifex-Openfoodnetwork
96bb26ad45 Updating translations for config/locales/ca.yml 2021-03-26 18:37:20 +11:00
Maikel Linke
4c1f977d26 Return thread syncing to concurrency spec
Without syncing the two threads with a lock, the spec could accidentally
pass even if the code is broken. It was accidentally removed during
refactoring in b0fa1464f.
2021-03-26 12:07:46 +11:00
Maikel Linke
cbd730f4eb Remove left-over comment
This spec was fixed before and the comment was outdated.
2021-03-26 12:07:24 +11:00
Andy Brett
563a2758a6 remove UI for modifying line items on canceled orders 2021-03-25 16:52:56 -07:00
Transifex-Openfoodnetwork
bc191ab9bb Updating translations for config/locales/de_DE.yml 2021-03-26 10:50:19 +11:00
Andy Brett
254f5e95af Merge pull request #7219 from jibees/7216-fix-failing-specs-on-unit-price
Refactor unit price i18n keys
2021-03-25 13:26:14 -07:00
Andy Brett
5631c895b7 Merge pull request #7155 from jibees/7126-fix-links-to-customer-email
/admin/orders : fix incorrect value of the mail field in the mailto link
2021-03-25 12:55:24 -07:00
Andy Brett
691dd05028 Merge pull request #6956 from andrewpbrett/unit-price-backend
Provide actual unit price values in front end shop
2021-03-25 12:50:59 -07:00
Andy Brett
1d78a827ae Merge pull request #7156 from jibees/5679-add-i18n-keys-for-distance_of_time_in_words_to_now-method
Add keys to handle some i18n issues
2021-03-25 12:43:09 -07:00
Andy Brett
2490861639 show correct values in line_item.rb 2021-03-25 12:26:02 -07:00
Transifex-Openfoodnetwork
8638509d01 Updating translations for config/locales/fr.yml 2021-03-26 06:20:25 +11:00
Transifex-Openfoodnetwork
76214e7733 Updating translations for config/locales/en_FR.yml 2021-03-26 06:17:27 +11:00
Transifex-Openfoodnetwork
aad9a69cfe Updating translations for config/locales/fr.yml 2021-03-26 06:17:20 +11:00
Matt-Yorkley
5b3fd25a78 Update all locales with the latest Transifex translations 2021-03-25 19:01:50 +00:00
Matt-Yorkley
cdd052d39f Merge pull request #7218 from openfoodfoundation/transifex
Transifex
2021-03-25 19:57:49 +01:00
Jean-Baptiste Bellet
5c93ccc0e3 Refactor unit price i18n keys
- Now got two keys: `js.admin.unit_price_tooltip` and `js.shopfront.unit_price_tooltip`
2021-03-25 17:59:20 +01:00
Transifex-Openfoodnetwork
93501743b6 Updating translations for config/locales/ar.yml 2021-03-26 03:48:04 +11:00
Matt-Yorkley
0f5af2d9f1 Merge pull request #6927 from Matt-Yorkley/adjustments-payment-fee
[Adjustments] Payment fee adjustment
2021-03-25 17:40:53 +01:00
Andy Brett
b68476cdcb Merge pull request #7212 from coopdevs/remove-n+1-on-admin-customers
Fix multiple N+1s on /admin/customers.json
2021-03-25 09:29:43 -07:00
Andy Brett
be60adbcb3 update class name to singular in spec 2021-03-25 08:51:16 -07:00
Andy Brett
907c0d3e8c rename unit_price.rb file 2021-03-25 08:51:15 -07:00
Andy Brett
d2828585eb fix typo in spec 2021-03-25 08:51:15 -07:00
Andy Brett
6ebf45610d use instance_double in specs 2021-03-25 08:51:15 -07:00
Andy Brett
7319ef7345 use better method and class names 2021-03-25 08:51:15 -07:00
Andy Brett
330839012e add translation 2021-03-25 08:51:15 -07:00
Andy Brett
89c7342892 memoize UnitPrices object 2021-03-25 08:51:15 -07:00
Andy Brett
0afc2d281a shorten UnitPrices method names 2021-03-25 08:51:15 -07:00
Andy Brett
39fc0707c3 provide unit price values in front end shop 2021-03-25 08:51:15 -07:00
Matt-Yorkley
cbd7c9f4c0 Update adjustments controller collection scope 2021-03-25 15:02:02 +00:00
Pau Pérez Fabregat
b12293d1fb Merge pull request #6991 from jibees/6494-show-unit-price-in-admin/product-edit-form
Show unit price in admin/product edit form
2021-03-25 15:59:09 +01:00
Pau Pérez Fabregat
0121c18823 Merge pull request #7210 from openfoodfoundation/dependabot/npm_and_yarn/karma-6.3.1
Bump karma from 0.13.22 to 6.3.1
2021-03-25 12:43:11 +01:00
Pau Pérez Fabregat
56d2db8c58 Merge pull request #7194 from Matt-Yorkley/deprecations-validates-id
Deprecations: validation definitions
2021-03-25 12:39:33 +01:00
Pau Pérez Fabregat
914e6d5f21 Merge pull request #7196 from Matt-Yorkley/deprecations-uniq
Deprecations: certain uses of #uniq
2021-03-25 12:12:36 +01:00
Pau Pérez Fabregat
26bd6f0f17 Merge pull request #7205 from Matt-Yorkley/deprecations-3
Deprecations 3
2021-03-25 12:11:30 +01:00
Pau Pérez Fabregat
9397922902 Merge pull request #7206 from openfoodfoundation/transifex
Transifex
2021-03-25 11:33:08 +01:00
Pau Perez
ead1ab31b4 Fix multiple N+1 on /admin/customers.json
This (should) considerably improve traces like
https://app.datadoghq.com/apm/trace/917632173599137280?spanID=3163385094622710144&env=production&sort=time&colorBy=service&spanViewType=metadata&graphType=flamegraph&shouldShowLegend=true
by fixing the following 3 N+1s

```
user: root
GET /admin/customers.json?enterprise_id=4
USE eager loading detected
  Customer => [:enterprise]
  Add to your query: .includes([:enterprise])
Call stack
  /usr/src/app/app/serializers/api/admin/customer_with_calculated_balance_serializer.rb:24:in `balance_value'
  /usr/src/app/app/serializers/api/admin/customer_with_calculated_balance_serializer.rb:9:in `balance'
  /usr/src/app/app/controllers/admin/customers_controller.rb:20:in `block (2 levels) in index'
  /usr/src/app/app/controllers/admin/customers_controller.rb:17:in `index'

user: root
GET /admin/customers.json?enterprise_id=4
USE eager loading detected
  Spree::Address => [:state]
  Add to your query: .includes([:state])
Call stack
  /usr/src/app/app/serializers/api/address_serializer.rb:14:in `state_name'
  /usr/src/app/app/controllers/admin/customers_controller.rb:20:in `block (2 levels) in index'
  /usr/src/app/app/controllers/admin/customers_controller.rb:17:in `index'

user: root
GET /admin/customers.json?enterprise_id=4
USE eager loading detected
  Spree::Address => [:country]
  Add to your query: .includes([:country])
Call stack
  /usr/src/app/app/serializers/api/address_serializer.rb:10:in `country_name'
  /usr/src/app/app/controllers/admin/customers_controller.rb:20:in `block (2 levels) in index'
  /usr/src/app/app/controllers/admin/customers_controller.rb:17:in `index'
```

This popped up after improving the balances calculation. Now, that it's
fast, it's clear that are more performance problems on that endpoint.
We'll see if there are any left after this.
2021-03-25 11:19:00 +01:00
Maikel Linke
49eaee05a2 Deactivate cop Naming/PredicateName
It picked up matcher helpers in specs like `have_in_cart` which is a
useful name here.
2021-03-25 18:10:57 +11:00
Maikel Linke
ffb4ba5ef5 Style numeric predicate use with Rubocop 2021-03-25 18:07:11 +11:00
Maikel Linke
852147bf45 Update Rubocop todo lists 2021-03-25 17:59:59 +11:00
Maikel Linke
853b250afa Disable Rubocop suggestions to avoid noise 2021-03-25 17:44:46 +11:00
Maikel Linke
74fce2d2f1 Disable new Rubo-Cops
We have enough violations already. Let's add them as we see fit and
avoid the warnings for now.
2021-03-25 17:41:45 +11:00
Maikel Linke
f2103e923f Update Rails version for Rubocop 2021-03-25 17:41:05 +11:00
Maikel Linke
0133cb4d22 Update deprecated Rubocop option 2021-03-25 17:40:09 +11:00
dependabot[bot]
33ca13ca8e Bump karma from 0.13.22 to 6.3.1
Bumps [karma](https://github.com/karma-runner/karma) from 0.13.22 to 6.3.1.
- [Release notes](https://github.com/karma-runner/karma/releases)
- [Changelog](https://github.com/karma-runner/karma/blob/master/CHANGELOG.md)
- [Commits](https://github.com/karma-runner/karma/compare/v0.13.22...v6.3.1)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-25 05:50:48 +00:00
dependabot[bot]
04400e0289 Bump rubocop from 1.11.0 to 1.12.0
Bumps [rubocop](https://github.com/rubocop/rubocop) from 1.11.0 to 1.12.0.
- [Release notes](https://github.com/rubocop/rubocop/releases)
- [Changelog](https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rubocop/rubocop/compare/v1.11.0...v1.12.0)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-25 05:26:45 +00:00
Maikel Linke
4d242af007 Use pessimistic locking processing Stripe payment
We used pessimistic locking around the `update` action already but when
Stripe redirects back to us we complete the payment in the `edit` action.
2021-03-25 15:17:30 +11:00
Maikel Linke
9fabca134a Fix and re-activate concurrency spec 2021-03-25 14:35:45 +11:00
Maikel Linke
af5ac2a25e Extend test coverage of CheckoutController
I'm covering the interaction with Stripe here to test for error cases in
the future.
2021-03-25 14:35:45 +11:00
Transifex-Openfoodnetwork
ac4903ef67 Updating translations for config/locales/pt_BR.yml 2021-03-25 06:28:47 +11:00
Matt-Yorkley
ba3984104b Replace deprecated #alias_method_chain in Spree::Product 2021-03-24 17:51:22 +00:00
Matt-Yorkley
0ab43d23f9 Replace deprecated reloading by passing true to an association
object.relation(true) -> object.relation.reload
2021-03-24 17:51:22 +00:00
Matt-Yorkley
26ed44412f Update #validates definitions
Where the presence of an object is being validated and that object comes from an *association*, we should use `validates :object, presence: true` instead of `validates :object_id, presence: true`.

This does not apply in the same way to validations on uniqueness of certain attributes, such as `validates :object_id, uniqueness...`
2021-03-24 15:43:09 +00:00
Matt-Yorkley
ec088c3a60 Merge pull request #7161 from openfoodfoundation/dependabot/bundler/oauth2-1.4.7
Bump oauth2 from 1.4.4 to 1.4.7
2021-03-24 13:35:32 +01:00
Matt-Yorkley
932adb533c Merge pull request #7184 from Matt-Yorkley/deprecation-errors-set
Update deprecated errors.set syntax
2021-03-24 13:17:55 +01:00
Matt-Yorkley
f1e4612c05 Update deprecated uses of #uniq
Enumerable#uniq is fine (eg calling #uniq on an Array object), but now using #uniq on an ActiveRecord::Relation is deprecated in favour of #distinct (which modifies the query itself, as opposed to iterating over the results of the query).
2021-03-24 11:42:24 +00:00
Andy Brett
1cb9504a2c Merge pull request #7187 from luisramos0/uniq
[Rails 5.2] Relation#Uniq is deprecated, distinct is recommended instead
2021-03-23 20:52:47 -07:00
Andy Brett
024efafa39 Merge pull request #7190 from luisramos0/more_spec_syntax
[rails 5.2] Fix more spec syntax
2021-03-23 20:52:31 -07:00
Andy Brett
28ad3a5f1d Merge pull request #7186 from luisramos0/tax_rate_validation_fix
[Rails 5.2] Fix tax_category validation to work in rails 5.2
2021-03-23 20:52:13 -07:00
Andy Brett
8080c09469 Merge pull request #7189 from luisramos0/inv_item_fix
[Rails 5.2] Fix validation problem in inventory items
2021-03-23 20:51:53 -07:00
Luis Ramos
e2df8937e5 Fix rspec syntax in bulk items controller 2021-03-23 22:00:50 +00:00
Luis Ramos
5549054325 Fix rspec syntax in line items controller 2021-03-23 21:55:58 +00:00
Luis Ramos
b14646ff50 Fix rspec syntax in checkout controller 2021-03-23 21:48:52 +00:00
Luis Ramos
7c8c720976 Fix rspec syntax to work with rails 5.2 2021-03-23 21:41:03 +00:00
Luis Ramos
b3d10cfb60 Fix validation of inventory item 2021-03-23 21:22:03 +00:00
Luis Ramos
c2364b3528 Relation#Uniq is deprecated, distinct is recommended instead 2021-03-23 20:57:58 +00:00
Luis Ramos
708c99fe9b Fix validation to work in rails 5.2 2021-03-23 20:33:04 +00:00
Matt-Yorkley
5f4e3c75c7 Update deprecated errors.set syntax
DEPRECATION WARNING: ActiveModel::Errors#set is deprecated and will be removed in Rails 5.1. Use model.errors.add(:preferred_discount_amount, ["has an invalid format. Please enter a number."]) instead. (called from block (2 levels) in localize_number at /home/runner/work/openfoodnetwork/openfoodnetwork/lib/spree/localized_number.rb:38)
2021-03-23 20:11:59 +00:00
Matt-Yorkley
5840b0e33c Adapt adjustment interface for payment's adjustment being singular
Payments only have one adjustment, all other adjustable objects have adjustments (plural).
2021-03-23 18:19:37 +00:00
Matt-Yorkley
e237727ba2 Migrate payment fee adjustments to payment objects 2021-03-23 18:19:37 +00:00
Matt-Yorkley
5d1d72b36b Update Admin::OrdersHelper#order_adjustments_for_display 2021-03-23 18:19:37 +00:00
Matt-Yorkley
21e0c36f4f Update order totals after deleting shipments and payments 2021-03-23 18:19:06 +00:00
Matt-Yorkley
5a7792bebc Update Checkout Restart spec 2021-03-23 18:19:06 +00:00
Matt-Yorkley
3294b33431 Update Payment spec 2021-03-23 18:19:06 +00:00
Matt-Yorkley
2ccaf80013 Update EnterpriseFeeSummary report scopes 2021-03-23 18:19:06 +00:00
Matt-Yorkley
242ccc4fb3 Update OrderAdjustmentsFetcher 2021-03-23 18:18:36 +00:00
Matt-Yorkley
8abfd7c3f3 Update Checkout spec 2021-03-23 18:17:50 +00:00
Matt-Yorkley
cb179c794b Update Paypal spec 2021-03-23 18:17:50 +00:00
Matt-Yorkley
a0e6b64e98 Update Order serializer 2021-03-23 18:17:50 +00:00
Matt-Yorkley
a42651d543 Update Payment fee adjustment 2021-03-23 18:17:50 +00:00
Matt-Yorkley
525fef14b1 Merge pull request #6974 from Matt-Yorkley/adjustments-line-item-fees
[Adjustments] Update line item enteprise fees
2021-03-23 19:06:02 +01:00
Andy Brett
b539015647 Merge pull request #7025 from Matt-Yorkley/adjustments-order-taxes
[Adjustments] Simplify order tax adjustments
2021-03-23 09:37:44 -07:00
Pau Pérez Fabregat
5a16b86ac9 Merge pull request #7178 from andrewpbrett/rebalance-ci
Robustify CI
2021-03-23 16:32:54 +01:00
Pau Pérez Fabregat
ac164df514 Merge pull request #7181 from openfoodfoundation/transifex
Transifex
2021-03-23 16:25:26 +01:00
Andy Brett
e9c259ec98 remove unnecessary type check 2021-03-23 08:12:26 -07:00
Transifex-Openfoodnetwork
cdc40f1b88 Updating translations for config/locales/en_FR.yml 2021-03-23 22:36:35 +11:00
Transifex-Openfoodnetwork
e97135f138 Updating translations for config/locales/en_FR.yml 2021-03-23 22:33:36 +11:00
Transifex-Openfoodnetwork
bf3e9b56c7 Updating translations for config/locales/fr.yml 2021-03-23 22:32:50 +11:00
Pau Pérez Fabregat
07d52bb44f Merge pull request #7173 from Matt-Yorkley/adjustments-indexes
Add indexes on adjustments polymorphic associations
2021-03-23 11:55:30 +01:00
Pau Pérez Fabregat
393ea92dc7 Merge pull request #7177 from coopdevs/fix-balances-order-cycle-report-regression
Fix balances order cycle report regression
2021-03-23 10:08:11 +01:00
Pau Pérez Fabregat
14104cba57 Merge pull request #7171 from openfoodfoundation/transifex
Transifex
2021-03-23 09:38:17 +01:00
Pau Perez
199d48123b Fully qualify table columns in query object
This fixes the error UK's is experiencing:

```
PG::AmbiguousColumn: ERROR: column reference "state" is ambiguous LINE
1: SELECT DISTINCT spree_orders.*, CASE WHEN state IN ('cancele...
^ : SELECT DISTINCT spree_orders.*, CASE WHEN state IN ('canceled',
'returned') THEN payment_total WHEN state IS NOT NULL THEN payment_total
- total ELSE 0 END AS balance_value, spree_orders.* FROM "spree_orders"
INNER JOIN "spree_shipments"
```

See
https://app.bugsnag.com/yaycode/openfoodnetwork-uk/errors/6058c45989d37300079e8312?event_id=6058ccd30075af73bcb20000&i=sk&m=nw.
2021-03-23 09:37:47 +01:00
Andy Brett
eff832c583 cleaner formatting
Co-authored-by: Maikel <maikel@email.org.au>
2021-03-22 20:47:12 -07:00
Andy Brett
3dc627995f Merge pull request #7138 from luisramos0/rails52commits
Rails52commits
2021-03-22 18:13:01 -07:00
Andy Brett
e8f00f3d8c Merge branch 'master' into rails52commits 2021-03-22 17:43:34 -07:00
Andy Brett
50296458b8 Merge pull request #7097 from luisramos0/rails-5-2-rspec-params
Rails 5 2 update Rspec controller syntax
2021-03-22 17:29:29 -07:00
Andy Brett
aab1a5e5d5 Merge pull request #7147 from Matt-Yorkley/deprecations-2
Deprecations 2
2021-03-22 17:28:11 -07:00
Andy Brett
f784db0127 Merge pull request #7100 from luisramos0/view_spec_in_rails5
Rails 5-2 - View spec in rails5
2021-03-22 16:42:56 -07:00
Luis Ramos
13b8b3d4a5 Fix rubocop issues 2021-03-22 23:24:01 +00:00
Andy Brett
2fbc5afce6 add rake task to catch all subfolders under /spec 2021-03-22 16:18:19 -07:00
Luis Ramos
3853aed718 Make validator work in rails 5 and rails 5.2 by adding a proc 2021-03-22 22:45:04 +00:00
Transifex-Openfoodnetwork
58a5a694a9 Updating translations for config/locales/en_US.yml 2021-03-23 08:19:44 +11:00
Luis Ramos
e2ce6634df Adapt specs to new rspec syntax without xhr 2021-03-22 20:43:48 +00:00
Luis Ramos
c224396e71 Correct helper name needed in this spec 2021-03-22 20:38:14 +00:00
Pau Perez
ec4bae3995 Reproduce regression in a test 2021-03-22 19:01:17 +01:00
Andy Brett
dbe06e206c Merge pull request #7048 from andrewpbrett/fix-sub-manifests
Verify line item when placing sub order (Fix #6680)
2021-03-22 10:24:20 -07:00
Andy Brett
f021e5e074 add --profile to all jobs 2021-03-22 09:37:03 -07:00
Andy Brett
8cc6e60ed1 include specs that start with numbers 2021-03-22 09:31:52 -07:00
Matt-Yorkley
3e9d1bfe1f Add defensive more code in not_hidden_for scope 2021-03-22 14:52:42 +00:00
Transifex-Openfoodnetwork
0d58701b07 Updating translations for config/locales/en_GB.yml 2021-03-22 20:11:05 +11:00
Transifex-Openfoodnetwork
471d2ea25d Updating translations for config/locales/es.yml 2021-03-22 19:57:33 +11:00
Transifex-Openfoodnetwork
6c984ab72f Updating translations for config/locales/ca.yml 2021-03-22 19:56:46 +11:00
Pau Pérez Fabregat
7e176298ef Merge pull request #7162 from openfoodfoundation/dependabot/bundler/i18n-js-3.8.2
Bump i18n-js from 3.8.1 to 3.8.2
2021-03-22 09:04:37 +01:00
Maikel Linke
fce8d3a2f8 Record invalid payment states for debugging
We observed invalid payment states in Bugsnag but we don't actually know
in which state the payment intent was in. From the context we can guess
that it was "succeeded" but it would be good to validate this. And in
the future it would be good to know if there are other invalid states we
can end up in.

The notification to Bugsnag happens in another part of the code.
2021-03-22 16:35:22 +11:00
Maikel Linke
3dac451e5b Add spec for StripeSCA payment gateway
We didn't actually have a unit test for this.
2021-03-22 16:35:22 +11:00
Maikel
56154bdb7e Merge pull request #7168 from andrewpbrett/rebalance-ci
Rebalance CI jobs
2021-03-22 12:23:20 +11:00
Andy Brett
5cbd37f112 reorder jobs and move to 7 jobs 2021-03-21 14:55:53 -07:00
Transifex-Openfoodnetwork
e1ae1aa78e Updating translations for config/locales/en_NZ.yml 2021-03-21 11:23:24 +11:00
Matt-Yorkley
85d2f3143b Improve indexes on adjustments adjustable and originator associations 2021-03-20 11:09:53 +00:00
Transifex-Openfoodnetwork
4ea195f803 Updating translations for config/locales/de_DE.yml 2021-03-20 08:19:28 +11:00
Andy Brett
40be8e2874 Merge pull request #7157 from Matt-Yorkley/dead-code-billing-names
DCOTW: Order#billing_firstname and Order#billing_lastname
2021-03-19 12:12:03 -07:00
Andy Brett
c298aa19fa rebalance CI jobs 2021-03-19 10:48:18 -07:00
dependabot[bot]
7fe889712b Bump i18n-js from 3.8.1 to 3.8.2
Bumps [i18n-js](https://github.com/fnando/i18n-js) from 3.8.1 to 3.8.2.
- [Release notes](https://github.com/fnando/i18n-js/releases)
- [Changelog](https://github.com/fnando/i18n-js/blob/main/CHANGELOG.md)
- [Commits](https://github.com/fnando/i18n-js/compare/v3.8.1...v3.8.2)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-19 05:26:00 +00:00
dependabot[bot]
4c9d4104ba Bump oauth2 from 1.4.4 to 1.4.7
Bumps [oauth2](https://github.com/oauth-xx/oauth2) from 1.4.4 to 1.4.7.
- [Release notes](https://github.com/oauth-xx/oauth2/releases)
- [Changelog](https://github.com/oauth-xx/oauth2/blob/master/CHANGELOG.md)
- [Commits](https://github.com/oauth-xx/oauth2/compare/v1.4.4...v1.4.7)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-19 05:21:59 +00:00
Maikel Linke
f80168fbca Update locales from Transifex 2021-03-19 11:46:30 +11:00
Maikel
16d629e5d2 Merge pull request #7121 from Matt-Yorkley/update-adjustments
Update adjustments
2021-03-19 11:25:22 +11:00
Maikel
cf3b32d712 Merge pull request #7158 from openfoodfoundation/transifex
Transifex
2021-03-19 11:18:10 +11:00
Maikel
c4370f1583 Merge pull request #7045 from jibees/7008-add-automated-tests-for-unit-price
add automated tests for unit price in the shopfront
2021-03-19 11:01:25 +11:00
Matt-Yorkley
77b0e2d23f Update has_many_through on Order
Fixes:

384) Spree::OrderMailer basic behaviour doesn't aggressively escape double quotes in confirmation body
       Failure/Error: adjustments = adjustments.to_a + order.shipment_adjustments.to_a

       ActionView::Template::Error:
         Cannot have a has_many :through association 'Spree::Order#shipment_adjustments' which goes through 'Spree::Order#shipments' before the through association is defined.
       # ./app/helpers/checkout_helper.rb:10:in `checkout_adjustments_for'
       # ./app/views/spree/order_mailer/_order_summary.html.haml:43:in `_app_views_spree_order_mailer__order_summary_html_haml__2911251238692323485_70331958934800'
       # ./app/views/spree/order_mailer/confirm_email_for_customer.html.haml:23:in `_app_views_spree_order_mailer_confirm_email_for_customer_html_haml__3734564010704881256_70331959518520'
       # ./app/mailers/spree/order_mailer.rb:35:in `block in confirm_email_for_customer'
       # ./app/mailers/spree/order_mailer.rb:33:in `confirm_email_for_customer'
       # ./spec/mailers/order_mailer_spec.rb:20:in `block (3 levels) in <top (required)>'
       # ------------------
       # --- Caused by: ---
       # ActiveRecord::HasManyThroughOrderError:
       #   Cannot have a has_many :through association 'Spree::Order#shipment_adjustments' which goes through 'Spree::Order#shipments' before the through association is defined.
       #   ./app/helpers/checkout_helper.rb:10:in `checkout_adjustments_for'
2021-03-18 21:56:37 +00:00
Matt-Yorkley
d5443cf489 Update has_many_through on ShippingMethod
Fixes:

259) Spree::ShippingMethod#shipments can gather all the related shipments
       Failure/Error: expect(shipping_method.shipments).to include(shipment)

       ActiveRecord::HasManyThroughOrderError:
         Cannot have a has_many :through association 'Spree::ShippingMethod#shipments' which goes through 'Spree::ShippingMethod#shipping_rates' before the through association is defined.
       # ./spec/models/spree/shipping_method_spec.rb:190:in `block (3 levels) in <module:Spree>'
2021-03-18 21:56:37 +00:00
Matt-Yorkley
6132f4bf18 Don't pass string to conditional in validation 2021-03-18 21:56:37 +00:00
Luis Ramos
ab18a2e60c [Rails 5] change #process method call args for upgraded rails
Copied from spree a5e14e3313
2021-03-18 21:53:00 +00:00
Matt-Yorkley
a7fd64d7bf Update has_many_through on Schedule 2021-03-18 21:53:00 +00:00
Matt-Yorkley
eb5c37daca Change order of declaration for has_many_through association with it's parent
Fixes:

292) OrderManagement::Subscriptions::ProxyOrderSyncer#sync! when the subscription is not persisted and the schedule includes upcoming oc that closes after ends_at does not create a new proxy order for that oc
       Failure/Error: order_cycle.schedules << schedule

       ActiveRecord::HasManyThroughOrderError:
         Cannot have a has_many :through association 'OrderCycle#schedules' which goes through 'OrderCycle#order_cycle_schedules' before the through association is defined.
       # ./spec/factories.rb:29:in `block (4 levels) in <top (required)>'
       # ./spec/factories.rb:28:in `each'
       # ./spec/factories.rb:28:in `block (3 levels) in <top (required)>'
       # ./engines/order_management/spec/services/order_management/subscriptions/proxy_order_syncer_spec.rb:59:in `block (4 levels) in <module:Subscriptions>'
       # ./engines/order_management/spec/services/order_management/subscriptions/proxy_order_syncer_spec.rb:65:in `block (4 levels) in <module:Subscriptions>'
       # ./engines/order_management/spec/services/order_management/subscriptions/proxy_order_syncer_spec.rb:133:in `block (6 levels) in <module:Subscriptions>'
       # ./engines/order_management/spec/services/order_management/subscriptions/proxy_order_syncer_spec.rb:133:in `block (5 levels) in <module:Subscriptions>'
2021-03-18 21:53:00 +00:00
Matt-Yorkley
ee0da87681 Fix touch call to unsaved object
Failure/Error: enterprise.andand.touch

       ActiveRecord::ActiveRecordError:
         cannot touch on a new or destroyed record object. Consider using persisted?, new_record?, or destroyed? before touching
       # ./app/models/spree/address.rb:155:in `touch_enterprise'
       # ./spec/factories/product_factory.rb:12:in `block (3 levels) in <top (required)>'
       # ./spec/factories/variant_factory.rb:26:in `block (4 levels) in <top (required)>'
       # ./spec/models/spree/variant_spec.rb:9:in `block (2 levels) in <module:Spree>'
2021-03-18 21:53:00 +00:00
Matt-Yorkley
bdbeb2feb8 Require missing dependency in VariantOverride 2021-03-18 21:53:00 +00:00
Andy Brett
80d90700c4 Merge pull request #7142 from coopdevs/tiny-improvement-of-specs
Tiny improvement of specs using OutstandingBalance class
2021-03-18 11:34:52 -07:00
Andy Brett
17143d62d6 Merge pull request #7148 from Matt-Yorkley/bump-cancancan
Bump cancancan to 1.15.0
2021-03-18 11:29:53 -07:00
Andy Brett
23494c918d Merge pull request #7143 from cillian/shorter-transient-data-retention-period
Reduce retention period of Spree state changes and log entries from 6 to 3 months
2021-03-18 11:28:29 -07:00
Matt-Yorkley
479c1ae6e6 Merge pull request #7062 from mkllnk/6327-terms-of-service
Show Terms of Service at checkout if required
2021-03-18 19:16:06 +01:00
Andy Brett
5f9c5c0d90 Merge pull request #7095 from luisramos0/render_plain
Raisl 5 - Render plain and render head
2021-03-18 10:56:48 -07:00
Andy Brett
afa7269f48 Merge branch 'master' into render_plain 2021-03-18 10:53:13 -07:00
Transifex-Openfoodnetwork
92da9b717c Updating translations for config/locales/ar.yml 2021-03-19 04:06:21 +11:00
Andy Brett
577401fca0 add regression spec 2021-03-18 09:18:46 -07:00
Matt-Yorkley
2e20078c05 Delete dead code Order#billing_firstname and Order#billing_lastname
🔥
2021-03-18 15:54:40 +00:00
Andy Brett
97a63edf50 Merge pull request #7096 from luisramos0/rails-5-2-helper
Rails 5.2 add T&Cs helper
2021-03-18 08:16:12 -07:00
Pau Perez
5ee647fd7c Improve specs
Better to rely on a verifying double and reveal our intentions using
`subject` instead.
2021-03-18 15:55:54 +01:00
Pau Pérez Fabregat
a1af16ae72 Merge pull request #7116 from coopdevs/increase-invoice-renderer-coverage
Better test InvoiceRenderer
2021-03-18 15:54:43 +01:00
Pau Pérez Fabregat
72b3dbbf44 Merge pull request #7149 from coopdevs/rearrange-order-updater-specs
Rearrange order updater tests to make them method-centric
2021-03-18 15:53:37 +01:00
Pau Pérez Fabregat
71b902d9d2 Merge pull request #6980 from drummer83/clean-footer
Cleaner and consistent design of front-end footer
2021-03-18 15:53:09 +01:00
Jean-Baptiste Bellet
b8353e0007 Add i18n keys to handle distance_of_time_in_words_to_now result
- This method is already translated thanks to rails-i18n, but it is missing few langages such as 'fr_BE'. Adding those keys makes it possible to have the translation.
 - Adding translations to `en.yml` could be seen as useless (since is already correctly handled by rails-i18n) but this is the way we process i18n issues.
2021-03-18 15:49:31 +01:00
Pau Pérez Fabregat
ec41a571ed Merge pull request #7140 from coopdevs/better-test-subs-mailer
Rearrange and cover balance in subs mailer specs
2021-03-18 15:43:41 +01:00
Jean-Baptiste Bellet
d79c457dae Use native <a /> element to create a mailto link
- Nothing special done by helper method `mail_to` so using a native <a /> element (and it's correctly escaped)
2021-03-18 15:09:21 +01:00
Matt-Yorkley
49f1e44999 Simplify Order#total_tax to cover all taxes from all sources 2021-03-18 14:05:29 +00:00
Matt-Yorkley
2f262f70e1 Update #subject syntax 2021-03-18 13:19:16 +00:00
Matt-Yorkley
6b4de4b3dd Migrate enterprise fees on line items 2021-03-18 13:19:16 +00:00
Matt-Yorkley
bd81289240 Use persisted order is order spec 2021-03-18 13:18:20 +00:00
Matt-Yorkley
2c7d6453ce Fix adjustment test setup in Order spec
Missing order associations...
2021-03-18 13:18:20 +00:00
Matt-Yorkley
9f23bb2203 Update SubscriptionPlacementJob fee deleting 2021-03-18 13:18:20 +00:00
Matt-Yorkley
cafe1b5f1c Update order totals after creating fees
This was being triggered by a callback in Spree::Adjustments before, but now that the adjustable is not the order, it does not get triggered by fees being added to line items...
2021-03-18 13:18:20 +00:00
Matt-Yorkley
62a495a42e Allow line item enterprise fees to be found in EnterpriseFeeSummary report 2021-03-18 13:18:20 +00:00
Matt-Yorkley
526794b32e Refactor CheckoutHelper 2021-03-18 13:18:20 +00:00
Matt-Yorkley
3253ab4616 Fix test setup in CheckoutHelper spec 2021-03-18 13:18:20 +00:00
Matt-Yorkley
4ee0271756 Loosen scope in order enterprise fees tax total method 2021-03-18 13:18:20 +00:00
Matt-Yorkley
f2627dff0b Loosen scope in adjustment spec to include enterprise fees on line items 2021-03-18 13:18:20 +00:00
Matt-Yorkley
a0a787b6ec Delete dead code OrderAdjustmentsFetcher#line_item_adjustments
🎉
2021-03-18 13:18:20 +00:00
Matt-Yorkley
f67a8e4af3 Update and simplify LineItem#price_with_adjustments 2021-03-18 13:18:20 +00:00
Matt-Yorkley
8d4733b3d5 Update EnterpriseFee#clear_all_adjustments 2021-03-18 13:18:20 +00:00
Matt-Yorkley
a768cb2510 Set adjustment "target" (adjustable) to be the line item when adding enterprise fees on line items 2021-03-18 13:18:20 +00:00
Matt-Yorkley
5bbe768827 Update order total in test setup 2021-03-18 13:16:19 +00:00
Matt-Yorkley
bb46df61d4 Simplify Order#total_tax
We get the same value here, but without the three additional database hits to adjustments (both of these values are already present on the order object itself).
2021-03-18 13:16:19 +00:00
Matt-Yorkley
c07a4e6c55 Remove "included_tax" hack from TaxRate
Yay! 🎉

The values of tax amounts stored in adjustments on the order no longer require use of the (deprecated) included_tax field.
2021-03-18 13:16:19 +00:00
Matt-Yorkley
be3e184651 Merge pull request #6973 from Matt-Yorkley/adjustments-line-item-taxes
[Adjustments] Update line item taxes
2021-03-18 11:50:01 +01:00
Matt-Yorkley
3ed8dbe3b3 Merge pull request #7146 from Matt-Yorkley/deprecations
Deprecations
2021-03-18 11:25:14 +01:00
Matt-Yorkley
fea6ca5907 Improve update efficiency in migration 2021-03-18 10:07:16 +00:00
Pau Perez
93bc60664a Fix long lines 2021-03-18 10:00:33 +01:00
Jean-Baptiste Bellet
d8772752da Factorize Unit Price into a single method: displayableUnitPrice
- Code is at a single place
 - No need to import `localizeCurrencyFilter` into Controllers that required unit_prices
 - Add `currencyconfig` into unit_prices_spec as it's now dependant to localizeCurrencyFilter
2021-03-18 09:48:42 +01:00
Jean-Baptiste Bellet
e8a0858f15 Add unit prices into the "Edit variant" form
- Only needs to watch `unit_value_human` and `variant.price` the only two editable field for this form that is related to unit price
 - Add hidden_field_tag to retrieve values into the controller
2021-03-18 09:48:42 +01:00
Jean-Baptiste Bellet
50b0e87722 Move module OFNShared to admin.products
instead of `ofn.admin`
 - `admin.products` is already embeded in `ofn.admin`
 - `OFNShared` needs `mm.foundation` (for tooltipProvider)
2021-03-18 09:48:42 +01:00
Jean-Baptiste Bellet
e137eb724b Readjust height of the question mark icon
- 15px is actually the height of an `<label />` inside a form.
2021-03-18 09:48:42 +01:00
Jean-Baptiste Bellet
945ed5fb78 Avoid NaN on unit price computing 2021-03-18 09:48:42 +01:00
Jean-Baptiste Bellet
5ce558c2db Move value and unit into the same input disabled text field
- Both value and unit of the unit price is now inside the `<input />` text field.
2021-03-18 09:48:42 +01:00
Jean-Baptiste Bellet
c084299b72 Add tests in imperial weight system 2021-03-18 09:48:42 +01:00
Jean-Baptiste Bellet
c8099dc2a4 Do not display unit price value and unit until information is filled
- Display the field but with `null` value
2021-03-18 09:48:32 +01:00
Jean-Baptiste Bellet
fa4974ddb2 React to form changes, compute unit price and display accurate values.
- Add method `processUnitPrice` which is responsible for computing the right unit price, that depends on `price`, `variant_unit_scale`, `variant_unit`, `unit_value` and `variant_unit_name`
 - Watch the needed model to compute the unit price: `product.price` and  `product.variant_unit_name`
 - Add dependencies : UnitPrices and localizeCurrencyFilter
 - Add currencyconfig to spec, as it's needed by localizeCurrencyFilter
 - Put `'ng-controller' => 'unitsCtrl'` to the relevant node.
 - Add new ng-model, as it's needed to watch it in order to compute unit price : `product.price`
 - Finally display the needed information: `product.unit_price_value` and `product.unit_price_unit`
2021-03-18 09:48:32 +01:00
Jean-Baptiste Bellet
8ad3109e95 Pass needed arguments and reorder state machine
- Arguments were misordered and `scale` is needed to compute the denominator.
 - Reorder "state machine" if-else as variant_unit_name is priority and "item" is too.
 - @andrewpbrett I need your review here ;)
 - Still need to test imperial system
2021-03-18 09:48:32 +01:00
Andy Brett
7abb3868fc add UnitPrices service 2021-03-18 09:48:17 +01:00
Jean-Baptiste Bellet
b494cd2f8b Add unit price field to New Product form
- Add a new i18n key for the content of the tooltip:  js.shopfront.unit_price_tooltip.admin
 - Display unit price readonly field near the price field
 - Still fake values, needs to be updated
2021-03-18 09:48:17 +01:00
Jean-Baptiste Bellet
3060670466 Add a key parameter to have possibility of different text inside
- The tooltip between the shopfront and the admin will not be the same
2021-03-18 09:48:17 +01:00
Jean-Baptiste Bellet
daa7cca866 Adjust import to include shared/* between Darkswarm and admin
- Import joyride css file
 - Used by question-mark-with-tooltip used in admin part
2021-03-18 09:48:17 +01:00
Jean-Baptiste Bellet
ec0f99a949 Add joyride-tip-guide css specifications
- Could not add the file itself because of many dependancies are broken the admin part.
 - Just use the strict minimum
2021-03-18 09:48:17 +01:00
Jean-Baptiste Bellet
3fcbb1a5fe Move files from darkswarm to shared
- As this directive is now used by Darkswarm and admin, move files in shared/ folders
 - Needs some css variable in admin part : as question-mark-with-tooltip is used in admin part, it needs some css variable
 - Add own scss variables file with all needed variables for question-mark-icon. Some duplication, but now really independant and shared between both darkswarm and admin.
 - Remove strange border around the button, rendered by chrome when button is focused.
2021-03-18 09:48:17 +01:00
Jean-Baptiste Bellet
429cf4a5cb Create a new angularjs module: OFNShared
- This module could be shared between Darkswarm and admin
 - add this new module to test environment
2021-03-18 09:48:17 +01:00
Jean-Baptiste Bellet
e9b833c27b Add unit test for cart page 2021-03-18 09:40:04 +01:00
Jean-Baptiste Bellet
014ffef16c Add tests about unit price inside the cart sidebar
- Test if the question mark icon is present
 - Click to show the tooltip
 - Another click to hide the tooltip
2021-03-18 09:40:04 +01:00
Jean-Baptiste Bellet
1be1d161d3 Add tests about unit price inside a shopfront
- Test that the unit price wrapper is here
 - Click on the question mark icon and display the tooltip
 - Click outside the question mark icon and hide the toolip
2021-03-18 09:40:04 +01:00
Pau Perez
85446c0dde Rearrange and cover balance in subs mailer specs
This moves them to a more unit-like style where the mailer methods are
the subjects. However, I did so only for the methods that show order
balance and thus we want to be extra sure of their coverage.
2021-03-18 09:18:16 +01:00
Pau Perez
ae9d8020a1 Better test InvoiceRenderer
This required a tiny refactoring to enable injecting the renderer. It'll
make it easier to later add the relevant specs related to the order
balance.
2021-03-18 09:17:44 +01:00
Maikel
33f7fa7e32 Merge pull request #7111 from coopdevs/fix-static-assets-deprecation
Replace assets config with public_file_server
2021-03-18 13:44:30 +11:00
Maikel
e53c996efd Merge pull request #7082 from openfoodfoundation/dependabot/bundler/i18n-1.8.9
Bump i18n from 1.8.5 to 1.8.9
2021-03-18 13:23:08 +11:00
Matt-Yorkley
751b9349e8 Merge pull request #7015 from andrewpbrett/shopfront-producers
Only show primary producers on shopfront list of producers (fix #4218)
2021-03-17 23:30:42 +01:00
Matt-Yorkley
e62cf67be5 Add more defensive code in TaxRateFinder 2021-03-17 22:23:04 +00:00
Matt-Yorkley
baaee1baab Update OrderAdjustmentsFetcher 2021-03-17 22:23:04 +00:00
Matt-Yorkley
064f7582cc Update line_item included taxes
Drops use of the `spree_adjustments.included_tax` database field (when summing line item tax), which we are slowly deprecating before eventual removal
2021-03-17 22:23:04 +00:00
Andy Brett
70b7143e7b reload line items and recalculate fees after removing line item 2021-03-17 12:06:05 -07:00
Matt-Yorkley
8503e3c5f3 Merge pull request #7023 from Matt-Yorkley/ineligible-efficiency
Reduce unnecessary updates in Payment#revoke_adjustment_eligibility
2021-03-17 18:55:01 +01:00
Andy Brett
b8629e847c Merge pull request #7014 from andrewpbrett/canceled-order-payments
Add resumed to list of allowable order states to view the payment tab
2021-03-17 10:46:51 -07:00
Andy Brett
12b66d82ab verify line item when placing sub order
This removes the inventory unit from the shipment manifest, so that the item no longer appears on the order view in the admin view.
2021-03-17 09:35:01 -07:00
Andy Brett
9d33b36799 Merge pull request #7024 from Matt-Yorkley/dead-code-auto-capture
DCOTW: Spree::Config[:auto_capture]
2021-03-17 09:31:00 -07:00
Matt-Yorkley
826515874b Replace some uses of #alias_method_chain 2021-03-17 16:28:19 +00:00
Luis Ramos
333a488dc8 Fix deprecation warning 2021-03-17 16:23:53 +00:00
Pau Perez
b48677c624 Rearrange tests to make them method-centric
If these are unit tests, it's much easier to find a `describe` with the
method under test and putting all the tests exercising that method
together.

It turns out that `#update_payment_state` is by far the method that we
test the most which leads me to think:

a) this class might be doing too many things.
b) other methods might not be that well covered.
2021-03-17 17:05:19 +01:00
Matt-Yorkley
fbff481a8b Bump cancancan
Conservative bump to a newer version that fixes some deprecated syntax for Rails 5.x (eg #before_filter)
2021-03-17 15:37:15 +00:00
Andy Brett
cd988733c3 Merge pull request #7145 from coopdevs/temp-skip-flaky-spec
Temporarily skip embedded shopfront flaky spec
2021-03-17 08:33:53 -07:00
Matt-Yorkley
39b1ae0ee8 Fix validation conditional in Spree::Product 2021-03-17 15:22:22 +00:00
Luis Ramos
da6a7da99d Remove sanitize
This was added here for no specific reason I think, it's just an id, I dont think we need this 1d83809866
2021-03-17 15:22:22 +00:00
Matt-Yorkley
29e0786906 Fix inheritance of Migration object in spec
Fixes:

Spree::Preferences::Preferable persisted preferables requires a valid id but returns default values
       Failure/Error:
               class CreatePrefTest < ActiveRecord::Migration
                 def self.up
                   create_table :pref_tests do |t|
                     t.string :col
                   end
                 end

                 def self.down
                   drop_table :pref_tests
                 end

       StandardError:
         Directly inheriting from ActiveRecord::Migration is not supported. Please specify the Rails release the migration was written for:

           class CreatePrefTest < ActiveRecord::Migration[4.2]
       # ./spec/models/spree/preferences/preferable_spec.rb:225:in `block (3 levels) in <top (required)>'
2021-03-17 15:22:22 +00:00
Matt-Yorkley
4505fa7fd9 Fix warning on Product variants_including_master scope 2021-03-17 15:22:22 +00:00
Matt-Yorkley
55b0751c1a Use strings for class names on associations 2021-03-17 15:15:57 +00:00
Matt-Yorkley
237075dd47 Replace deprecated before_filter syntax 2021-03-17 15:15:26 +00:00
Matt-Yorkley
6c19baeab3 Remove transactional callback config 2021-03-17 15:15:20 +00:00
Pau Pérez Fabregat
571f1b9f87 Merge pull request #7122 from openfoodfoundation/transifex
Transifex
2021-03-17 16:08:49 +01:00
Pau Perez
cf730f8b0c Temporarily skip embedded shopfront flaky spec
Closes #7129 as discussed on that issue.
2021-03-17 16:06:48 +01:00
Andy Brett
9aa992b700 Merge pull request #7067 from openfoodfoundation/dependabot/bundler/rspec-rails-4.1.2
Bump rspec-rails from 4.0.2 to 4.1.2
2021-03-17 07:46:59 -07:00
Pau Perez
8c57ccdaf9 Replace assets test config with public_file_server
This fixes the following deprecation warnings

```
DEPRECATION WARNING: `config.serve_static_files` is deprecated and will be removed in Rails 5.1.
Please use `config.public_file_server.enabled = true` instead.
 (called from block in <top (required)> at /home/runner/work/openfoodnetwork/openfoodnetwork/config/environments/test.rb:13)
DEPRECATION WARNING: `config.static_cache_control` is deprecated and will be removed in Rails 5.1.
Please use
`config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' }`
instead.
 (called from block in <top (required)> at /home/runner/work/openfoodnetwork/openfoodnetwork/config/environments/test.rb:14)
```
2021-03-17 15:43:31 +01:00
Andy Brett
1311ff2959 Merge pull request #7136 from coopdevs/better-test-order-mailer
Rearrange and extend some OrderMailer unit-tests
2021-03-17 07:33:27 -07:00
Cillian O'Ruanaidh
a80e1b7625 Reduce retention period of Spree state changes and log entries from 6 to 3 months
The UK instance noticed Spree state changes and log entries seem to be filling up quite quickly.

Fixes #7123
2021-03-17 12:12:45 +00:00
Matt-Yorkley
3a5f763bf2 Merge pull request #7107 from filipefurtad0/line_items_controller.spec
covers payment_state changes from item deletion
2021-03-17 12:50:52 +01:00
Transifex-Openfoodnetwork
736a628082 Updating translations for config/locales/en_IE.yml 2021-03-17 22:31:32 +11:00
Pau Perez
f56678bcd9 Rearrange and extend some OrderMailer unit-tests
This moves them to a more unit-like style where the mailer methods are
the subjects. However, I did so only for the methods that show order
balance and thus we want to be extra sure of their coverage.
2021-03-17 12:09:06 +01:00
Pau Pérez Fabregat
51f63060a4 Merge pull request #6879 from coopdevs/customer-balance-bulk-coop-report
Customer balance bulk coop report
2021-03-17 12:08:44 +01:00
Pau Pérez Fabregat
0a1a1c3567 Merge pull request #7137 from andrewpbrett/ci-timezones
Fix failing timezone-related specs
2021-03-17 12:03:39 +01:00
Maikel
3a0c9814b8 Merge pull request #7037 from openfoodfoundation/dependabot/bundler/awesome_print-1.9.2
Bump awesome_print from 1.8.0 to 1.9.2
2021-03-17 17:26:22 +11:00
Luis Ramos
c4c5bbc9a3 Adapt helpers to rails 5.2 2021-03-16 23:37:24 +00:00
Luis Ramos
32c68f5951 Adapt helper call to make it work in rails 5.2 2021-03-16 23:37:24 +00:00
Luis Ramos
f55150745e Add checkout helper to checkout controller 2021-03-16 23:37:24 +00:00
Luis Ramos
d4cbf47226 Add T and Cs helper to checkout controller 2021-03-16 23:37:24 +00:00
Luis Ramos
25e0262364 Adapt spec to new rspec syntax with params and no xhr 2021-03-16 23:31:43 +00:00
Luis Ramos
f710bbed3e Convert calls to xhr to post or put with xhr: true 2021-03-16 23:31:43 +00:00
Luis Ramos
58c3c49cfb Adapt to new rspec syntax 2021-03-16 23:31:43 +00:00
Luis Ramos
c5581fa25f Rename spec/support/CheckoutHelper to resolve colision with app/helpers/CheckoutHelper 2021-03-16 23:20:11 +00:00
Luis Ramos
a953a12f76 Remove dead code 2021-03-16 23:20:11 +00:00
Luis Ramos
138522bd17 Add helper to view spec to make it work in rails 5 2021-03-16 23:20:11 +00:00
Luis Ramos
cb8fd2131e Use body: nil instead of deprecated nothing:
Ideally we would be using render head status but it's issuing quite a lot of double render problems, we can improve later
2021-03-16 23:13:58 +00:00
Luis Ramos
53d758ca21 Replace render text with render plain for rails 5.1 2021-03-16 23:13:58 +00:00
dependabot[bot]
4adaa6d28d Bump rspec-rails from 4.0.2 to 4.1.2
Bumps [rspec-rails](https://github.com/rspec/rspec-rails) from 4.0.2 to 4.1.2.
- [Release notes](https://github.com/rspec/rspec-rails/releases)
- [Changelog](https://github.com/rspec/rspec-rails/blob/main/Changelog.md)
- [Commits](https://github.com/rspec/rspec-rails/compare/v4.0.2...v4.1.2)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-16 22:33:54 +00:00
dependabot[bot]
7f594026cd Bump awesome_print from 1.8.0 to 1.9.2
Bumps [awesome_print](https://github.com/awesome-print/awesome_print) from 1.8.0 to 1.9.2.
- [Release notes](https://github.com/awesome-print/awesome_print/releases)
- [Changelog](https://github.com/awesome-print/awesome_print/blob/master/CHANGELOG.md)
- [Commits](https://github.com/awesome-print/awesome_print/compare/v1.8.0...v1.9.2)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-16 22:32:03 +00:00
filipefurtad0
2e870ed7bc replace update! w/ reload; remove assertion 2021-03-16 22:02:26 +00:00
filipefurtad0
87e4b5e49d covers payment_state changes from item deletion 2021-03-16 22:02:26 +00:00
dependabot[bot]
6ebcff9a4a Bump i18n from 1.8.5 to 1.8.9
Bumps [i18n](https://github.com/ruby-i18n/i18n) from 1.8.5 to 1.8.9.
- [Release notes](https://github.com/ruby-i18n/i18n/releases)
- [Changelog](https://github.com/ruby-i18n/i18n/blob/master/CHANGELOG.md)
- [Commits](https://github.com/ruby-i18n/i18n/compare/v1.8.5...v1.8.9)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-16 19:32:53 +00:00
Andy Brett
06deab9605 Merge pull request #7084 from openfoodfoundation/dependabot/bundler/acts-as-taggable-on-7.0.0
Bump acts-as-taggable-on from 4.0.0 to 7.0.0
2021-03-16 12:31:58 -07:00
Matt-Yorkley
d64fd195c0 Merge pull request #7104 from openfoodfoundation/dependabot/bundler/compass-rails-4.0.0
Bump compass-rails from 2.0.1 to 4.0.0
2021-03-16 20:31:49 +01:00
Andy Brett
046a2077f2 check the time, not the printed zone, in the spec 2021-03-16 12:14:27 -07:00
Andy Brett
f9f1bf8331 specify UTC explicitly 2021-03-16 12:00:20 -07:00
Andy Brett
134e017122 Merge pull request #7085 from openfoodfoundation/dependabot/bundler/responders-3.0.1
Bump responders from 2.4.1 to 3.0.1
2021-03-16 11:24:28 -07:00
dependabot[bot]
b1b71483de Bump responders from 2.4.1 to 3.0.1
Bumps [responders](https://github.com/heartcombo/responders) from 2.4.1 to 3.0.1.
- [Release notes](https://github.com/heartcombo/responders/releases)
- [Changelog](https://github.com/heartcombo/responders/blob/master/CHANGELOG.md)
- [Commits](https://github.com/heartcombo/responders/compare/v2.4.1...v3.0.1)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-16 17:57:43 +00:00
Matt-Yorkley
0f05198f48 Update any adjustments that are missing an order association 2021-03-16 17:45:11 +00:00
Andy Brett
0d364c6b69 Merge pull request #7110 from Matt-Yorkley/payment-capture-error
Fix payment capture handling in Api::OrdersController
2021-03-16 10:41:43 -07:00
Matt-Yorkley
2ba6a3cc23 Merge pull request #7133 from coopdevs/fix-env-deprecation
Fix `env` deprecated in Rails 5.0
2021-03-16 18:29:40 +01:00
Andy Brett
3ff9a0f2a3 Merge pull request #7135 from Matt-Yorkley/paypal-spec-setup
Update order totals in paypal test setup
2021-03-16 10:22:48 -07:00
Andy Brett
76940a6a2e Merge pull request #7134 from coopdevs/feature-test-payments-report
Feature-test payments report
2021-03-16 10:18:36 -07:00
Matt-Yorkley
c91f02a94a Update order totals in paypal test setup 2021-03-16 16:52:30 +00:00
Andy Brett
e8a256ecc5 Merge pull request #7132 from Matt-Yorkley/reload-deprecations
Replace deprecated use of :reload argument
2021-03-16 09:31:24 -07:00
Pau Perez
16647006c6 Feature-test payments report
This report displays order balances and we'll need this basic
feature-test coverage to ensure it keeps working once we refactor them.
2021-03-16 17:05:31 +01:00
Andy Brett
b0f2688001 Merge pull request #7128 from jibees/7127-terms-&-conditions-test-fails
Use timezone as hour and minute offset from UTC in terms_and_conditions_spec.rb
2021-03-16 08:34:18 -07:00
Pau Perez
57101aa5b6 Fix env deprecated in Rails 5.0
I found it at the very bottom of the `test-consumer-features` CI build
job. See: https://github.com/rails/rails/issues/23294.
2021-03-16 15:12:44 +01:00
Matt-Yorkley
e78fb784c6 Merge pull request #7042 from coopdevs/fix-money-object-deprecation-warnings
Fix money object deprecation warnings
2021-03-16 14:30:51 +01:00
Matt-Yorkley
5e8d231c49 Merge pull request #7113 from coopdevs/fix-reload-deprecation-on-user-112
Fix deprecation warning related to #reload
2021-03-16 14:25:18 +01:00
Matt-Yorkley
80a654cef1 Merge pull request #6938 from Matt-Yorkley/paypal-adjustments-coverage
[Adjustments] Paypal adjustments test coverage
2021-03-16 13:16:07 +01:00
Matt-Yorkley
2d9d293405 Replace deprecated use of :reload argument 2021-03-16 12:04:35 +00:00
Jean-Baptiste Bellet
57a65da674 Use timezone as hour and minute offset from UTC
- e.g. +0900 (and not e.g. +09:00)
2021-03-16 09:52:45 +01:00
Pau Perez
6fae80bb04 Fix deprecation warning related to #reload
This fixes:

```
DEPRECATION WARNING: Passing an argument to force an association to
reload is now deprecated and will be removed in Rails 5.1. Please call
`reload` on the result collection proxy instead. (called from
can_own_more_enterprises? at /usr/src/app/app/models/spree/user.rb:112)
```

This method in particular gets called a lot of times so it'll have it's
cost in performance.
2021-03-16 08:01:25 +01:00
Andy Brett
fbc0d8f352 Merge pull request #7125 from coopdevs/show-build-status-in-prs
Run Github CI build on pull_request event
2021-03-15 15:30:26 -07:00
Andy Brett
ae4e8386c4 Merge pull request #7019 from openfoodfoundation/dependabot/bundler/monetize-1.11.0
Bump monetize from 1.10.0 to 1.11.0
2021-03-15 15:13:27 -07:00
Andy Brett
ffe9d4737c Merge pull request #7114 from coopdevs/extract-spec-file
Move invoice-related specs to their own file
2021-03-15 15:11:14 -07:00
Pau Perez
e952664a14 Run build on pull_request event
As is, we're seeing builds almost only on merge commits and not on
others. Also, the build status is not displayed at the bottom of the
PR.

Once we see this fixed and have a better understanding, we can decide
whether or not we remove the `push` event. I guess both we'll be needed.
2021-03-15 20:06:15 +01:00
Transifex-Openfoodnetwork
eb9cf04071 Updating translations for config/locales/fr_CA.yml 2021-03-16 04:22:30 +11:00
Transifex-Openfoodnetwork
e55457d9dd Updating translations for config/locales/en_CA.yml 2021-03-16 04:13:10 +11:00
Transifex-Openfoodnetwork
aeefd068bf Updating translations for config/locales/en_CA.yml 2021-03-16 03:58:49 +11:00
Pau Perez
7a3121b624 Move invoice-related specs to their own file
The `Spree::Admin::OrdersController`'s test file quite long (as well as
the controller itself) but it'll grow more in the upcoming commits.
That's just a symptom of that controller having too many
responsibilities. It does much more than CRUD on `Spree::Order` (the
Rails convention).

Things like invoices are an entity on their own and would better fit
into a `InvoicesController`. Hopefully, splitting up the tests is hint
for the next dev to do that.
2021-03-15 12:45:27 +01:00
Matt-Yorkley
5354c63d9a Fix payment capture handling in Api::OrdersController
Fixes:

NoMethodError: undefined method `t' for #<Api::OrdersController:0x0000000013834290>
Location
app/controllers/api/orders_controller.rb:50 - payment_capture_failed
2021-03-15 10:36:07 +00:00
dependabot[bot]
1fcc77dbe7 Bump acts-as-taggable-on from 4.0.0 to 7.0.0
Bumps [acts-as-taggable-on](https://github.com/mbleigh/acts-as-taggable-on) from 4.0.0 to 7.0.0.
- [Release notes](https://github.com/mbleigh/acts-as-taggable-on/releases)
- [Changelog](https://github.com/mbleigh/acts-as-taggable-on/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mbleigh/acts-as-taggable-on/compare/v4.0.0...v7.0.0)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-14 18:47:23 +00:00
dependabot[bot]
492858ae1f Bump compass-rails from 2.0.1 to 4.0.0
Bumps [compass-rails](https://github.com/Compass/compass-rails) from 2.0.1 to 4.0.0.
- [Release notes](https://github.com/Compass/compass-rails/releases)
- [Changelog](https://github.com/Compass/compass-rails/blob/master/CHANGELOG.md)
- [Commits](https://github.com/Compass/compass-rails/commits)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-14 14:21:13 +00:00
dependabot[bot]
431536e8a6 Bump monetize from 1.10.0 to 1.11.0
Bumps [monetize](https://github.com/RubyMoney/monetize) from 1.10.0 to 1.11.0.
- [Release notes](https://github.com/RubyMoney/monetize/releases)
- [Changelog](https://github.com/RubyMoney/monetize/blob/main/CHANGELOG.md)
- [Commits](https://github.com/RubyMoney/monetize/commits/v1.11.0)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-14 14:21:03 +00:00
Maikel Linke
06f46c4e29 Remove unnecessary comments 2021-03-11 11:18:12 +11:00
Pau Perez
0eb14bc0a4 Do not modify the HTML returned by Money gem
It was due to these lines that we were returning a broken HTML tag but
also, there's no need to remove blanks.
2021-03-10 16:29:09 +01:00
Maikel Linke
20f11327b5 Show combined checkbox when all terms required
The user should need to tick only one box to agree.

We don't remember yet if someone agreed to the platform TOS and
therefore the box is always unticked to start with.

Remembering the agreement is another issue:
https://github.com/openfoodfoundation/openfoodnetwork/issues/6328
2021-03-10 17:09:26 +11:00
Maikel Linke
f73c32ce4b Move rendering logic of terms to helper
Preparing for a third option to display.
2021-03-10 17:09:26 +11:00
Maikel Linke
4af0e61163 Simplify logic for terms and conditions display
Checking for `false` instead of a falsey value allows us to distinguish
from an unset variable and disable the checkout button only when a
checkbox is present and unticked.
2021-03-10 17:09:26 +11:00
Maikel Linke
b266c9df34 Enable checkout button only when terms accepted
This was working with the seller's terms but now it includes the
platform's terms as well.

Pending:

- Simplify Ansible code
- Unify the two terms checkboxes if both required
2021-03-10 17:09:26 +11:00
Maikel Linke
2149ce7c94 Reduce run time of specs by combining them
It's better style to have those specs independent but we also have a
need for fast tests.
2021-03-10 17:09:26 +11:00
Maikel Linke
561da1f834 Show Terms of Service at checkout if required
The checkout page shows a checkbox to accept the platform's Terms of
Service. Ticking the box doesn't have any effect yet but at least people
are aware and are presented with a link to the terms.
2021-03-10 17:09:26 +11:00
Maikel Linke
0e8745adc3 Remove passing of unused variable 2021-03-10 17:09:26 +11:00
Maikel Linke
ee66a096e2 Ignore uploaded Ts&Cs for version control
We do that for other uploaded files already.
2021-03-10 17:09:26 +11:00
Maikel Linke
ba9de403e6 Add admin option to require shoppers agree to TOS
This switch doesn't have any effect yet. We need to implement it in the
checkout.
2021-03-10 17:09:26 +11:00
Pau Perez
9c642e2957 Use the instance currency as Money's default 2021-03-09 09:00:37 +01:00
Andy Brett
0125b5f10e add spec for plus_relatives_and_oc_producers 2021-03-08 09:10:40 -08:00
Andy Brett
95c232dfe7 add spec for a resumed order 2021-03-08 08:54:28 -08:00
Pau Perez
5c74668726 Make test rely on container rather than parent
This decouples it a bit from the actual HTML markup and makes it a bit
more resilient.
2021-03-08 16:20:07 +01:00
Pau Perez
7792bc34c8 Test that currency symbol position can be changed 2021-03-08 13:40:00 +01:00
Pau Perez
ca268d5c84 Remove unnecessary indirection in test 2021-03-08 13:34:57 +01:00
Pau Perez
41011ce28a Fix Money deprecation warning w/ :default_currency
This removes the deprecation warning:

```
[WARNING] The default currency will change from `USD` to `nil` in the
next major release. Make sure to set it explicitly using
`Money.default_currency=` to avoid potential issues
```
2021-03-08 13:03:00 +01:00
Pau Perez
ccfb6ae26e Fix Money deprecation warning with :rounding_mode
This removes the deprecation warning:

```
[WARNING] The default rounding mode will change from `ROUND_HALF_EVEN`
to `ROUND_HALF_UP` in the next major release. Set it explicitly using
`Money.rounding_mode=` to avoid potential problems.
```

by specifying the default rounding mode at boot time so that it's only
set once for the whole app. See
https://github.com/RubyMoney/money#rounding for details.
2021-03-08 13:03:00 +01:00
Pau Perez
96bcde61a3 Fix Money deprecation warning with :html_wrap
This fixes the following deprecation warning

```
[DEPRECATION] `html` is deprecated - use `html_wrap` instead. Please
note that `html_wrap` will wrap all parts of currency and if you use
`with_currency` option, currency element class changes from `currency`
to `money-currency`.
```
2021-03-08 13:03:00 +01:00
Pau Perez
485449e289 Fix Money gem deprecation warning with :format
This removes millions of deprecation warnings like the following

```
[DEPRECATION] `symbol_position: :before` is deprecated - you can replace it with `format: %u %n`
```

from the build. It gets printed every time a `Spree::Money` is instantiated.

This should result in a non-negligible speed up of the test suite.
2021-03-08 13:03:00 +01:00
Pau Perez
e355a00724 Remove redundant spec context
This is already tested by the top-most before block and besides, we
there's no OFN in Japan. We don't need to test all supported currencies
but ensure that the various arguments work as intended.
2021-03-08 12:52:41 +01:00
Matt-Yorkley
365700615a Remove dead code: Spree::Config.auto_capture
We set this value to `true` unconditionally in an initializer, and then check the value in various places via Spree::Config. It's never false, and it's not configurable, so we can just drop it and remove the related conditionals. 🔥
2021-03-05 16:03:07 +00:00
Matt-Yorkley
a670771037 Reduce duplicate updates in Payment#revoke_adjustment_eligibility
This was triggering two separate updates, and each of those updates could trigger callbacks, and those could trigger other callbacks. Here we're doing the same thing, but with one update.
2021-03-05 15:12:41 +00:00
Andy Brett
a431c03eb1 only show primary producers on shopfront list of producers 2021-03-04 14:32:55 -08:00
Andy Brett
4e5945f9ef add resumed to list of allowable order states 2021-03-04 11:24:39 -08:00
Konrad
748b2b8223 Removed #secure and replaced with class 2021-03-03 20:59:30 +01:00
Konrad
db6eaede14 Shortened long line 2021-03-03 20:58:45 +01:00
Konrad
aa761d6d67 Removed #secure and replaced with class 2021-03-03 20:57:55 +01:00
Konrad
07b23602cd Included #secure and method show_social_icons? 2021-03-03 20:38:12 +01:00
Konrad
e0108431d9 Added method to check for social icons 2021-03-03 20:36:22 +01:00
Konrad
553954f8bf Removed "footer .row a" and added "#secure" 2021-03-03 20:35:16 +01:00
Pau Perez
b49777062b Include canceled orders in report when searching
It's a code smell to have a boolean control argument.
`Permissions::Order` goes too far and assumes we want to filter out
canceled orders when using report's search params and this is not the
case.
2021-03-03 18:21:44 +01:00
Pau Perez
f67b45a580 Reuse query object in Reports::LineItems
This almost removes the responsibility of fetching orders from this
class, that has too many. Ideally, I'd go on and leave this up to the
caller of this class making `Reports::LineItems` rely completely on the
passed in `orders_relation`. Not today.
2021-03-03 18:21:43 +01:00
Pau Perez
21fb3f3da6 Extract orders relation as a query object 2021-03-03 18:21:10 +01:00
Pau Perez
72597ea3f9 Optionally inject orders relation
So we can fetch them differently if we need to. Spoiler: we do in the
bulk coop report.
2021-03-03 18:21:07 +01:00
Pau Perez
2ead2ad417 Replace private stub with fake collaborator object 2021-03-03 18:19:26 +01:00
Pau Perez
b6ce9ca3ca Test bulk coop report includes canceled orders
Without them numbers in the report don't match with /admin/customers and
/account where their order total is considered towards the customer
balance.
2021-03-03 18:19:26 +01:00
Pau Perez
fce98da88d Reject line items in a more succinct way
Thanks for the suggestion @mkllnk!
2021-03-03 18:19:26 +01:00
Pau Perez
3b7f45516c Toggle bulk coop report balance calculation
This will make users hit the new method that implements the new
calculation we are aiming for, only if they have the feature enabled.
2021-03-03 18:19:26 +01:00
Pau Perez
cd60cea5de Extract balance-related methods into module
This model concerns helps us put together this related methods. Although
it doesn't provide any encapsulation yet, it makes a bit easier to
consider them all next time we need to change this implementation
somehow. It's a bit of an illusion but it feels like we are making this
God object model a bit smaller.

It also gives more room for documentation that will aid future devs.
2021-03-03 18:19:26 +01:00
Pau Perez
d1fde07535 Extend #outstanding_balance to mimic OustandingBalance 2021-03-03 18:19:26 +01:00
Pau Perez
c69f0baf9f Extract specs related to outstanding_balance 2021-03-03 18:19:26 +01:00
Pau Perez
d00a35e12c Split long statement 2021-03-03 18:19:26 +01:00
Pau Perez
b7335e12e9 Add first basic unit test to Reports::LineItems
This is quite hard and tedious due to its tight coupling with
Permissions::Order but sets the path to adding more of these and
eventually refactoring this class in the future.
2021-03-03 18:19:26 +01:00
Pau Perez
197d787396 Unit-test OrderDataMasker 2021-03-03 18:19:26 +01:00
Pau Perez
58ffd00f4a Extract private method
This was initially intended to cache the result of the `#map` and
`#uniq` calls but we're not confident enough and don't want to
scopecreep this. It's still worth to point out that this is what we
need, line items' `unique orders`. Hopefully, next time we find a way to
optimize it.
2021-03-03 18:19:26 +01:00
Pau Perez
49dfccfb51 Unit test #columns method
At least, this covers what we're investigating now.
2021-03-03 18:19:26 +01:00
Pau Perez
a3b2a25ccf Refactor and reuse :not_state scope 2021-03-03 18:19:26 +01:00
Konrad
3d8cfc4ccd Updated footer for clean footer
Updated the footer to have precise alignment of elements and consistent font sizes throughout the front-end footer.
2021-03-01 20:47:36 +01:00
Konrad
799d35f187 Updated stylesheets for clean footer
Updated the stylesheets to have precise alignment fo elements and consistent font sizes throughout the front-end footer.
2021-03-01 20:44:22 +01:00
Matt-Yorkley
faf7e3c02b Simplify filtering items with zero price 2021-02-24 12:39:10 +00:00
Matt-Yorkley
02b3636377 Extract relevant adjustments to comment-method 2021-02-24 12:39:10 +00:00
Matt-Yorkley
d517e5adf6 Simplify matching 2021-02-22 16:03:27 +00:00
Matt-Yorkley
ecf4332527 Use #all_adjustments scope
Some of the way these objects are returned by different scopes will be changing soon. This ensures we should get the same results.
2021-02-22 16:03:26 +00:00
Matt-Yorkley
20f4a5359e Exclude all tax adjustments in item building
Included taxes are ignored here, and the additional tax total is is handled separately.
2021-02-22 16:02:19 +00:00
Matt-Yorkley
3ac16432c7 Refactor data representation methods 2021-02-22 16:02:19 +00:00
Matt-Yorkley
8de5ac4680 Extract itemized contents to service 2021-02-22 16:02:19 +00:00
Matt-Yorkley
eaf9305a77 Simplify adjustments summing 2021-02-22 15:45:32 +00:00
Matt-Yorkley
40d284812a Extract itemized contents to testable method 2021-02-22 13:12:04 +00:00
288 changed files with 5053 additions and 2655 deletions

View File

@@ -3,11 +3,54 @@ name: Build
on:
workflow_dispatch:
push:
pull_request:
env:
DISABLE_KNAPSACK: true
TIMEZONE: UTC
jobs:
test-controllers-and-serializers:
runs-on: ubuntu-18.04
services:
postgres:
image: postgres:10
ports: ["5432:5432"]
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
POSTGRES_DB: open_food_network_test
POSTGRES_USER: ofn
POSTGRES_PASSWORD: f00d
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- uses: actions/setup-node@v2
with:
node-version: '14.15.5'
- name: Install JS dependencies
run: yarn install --frozen-lockfile
- name: Set up application.yml
run: cp config/application.yml.example config/application.yml
- name: Set up database
run: |
bundle exec rake db:create RAILS_ENV=test
bundle exec rake db:schema:load RAILS_ENV=test
- name: Run controller tests
run: bundle exec rspec --profile -- spec/controllers spec/serializers
test-models:
runs-on: ubuntu-18.04
services:
@@ -47,9 +90,9 @@ jobs:
bundle exec rake db:schema:load RAILS_ENV=test
- name: Run tests
run: bundle exec rspec spec/models
run: bundle exec rspec --profile -- spec/models
test-admin-features:
test-admin-features-1:
runs-on: ubuntu-18.04
services:
postgres:
@@ -88,9 +131,9 @@ jobs:
bundle exec rake db:schema:load RAILS_ENV=test
- name: Run admin feature tests
run: bundle exec rspec --profile -- spec/features/admin/*_spec.rb
run: bundle exec rspec --profile -- spec/features/admin/[a-o0-9]*_spec.rb
test-admin-features-folders:
test-admin-features-2:
runs-on: ubuntu-18.04
services:
postgres:
@@ -129,7 +172,7 @@ jobs:
bundle exec rake db:schema:load RAILS_ENV=test
- name: Run admin feature tests
run: bundle exec rspec --profile --pattern "spec/features/admin/*/*_spec.rb"
run: bundle exec rspec --profile -- spec/features/admin/[p-z]*_spec.rb
test-consumer-features:
runs-on: ubuntu-18.04
@@ -172,48 +215,7 @@ jobs:
- name: Run consumer feature tests
run: bundle exec rspec --profile -- spec/features/consumer
test-controllers:
runs-on: ubuntu-18.04
services:
postgres:
image: postgres:10
ports: ["5432:5432"]
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
POSTGRES_DB: open_food_network_test
POSTGRES_USER: ofn
POSTGRES_PASSWORD: f00d
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- uses: actions/setup-node@v2
with:
node-version: '14.15.5'
- name: Install JS dependencies
run: yarn install --frozen-lockfile
- name: Set up application.yml
run: cp config/application.yml.example config/application.yml
- name: Set up database
run: |
bundle exec rake db:create RAILS_ENV=test
bundle exec rake db:schema:load RAILS_ENV=test
- name: Run tests
run: bundle exec rspec spec/controllers
test-other:
test-engines-etc:
runs-on: ubuntu-18.04
services:
postgres:
@@ -255,19 +257,45 @@ jobs:
run: RAILS_ENV=test bundle exec rake karma:run
- name: Run all other tests
run: |
bundle exec rspec \
spec/helpers/ \
spec/initializers/ \
spec/jobs/ \
spec/lib/ \
spec/mailers/ \
spec/queries/ \
spec/requests/ \
spec/serializers/ \
spec/services/ \
spec/validators/ \
spec/views
run: bundle exec rake ofn:specs:run:excluding_folders["models,controllers,serializers,features,lib"]
- name: Run engines tests
run: bundle exec rake ofn:specs:engines:rspec
test-the-rest:
runs-on: ubuntu-18.04
services:
postgres:
image: postgres:10
ports: ["5432:5432"]
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
POSTGRES_DB: open_food_network_test
POSTGRES_USER: ofn
POSTGRES_PASSWORD: f00d
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- uses: actions/setup-node@v2
with:
node-version: '14.15.5'
- name: Install JS dependencies
run: yarn install --frozen-lockfile
- name: Set up application.yml
run: cp config/application.yml.example config/application.yml
- name: Set up database
run: |
bundle exec rake db:create RAILS_ENV=test
bundle exec rake db:schema:load RAILS_ENV=test
- name: Run admin feature folders, engines, lib
run: bundle exec rspec --profile --pattern "engines/*/spec/{,/*/**}/*_spec.rb,spec/features/admin/*/*_spec.rb,spec/lib/{,/*/**}/*_spec.rb"

1
.gitignore vendored
View File

@@ -31,6 +31,7 @@ app/public
public/system
public/stylesheets
public/images
public/files
public/spree
public/assets
config/abr.yml

View File

@@ -21,6 +21,25 @@
Layout/LineLength:
Max: 100
Exclude:
- app/controllers/spree/admin/products_controller.rb
- app/controllers/spree/admin/reports_controller.rb
- app/controllers/spree/paypal_controller.rb
- engines/order_management/spec/services/order_management/order/stripe_sca_payment_authorize_spec.rb
- engines/order_management/spec/services/order_management/order/updater_spec.rb
- engines/order_management/spec/services/order_management/reports/bulk_coop/bulk_coop_report_spec.rb
- lib/open_food_network/reports/line_items.rb
- spec/controllers/spree/admin/orders/invoices_spec.rb
- spec/controllers/spree/admin/tax_rates_controller_spec.rb
- spec/controllers/user_passwords_controller_spec.rb
- spec/features/admin/configuration/general_settings_spec.rb
- spec/features/consumer/shopping/unit_price_spec.rb
- spec/helpers/admin/orders_helper_spec.rb
- spec/lib/open_food_network/order_cycle_management_report_spec.rb
- spec/lib/stripe/authorize_response_patcher_spec.rb
- spec/services/bulk_invoice_service_spec.rb
- spec/services/content_sanitizer_spec.rb
- spec/services/process_payment_intent_spec.rb
- spec/support/features/datepicker_helper.rb
- app/controllers/admin/bulk_line_items_controller.rb
- app/controllers/admin/contents_controller.rb
- app/controllers/admin/customers_controller.rb
@@ -329,6 +348,29 @@ Layout/LineLength:
Metrics/AbcSize:
Max: 15
Exclude:
- app/controllers/admin/schedules_controller.rb
- app/controllers/checkout_controller.rb
- app/controllers/spree/admin/general_settings_controller.rb
- app/controllers/spree/admin/images_controller.rb
- app/controllers/spree/admin/mail_methods_controller.rb
- app/controllers/spree/admin/shipping_methods_controller.rb
- app/controllers/spree/paypal_controller.rb
- app/helpers/spree/base_helper.rb
- app/jobs/subscription_placement_job.rb
- app/models/order_cycle.rb
- app/models/product_import/unit_converter.rb
- app/models/spree/gateway/pay_pal_express.rb
- app/serializers/api/admin/enterprise_serializer.rb
- app/services/order_factory.rb
- app/services/variants_stock_levels.rb
- engines/order_management/app/services/order_management/subscriptions/form.rb
- lib/open_food_network/enterprise_fee_calculator.rb
- lib/open_food_network/order_grouper.rb
- lib/spree/core/controller_helpers/auth.rb
- lib/spree/core/controller_helpers/common.rb
- lib/spree/core/product_duplicator.rb
- lib/stripe/authorize_response_patcher.rb
- lib/stripe/profile_storer.rb
- app/controllers/admin/bulk_line_items_controller.rb
- app/controllers/admin/customers_controller.rb
- app/controllers/admin/enterprise_fees_controller.rb
@@ -468,7 +510,7 @@ Metrics/AbcSize:
Metrics/BlockLength:
Max: 25
ExcludedMethods: [
IgnoredMethods: [
"class_eval",
"collection",
"context",
@@ -482,6 +524,8 @@ Metrics/BlockLength:
"scenario"
]
Exclude:
- spec/features/admin/order_cycles/complex_updating_specific_time_spec.rb
- spec/features/admin/tag_rules_spec.rb
- app/models/spree/order/checkout.rb
- app/models/spree/payment/processing.rb
- app/models/spree/shipment.rb
@@ -514,6 +558,27 @@ Metrics/BlockLength:
Metrics/CyclomaticComplexity:
Max: 6
Exclude:
- app/controllers/admin/resource_controller.rb
- app/controllers/spree/admin/payment_methods_controller.rb
- app/controllers/spree/admin/payments_controller.rb
- app/controllers/spree/admin/products_controller.rb
- app/controllers/spree/admin/users_controller.rb
- app/models/product_import/entry_validator.rb
- app/models/spree/order_inventory.rb
- app/models/spree/order.rb
- app/models/spree/shipment.rb
- app/models/spree/tax_rate.rb
- app/models/spree/variant.rb
- engines/order_management/app/services/order_management/reports/enterprise_fee_summary/parameters.rb
- lib/active_merchant/billing/gateways/stripe_decorator.rb
- lib/open_food_network/group_buy_report.rb
- lib/open_food_network/order_cycle_form_applicator.rb
- lib/open_food_network/order_cycle_permissions.rb
- lib/open_food_network/payments_report.rb
- lib/spree/core/controller_helpers/common.rb
- lib/stripe/authorize_response_patcher.rb
- lib/stripe/credit_card_clone_destroyer.rb
- spec/support/i18n_translations_checker.rb
- app/controllers/admin/enterprise_fees_controller.rb
- app/controllers/admin/enterprises_controller.rb
- app/controllers/spree/admin/taxons_controller.rb
@@ -552,6 +617,18 @@ Metrics/CyclomaticComplexity:
Metrics/PerceivedComplexity:
Max: 7
Exclude:
- app/controllers/spree/admin/payment_methods_controller.rb
- app/controllers/spree/admin/payments_controller.rb
- app/controllers/spree/admin/users_controller.rb
- app/models/product_import/entry_validator.rb
- app/models/spree/order_inventory.rb
- app/models/spree/shipment.rb
- app/models/spree/variant.rb
- lib/active_merchant/billing/gateways/stripe_decorator.rb
- lib/open_food_network/group_buy_report.rb
- lib/open_food_network/order_cycle_form_applicator.rb
- lib/open_food_network/order_cycle_permissions.rb
- lib/open_food_network/payments_report.rb
- app/controllers/admin/enterprises_controller.rb
- app/controllers/api/variants_controller.rb
- app/controllers/spree/admin/taxons_controller.rb
@@ -702,10 +779,18 @@ Metrics/MethodLength:
- spec/features/consumer/shopping/variant_overrides_spec.rb
- spec/models/product_importer_spec.rb
- spec/support/i18n_translations_checker.rb
- app/controllers/admin/bulk_line_items_controller.rb
- app/controllers/spree/paypal_controller.rb
- app/jobs/subscription_placement_job.rb
- app/models/spree/gateway/pay_pal_express.rb
Metrics/ClassLength:
Max: 100
Exclude:
- app/controllers/admin/customers_controller.rb
- app/controllers/spree/admin/payments_controller.rb
- app/controllers/spree/paypal_controller.rb
- engines/order_management/app/services/order_management/order/updater.rb
- app/controllers/admin/enterprises_controller.rb
- app/controllers/admin/order_cycles_controller.rb
- app/controllers/admin/resource_controller.rb

View File

@@ -5,7 +5,9 @@
# rubocop locally, the default configuration file `.rubocop.yml` loads
# our "todo lists" to ignore all current violations.
AllCops:
TargetRailsVersion: 4.0
NewCops: disable
SuggestExtensions: false
TargetRailsVersion: 5.0
Exclude:
- 'bin/**/*'
- 'db/**/*'
@@ -183,7 +185,7 @@ Metrics/AbcSize:
Metrics/BlockLength:
Max: 25
ExcludedMethods: [
IgnoredMethods: [
"class_eval",
"collection",
"context",
@@ -217,3 +219,6 @@ Metrics/ParameterLists:
Metrics/PerceivedComplexity:
Max: 7
Naming/PredicateName:
Enabled: false

File diff suppressed because it is too large Load Diff

View File

@@ -6,12 +6,13 @@ This is a general guide to setting up an Open Food Network **development environ
The fastest way to make it work locally is to use Docker, you only need to setup git, see the [Docker setup guide](docker/README.md).
Otherwise, for a local setup you will need:
* Ruby 2.3.7 and bundler
* Ruby 2.4.4 and bundler (check current Ruby version in [.ruby-version](https://github.com/openfoodfoundation/openfoodnetwork/blob/master/.ruby-version) file)
* PostgreSQL database
* Chrome (for testing)
The following guides will provide OS-specific step-by-step instructions to get these requirements installed:
- [Ubuntu Setup Guide][ubuntu]
- [Debian Setup Guide][debian]
- [OSX Setup Guide][osx]
If you are likely to need to manage multiple version of ruby on your local machine, we recommend version managers such as [rbenv](https://github.com/rbenv/rbenv) or [RVM](https://rvm.io/).
@@ -20,7 +21,7 @@ For those new to Rails, the following tutorial will help get you up to speed wit
### Get it
If you're planning on contributing code to the project (which we [LOVE](CONTRIBUTING.md)), it is a good idea to begin by forking this repo using the `Fork` button in the top-right corner of this screen. You should then be able to use `git clone` to copy your fork onto your local machine.
So you have set up your local environment according to the requirements listed above. If you're planning on contributing code to the project (which we [LOVE](CONTRIBUTING.md)), it is a good idea to begin by forking this repo using the `Fork` button in the top-right corner of this screen. You should then be able to use `git clone` to copy your fork onto your local machine:
git clone https://github.com/YOUR_GITHUB_USERNAME_HERE/openfoodnetwork
@@ -116,6 +117,7 @@ If these commands succeed, you should be able to [continue the setup process](#g
[developer-wiki]: https://github.com/openfoodfoundation/openfoodnetwork/wiki
[osx]: https://github.com/openfoodfoundation/openfoodnetwork/wiki/Development-Environment-Setup:-OS-X
[ubuntu]: https://github.com/openfoodfoundation/openfoodnetwork/wiki/Development-Environment-Setup:-Ubuntu
[debian]: https://github.com/openfoodfoundation/openfoodnetwork/wiki/Development-Environment-Setup:-Debian
[wiki]: https://github.com/openfoodfoundation/openfoodnetwork/wiki
[zeus]: https://github.com/burke/zeus
[rubocop]: https://rubocop.readthedocs.io/en/latest/

10
Gemfile
View File

@@ -15,7 +15,7 @@ gem 'sass', '<= 4.7.1'
gem 'sass-rails', '< 6.0.0'
gem 'i18n'
gem 'i18n-js', '~> 3.8.1'
gem 'i18n-js', '~> 3.8.2'
gem 'rails-i18n'
gem 'rails_safe_tasks', '~> 1.0'
@@ -32,11 +32,11 @@ gem 'activerecord-postgresql-adapter'
gem 'pg', '~> 0.21.0'
gem 'acts_as_list', '0.9.19'
gem 'cancancan', '~> 1.7.0'
gem 'cancancan', '~> 1.15.0'
gem 'ffaker'
gem 'highline', '2.0.3' # Necessary for the install generator
gem 'json'
gem 'monetize', '~> 1.10'
gem 'monetize', '~> 1.11'
gem 'paranoia', '~> 2.4'
gem 'state_machines-activerecord'
gem 'stringex', '~> 2.8.5'
@@ -48,7 +48,7 @@ gem 'devise'
gem 'devise-encryptable'
gem 'devise-token_authenticatable'
gem 'jwt', '~> 2.2'
gem 'oauth2', '~> 1.4.4' # Used for Stripe Connect
gem 'oauth2', '~> 1.4.7' # Used for Stripe Connect
gem 'daemons'
gem 'delayed_job_active_record'
@@ -68,7 +68,7 @@ gem 'actionpack-action_caching'
# AMS is deprecated, we will introduce an alternative at some point
gem "active_model_serializers", "0.8.4"
gem 'activerecord-session_store'
gem 'acts-as-taggable-on', '~> 4.0'
gem 'acts-as-taggable-on', '~> 7.0'
gem 'angularjs-file-upload-rails', '~> 2.4.1'
gem 'custom_error_message', github: 'jeremydurham/custom-err-msg'
gem 'dalli'

View File

@@ -103,8 +103,8 @@ GEM
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
acts-as-taggable-on (4.0.0)
activerecord (>= 4.0)
acts-as-taggable-on (7.0.0)
activerecord (>= 5.0, < 6.2)
acts_as_list (0.9.19)
activerecord (>= 3.0)
addressable (2.7.0)
@@ -123,7 +123,7 @@ GEM
atomic (1.1.101)
awesome_nested_set (3.4.0)
activerecord (>= 4.0.0, < 7.0)
awesome_print (1.8.0)
awesome_print (1.9.2)
aws-sdk (1.67.0)
aws-sdk-v1 (= 1.67.0)
aws-sdk-v1 (1.67.0)
@@ -137,7 +137,7 @@ GEM
activesupport (>= 3.0.0)
uniform_notifier (~> 1.11)
byebug (11.1.3)
cancancan (1.7.1)
cancancan (1.15.0)
capybara (3.32.2)
addressable
mini_mime (>= 0.1.3)
@@ -148,7 +148,7 @@ GEM
xpath (~> 3.2)
childprocess (3.0.0)
chronic (0.10.2)
chunky_png (1.3.14)
chunky_png (1.4.0)
climate_control (0.2.0)
cocaine (0.5.8)
climate_control (>= 0.0.3, < 1.0)
@@ -174,8 +174,10 @@ GEM
sass (>= 3.3.0, < 3.5)
compass-import-once (1.0.5)
sass (>= 3.2, < 3.5)
compass-rails (2.0.1)
compass-rails (4.0.0)
compass (~> 1.0.0)
sass-rails (< 5.1)
sprockets (< 4.0)
concurrent-ruby (1.1.8)
crack (0.4.5)
rexml
@@ -190,7 +192,7 @@ GEM
debugger-linecache (1.2.0)
delayed_job (4.1.9)
activesupport (>= 3.0, < 6.2)
delayed_job_active_record (4.1.5)
delayed_job_active_record (4.1.6)
activerecord (>= 3.0, < 6.2)
delayed_job (>= 3.0, < 5)
delayed_job_web (1.4.4)
@@ -219,10 +221,13 @@ GEM
factory_bot_rails (5.2.0)
factory_bot (~> 5.2.0)
railties (>= 4.2.0)
faraday (1.0.1)
faraday (1.3.0)
faraday-net_http (~> 1.0)
multipart-post (>= 1.2, < 3)
ruby2_keywords
faraday-net_http (1.0.1)
ffaker (2.16.0)
ffi (1.13.1)
ffi (1.15.0)
figaro (1.2.0)
thor (>= 0.14.0, < 2)
fog-aws (2.0.1)
@@ -264,9 +269,9 @@ GEM
tilt
hashdiff (1.0.1)
highline (2.0.3)
i18n (1.8.5)
i18n (1.8.9)
concurrent-ruby (~> 1.0)
i18n-js (3.8.1)
i18n-js (3.8.2)
i18n (>= 0.6.6)
immigrant (0.3.6)
activerecord (>= 3.0)
@@ -319,9 +324,9 @@ GEM
mini_racer (0.3.1)
libv8 (~> 8.4.255)
minitest (5.14.4)
monetize (1.10.0)
monetize (1.11.0)
money (~> 6.12)
money (6.14.0)
money (6.14.1)
i18n (>= 0.6.4, <= 2)
msgpack (1.4.2)
multi_json (1.15.0)
@@ -332,7 +337,7 @@ GEM
nio4r (2.5.2)
nokogiri (1.10.10)
mini_portile2 (~> 2.4.0)
oauth2 (1.4.4)
oauth2 (1.4.7)
faraday (>= 0.8, < 2.0)
jwt (>= 1.0, < 3.0)
multi_json (~> 1.3)
@@ -426,9 +431,9 @@ GEM
regexp_parser (1.8.2)
request_store (1.5.0)
rack (>= 1.4)
responders (2.4.1)
actionpack (>= 4.2.0, < 6.0)
railties (>= 4.2.0, < 6.0)
responders (3.0.1)
actionpack (>= 5.0)
railties (>= 5.0)
rexml (3.2.4)
roadie (3.5.1)
css_parser (~> 1.4)
@@ -448,10 +453,10 @@ GEM
rspec-expectations (3.10.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-mocks (3.10.0)
rspec-mocks (3.10.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-rails (4.0.2)
rspec-rails (4.1.2)
actionpack (>= 4.2)
activesupport (>= 4.2)
railties (>= 4.2)
@@ -461,7 +466,7 @@ GEM
rspec-support (~> 3.10)
rspec-retry (0.6.2)
rspec-core (> 3.3)
rspec-support (3.10.1)
rspec-support (3.10.2)
rswag (2.4.0)
rswag-api (= 2.4.0)
rswag-specs (= 2.4.0)
@@ -475,7 +480,7 @@ GEM
rswag-ui (2.4.0)
actionpack (>= 3.1, < 7.0)
railties (>= 3.1, < 7.0)
rubocop (1.11.0)
rubocop (1.12.0)
parallel (~> 1.10)
parser (>= 3.0.0.0)
rainbow (>= 2.2.2, < 4.0)
@@ -566,7 +571,7 @@ GEM
nokogiri (~> 1.6)
rubyzip (>= 1.3.0)
selenium-webdriver (>= 3.0, < 4.0)
webmock (3.12.1)
webmock (3.12.2)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
@@ -592,7 +597,7 @@ DEPENDENCIES
activerecord-import
activerecord-postgresql-adapter
activerecord-session_store
acts-as-taggable-on (~> 4.0)
acts-as-taggable-on (~> 7.0)
acts_as_list (= 0.9.19)
andand
angular-rails-templates (>= 0.3.0)
@@ -606,7 +611,7 @@ DEPENDENCIES
bugsnag
bullet
byebug
cancancan (~> 1.7.0)
cancancan (~> 1.15.0)
capybara
catalog!
coffee-rails (~> 4.2.2)
@@ -639,7 +644,7 @@ DEPENDENCIES
haml
highline (= 2.0.3)
i18n
i18n-js (~> 3.8.1)
i18n-js (~> 3.8.2)
immigrant
jquery-migrate-rails
jquery-rails (= 4.4.0)
@@ -651,8 +656,8 @@ DEPENDENCIES
knapsack
letter_opener (>= 1.4.1)
mini_racer (= 0.3.1)
monetize (~> 1.10)
oauth2 (~> 1.4.4)
monetize (~> 1.11)
oauth2 (~> 1.4.7)
ofn-qz!
order_management!
paper_trail (~> 10.3.1)

View File

@@ -52,6 +52,9 @@
//= require admin/spree/handlebar_extensions
// OFN specific
//= require ../shared/shared
//= require_tree ../shared/directives
//= require_tree ../templates/shared
//= require_tree ../templates/admin
//= require ./admin_ofn
//= require ./customers/customers

View File

@@ -1,12 +1,13 @@
angular.module("admin.products")
.controller "unitsCtrl", ($scope, VariantUnitManager, OptionValueNamer) ->
.controller "unitsCtrl", ($scope, VariantUnitManager, OptionValueNamer, UnitPrices) ->
$scope.product = { master: {} }
$scope.product.master.product = $scope.product
$scope.placeholder_text = ""
$scope.$watchCollection '[product.variant_unit_with_scale, product.master.unit_value_with_description]', ->
$scope.$watchCollection '[product.variant_unit_with_scale, product.master.unit_value_with_description, product.price, product.variant_unit_name]', ->
$scope.processVariantUnitWithScale()
$scope.processUnitValueWithDescription()
$scope.processUnitPrice()
$scope.placeholder_text = new OptionValueNamer($scope.product.master).name()
$scope.variant_unit_options = VariantUnitManager.variantUnitOptions()
@@ -32,6 +33,14 @@ angular.module("admin.products")
$scope.product.master.unit_value *= $scope.product.variant_unit_scale if $scope.product.master.unit_value && $scope.product.variant_unit_scale
$scope.product.master.unit_description = match[3]
$scope.processUnitPrice = ->
price = $scope.product.price
scale = $scope.product.variant_unit_scale
unit_type = $scope.product.variant_unit
unit_value = $scope.product.master.unit_value
variant_unit_name = $scope.product.variant_unit_name
$scope.unit_price = UnitPrices.displayableUnitPrice(price, scale, unit_type, unit_value, variant_unit_name)
$scope.hasVariants = (product) ->
Object.keys(product.variants).length > 0

View File

@@ -1,8 +1,24 @@
angular.module("admin.products").controller "variantUnitsCtrl", ($scope, VariantUnitManager, $timeout) ->
angular.module("admin.products").controller "variantUnitsCtrl", ($scope, VariantUnitManager, $timeout, UnitPrices) ->
$scope.unitName = (scale, type) ->
VariantUnitManager.getUnitName(scale, type)
$scope.$watchCollection "[unit_value_human, variant.price]", ->
$scope.processUnitPrice()
$scope.processUnitPrice = ->
if ($scope.variant)
price = $scope.variant.price
scale = $scope.scale
unit_type = angular.element("#product_variant_unit").val()
if (unit_type != "items")
$scope.updateValue()
unit_value = $scope.unit_value
else
unit_value = 1
variant_unit_name = angular.element("#product_variant_unit_name").val()
$scope.unit_price = UnitPrices.displayableUnitPrice(price, scale, unit_type, unit_value, variant_unit_name)
$scope.scale = angular.element('#product_variant_unit_scale').val()
$scope.updateValue = ->
@@ -11,4 +27,6 @@ angular.module("admin.products").controller "variantUnitsCtrl", ($scope, Variant
variant_unit_value = angular.element('#variant_unit_value').val()
$scope.unit_value_human = variant_unit_value / $scope.scale
$timeout -> $scope.processUnitPrice()
$timeout -> $scope.updateValue()

View File

@@ -1 +1 @@
angular.module("admin.products", ["textAngular", "admin.utils"])
angular.module("admin.products", ["textAngular", "admin.utils", "OFNShared"])

View File

@@ -0,0 +1,32 @@
angular.module("admin.products").factory "UnitPrices", (VariantUnitManager, localizeCurrencyFilter) ->
class UnitPrices
@displayableUnitPrice: (price, scale, unit_type, unit_value, variant_unit_name) ->
if price && !isNaN(price) && unit_type && unit_value
value = localizeCurrencyFilter(UnitPrices.price(price, scale, unit_type, unit_value, variant_unit_name))
unit = UnitPrices.unit(scale, unit_type, variant_unit_name)
return value + " / " + unit
return null
@price: (price, scale, unit_type, unit_value) ->
price / @denominator(scale, unit_type, unit_value)
@denominator: (scale, unit_type, unit_value) ->
unit = @unit(scale, unit_type)
if unit == "lb"
unit_value / 453.6
else if unit == "kg"
unit_value / 1000
else
unit_value
@unit: (scale, unit_type, variant_unit_name = '') ->
if variant_unit_name.length > 0
variant_unit_name
else if unit_type == "items"
"item"
else if VariantUnitManager.systemOfMeasurement(scale, unit_type) == "imperial"
"lb"
else if unit_type == "weight"
"kg"
else if unit_type == "volume"
"L"

View File

@@ -67,3 +67,9 @@ angular.module("admin.products").factory "VariantUnitManager", (availableUnits)
scaleSystem = @units[unitType][scale]['system']
(parseFloat(scale) for scale, scaleInfo of @units[unitType] when scaleInfo['system'] == scaleSystem).sort (a, b) ->
a - b
@systemOfMeasurement: (scale, unitType) ->
if @units[unitType][scale]
@units[unitType][scale]['system']
else
'custom'

View File

@@ -19,6 +19,8 @@
#= require ../shared/ng-infinite-scroll.min.js
#= require ../shared/angular-local-storage.js
#= require ../shared/angular-slideables.js
#= require ../shared/shared
#= require_tree ../shared/directives
#= require angularjs-file-upload
#= require i18n/translations

View File

@@ -10,7 +10,8 @@ window.Darkswarm = angular.module("Darkswarm", [
'uiGmapgoogle-maps',
'duScroll',
'angularFileUpload',
'angularSlideables'
'angularSlideables',
'OFNShared'
]).config ($httpProvider, $tooltipProvider, $locationProvider, $anchorScrollProvider) ->
$httpProvider.defaults.headers['common']['X-Requested-With'] = 'XMLHttpRequest'
$httpProvider.defaults.headers.common['Accept'] = "application/json, text/javascript, */*"

View File

@@ -1,17 +1,19 @@
Darkswarm.directive "questionMarkWithTooltip", ($tooltip)->
OFNShared.directive "questionMarkWithTooltip", ($tooltip)->
# We use the $tooltip service from Angular foundation to give us boilerplate
# Subsequently we patch the scope, template and restrictions
tooltip = $tooltip 'questionMarkWithTooltip', 'questionMarkWithTooltip', 'click'
tooltip.scope =
context: "="
tooltip.templateUrl = "question_mark_with_tooltip_icon.html"
variant: "="
key: "="
tooltip.templateUrl = "shared/question_mark_with_tooltip_icon.html"
tooltip.replace = true
tooltip.restrict = 'E'
tooltip
# This is automatically referenced via naming convention in $tooltip
Darkswarm.directive 'questionMarkWithTooltipPopup', ->
OFNShared.directive 'questionMarkWithTooltipPopup', ->
restrict: 'EA'
replace: true
templateUrl: 'question_mark_with_tooltip.html'
templateUrl: 'shared/question_mark_with_tooltip.html'
scope: false

View File

@@ -0,0 +1,4 @@
window.OFNShared = angular.module("OFNShared", [
"mm.foundation"
]).config ($httpProvider) ->
$httpProvider.defaults.headers.common["Accept"] = "application/json, text/javascript, */*"

View File

@@ -1,6 +1,6 @@
.joyride-tip-guide.question-mark-tooltip{class: "{{ context }}", ng: {class: "{ in: tt_isOpen, fade: tt_animation }", show: "tt_isOpen"}}
.background{ng: {click: "tt_isOpen = false"}}
.joyride-content-wrapper
{{ "js.shopfront.unit_price_tooltip" | t }}
{{ key | t }}
%span.joyride-nub.bottom

View File

@@ -12,7 +12,8 @@
%question-mark-with-tooltip{"question-mark-with-tooltip" => "_",
"question-mark-with-tooltip-append-to-body" => "true",
"question-mark-with-tooltip-placement" => "top",
"question-mark-with-tooltip-animation" => true}
"question-mark-with-tooltip-animation" => true,
key: "'js.shopfront.unit_price_tooltip'"}
{{ variant.unit_price_price | localizeCurrency }} / {{ variant.unit_price_unit }}
.medium-2.large-2.columns.total-price

View File

@@ -48,3 +48,6 @@
@import 'components/*';
@import 'pages/*';
@import '*';
@import "../shared/question-mark-icon";
@import "question-mark-tooltip";

View File

@@ -0,0 +1,18 @@
.joyride-tip-guide {
background: $color-3;
color: $white;
font-family: inherit;
font-weight: $font-weight-normal;
position: absolute;
z-index: 101;
padding: 5px 15px;
.joyride-nub.bottom {
border: 10px solid;
display: block;
height: 0;
position: absolute;
width: 0;
}
}

View File

@@ -21,3 +21,5 @@
ofn-modal {
display: block;
}
@import "../shared/question-mark-icon";

View File

@@ -4,8 +4,8 @@
footer {
.row {
p a {
font-size: 0.875rem;
p {
font-size: 1rem;
}
a, a * {
@@ -107,9 +107,14 @@ footer {
color: rgba($disabled-med, 0.35);
}
p.text-big {
font-size: 1.5rem;
font-weight: 300;
}
.social-icons {
margin-bottom: 0.25rem;
margin-top: 0.75rem;
margin-bottom: 0.9rem;
padding-top: 0.1rem;
a {
i {
@@ -128,5 +133,9 @@ footer {
}
}
}
.legal p {
font-size: 0.875rem;
}
}
}

View File

@@ -1,3 +1,5 @@
@import "variables/variables";
.unit-price {
display: flex;
align-items: center;
@@ -26,6 +28,10 @@
background-image: none;
background-color: $teal-500;
&:focus {
outline: 0;
}
&::before {
@include icon-font;
content: "";
@@ -34,6 +40,13 @@
}
}
// Question mark icon into a field
.field .question-mark-icon {
width: 15px;
min-width: 15px;
height: 15px;
}
.joyride-tip-guide.question-mark-tooltip {
width: 16rem;
max-width: 65%;

View File

@@ -0,0 +1,25 @@
$padding-small: 0.5rem;
$radius-small: 0.25em;
$white: #fff;
$dynamic-blue: #3d8dd1;
$teal-500: #0096ad;
@font-face {
font-family: 'OFN';
src: font-url('OFN-v2.eot');
src: font-url('OFN-v2.eot') format('embedded-opentype'),
font-url('OFN-v2.woff') format('woff'),
font-url('OFN-v2.ttf') format('truetype'),
font-url('OFN-v2.svg') format('svg');
font-weight: normal;
font-style: normal;
}
@mixin icon-font {
font-family: "OFN";
display: inline-block;
font-weight: normal;
font-style: normal;
font-variant: normal;
text-transform: none;
}

View File

@@ -36,7 +36,7 @@ module Admin
order.update_line_item_fees! @line_item
order.update_order_fees!
order.update!
render nothing: true, status: :no_content # No Content, does not trigger ng resource auto-update
render body: nil, status: :no_content # No Content, does not trigger ng resource auto-update
else
render json: { errors: @line_item.errors }, status: :precondition_failed
end
@@ -50,7 +50,7 @@ module Admin
authorize! :update, order
@line_item.destroy
render nothing: true, status: :no_content # No Content, does not trigger ng resource auto-update
render body: nil, status: :no_content # No Content, does not trigger ng resource auto-update
end
private

View File

@@ -12,7 +12,7 @@ module Admin
elsif @cp_set.errors.present?
render json: { errors: @cp_set.errors }, status: :bad_request
else
render nothing: true, status: :internal_server_error
render body: nil, status: :internal_server_error
end
end

View File

@@ -74,7 +74,12 @@ module Admin
def collection
if json_request? && params[:enterprise_id].present?
customers_relation.
includes(:bill_address, :ship_address, user: :credit_cards)
includes(
:enterprise,
{ bill_address: [:state, :country] },
{ ship_address: [:state, :country] },
user: :credit_cards
)
else
Customer.where('1=0')
end

View File

@@ -25,15 +25,14 @@ module Admin
protected
def build_resource_with_address
enterprise_group = build_resource_without_address
def build_resource
enterprise_group = super
enterprise_group.address = Spree::Address.new
enterprise_group.address.country = Spree::Country.find_by(
id: Spree::Config[:default_country_id]
)
enterprise_group
end
alias_method_chain :build_resource, :address
# Overriding method on Spree's resource controller,
# so that resources are found using permalink.

View File

@@ -14,7 +14,7 @@ module Admin
@enterprise_relationship = EnterpriseRelationship.new enterprise_relationship_params
if @enterprise_relationship.save
render text: Api::Admin::EnterpriseRelationshipSerializer.new(@enterprise_relationship).to_json
render plain: Api::Admin::EnterpriseRelationshipSerializer.new(@enterprise_relationship).to_json
else
render status: :bad_request, json: { errors: @enterprise_relationship.errors.full_messages.join(', ') }
end
@@ -23,7 +23,7 @@ module Admin
def destroy
@enterprise_relationship = EnterpriseRelationship.find params[:id]
@enterprise_relationship.destroy
render nothing: true
render body: nil
end
private

View File

@@ -10,7 +10,7 @@ module Admin
@enterprise_role = EnterpriseRole.new enterprise_role_params
if @enterprise_role.save
render text: Api::Admin::EnterpriseRoleSerializer.new(@enterprise_role).to_json
render plain: Api::Admin::EnterpriseRoleSerializer.new(@enterprise_role).to_json
else
render status: :bad_request, json: { errors: @enterprise_role.errors.full_messages.join(', ') }
@@ -20,7 +20,7 @@ module Admin
def destroy
@enterprise_role = EnterpriseRole.find params[:id]
@enterprise_role.destroy
render nothing: true
render body: nil
end
private

View File

@@ -114,13 +114,12 @@ module Admin
protected
def build_resource_with_address
enterprise = build_resource_without_address
def build_resource
enterprise = super
enterprise.address ||= Spree::Address.new
enterprise.address.country ||= Spree::Country.find_by(id: Spree::Config[:default_country_id])
enterprise
end
alias_method_chain :build_resource, :address
# Overriding method on Spree's resource controller,
# so that resources are found using permalink

View File

@@ -62,7 +62,7 @@ module Admin
end
respond_to do |format|
format.js { render text: 'Ok' }
format.js { render plain: 'Ok' }
end
end

View File

@@ -3,7 +3,7 @@ module Admin
respond_to :json
respond_override destroy: { json: {
success: lambda { render nothing: true, status: :no_content }
success: lambda { render body: nil, status: :no_content }
} }
def map_by_tag

View File

@@ -21,7 +21,7 @@ module Admin
elsif @vo_set.errors.present?
render json: { errors: @vo_set.errors }, status: :bad_request
else
render nothing: true, status: :internal_server_error
render body: nil, status: :internal_server_error
end
end

View File

@@ -6,9 +6,9 @@ module Api
authorize! :destroy, enterprise_fee
if enterprise_fee.destroy
render text: I18n.t(:successfully_removed), status: :no_content
render plain: I18n.t(:successfully_removed), status: :no_content
else
render text: enterprise_fee.errors.full_messages.first, status: :forbidden
render plain: enterprise_fee.errors.full_messages.first, status: :forbidden
end
end

View File

@@ -37,9 +37,9 @@ module Api
authorize! :update, @enterprise
if params[:logo] && @enterprise.update( logo: params[:logo] )
render text: @enterprise.logo.url(:medium), status: :ok
render plain: @enterprise.logo.url(:medium), status: :ok
elsif params[:promo] && @enterprise.update( promo_image: params[:promo] )
render text: @enterprise.promo_image.url(:medium), status: :ok
render plain: @enterprise.promo_image.url(:medium), status: :ok
else
invalid_resource!(@enterprise)
end

View File

@@ -32,7 +32,7 @@ module Api
private
def render_variant_count
render text: {
render plain: {
count: variants.count
}.to_json
end

View File

@@ -47,7 +47,7 @@ module Api
private
def payment_capture_failed
render json: { error: t(:payment_processing_failed) }, status: :unprocessable_entity
render json: { error: I18n.t(:payment_processing_failed) }, status: :unprocessable_entity
end
def serialized_orders(orders)

View File

@@ -8,7 +8,7 @@ module Api
def show
enterprise = Enterprise.find_by(id: params[:id])
render text: Api::EnterpriseShopfrontSerializer.new(enterprise).to_json, status: :ok
render plain: Api::EnterpriseShopfrontSerializer.new(enterprise).to_json, status: :ok
end
def closed_shops

View File

@@ -6,15 +6,15 @@ class CheckoutController < ::BaseController
layout 'darkswarm'
include OrderStockCheck
include CheckoutHelper
include OrderCyclesHelper
include EnterprisesHelper
helper 'terms_and_conditions'
helper 'checkout'
ssl_required
# We need pessimistic locking to avoid race conditions.
# Otherwise we fail on duplicate indexes or end up with negative stock.
prepend_around_action CurrentOrderLocker, only: :update
prepend_around_action CurrentOrderLocker, only: [:edit, :update]
prepend_before_action :check_hub_ready_for_checkout
prepend_before_action :check_order_cycle_expiry

View File

@@ -19,7 +19,7 @@ class DiscourseSsoController < ApplicationController
begin
redirect_to sso_url
rescue TypeError
render text: "Bad SingleSignOn request.", status: :bad_request
render plain: "Bad SingleSignOn request.", status: :bad_request
end
else
redirect_to login_path

View File

@@ -39,14 +39,14 @@ class EnterprisesController < BaseController
def check_permalink
if Enterprise.find_by permalink: params[:permalink]
render(text: params[:permalink], status: :conflict) && return
render(plain: params[:permalink], status: :conflict) && return
end
begin
Rails.application.routes.recognize_path( "/#{params[:permalink]}" )
render text: params[:permalink], status: :conflict
render plain: params[:permalink], status: :conflict
rescue ActionController::RoutingError
render text: params[:permalink], status: :ok
render plain: params[:permalink], status: :ok
end
end

View File

@@ -29,11 +29,11 @@ class LineItemsController < BaseController
def unauthorized
status = spree_current_user ? 403 : 401
render(nothing: true, status: status) && return
render(body: nil, status: status) && return
end
def not_found
render(nothing: true, status: :not_found) && return
render(body: nil, status: :not_found) && return
end
def destroy_with_lock(item)

View File

@@ -1,6 +1,6 @@
# For the API
ActionController::Metal.class_eval do
def spree_current_user
@spree_current_user ||= env['warden'].user
@spree_current_user ||= request.env['warden'].user
end
end

View File

@@ -17,7 +17,7 @@ module Spree
end
def collection
parent.adjustments.eligible | parent.shipment_adjustments.shipping
parent.all_adjustments.eligible
end
def find_resource

View File

@@ -136,7 +136,7 @@ module Spree
#
# Otherwise redirect user to that step
def can_transition_to_payment
return if @order.payment? || @order.complete? || @order.canceled?
return if @order.payment? || @order.complete? || @order.canceled? || @order.resumed?
flash[:notice] = Spree.t(:fill_in_customer_info)
redirect_to spree.edit_admin_order_customer_url(@order)

View File

@@ -84,7 +84,7 @@ module Spree
elsif product_set.errors.present?
render json: { errors: product_set.errors }, status: :bad_request
else
render nothing: true, status: :internal_server_error
render body: nil, status: :internal_server_error
end
end

View File

@@ -13,33 +13,9 @@ module Spree
def express
order = current_order || raise(ActiveRecord::RecordNotFound)
items = order.line_items.map(&method(:line_item))
tax_adjustments = order.adjustments.tax.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 https://github.com/spree-contrib/better_spree_paypal_express/issues/10
# "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)
express_checkout_request_details(order)
)
begin
@@ -98,20 +74,7 @@ module Spree
private
def line_item(item)
{
Name: item.product.name,
Number: item.variant.sku,
Quantity: item.quantity,
Amount: {
currencyID: item.order.currency,
value: item.price
},
ItemCategory: "Physical"
}
end
def express_checkout_request_details(order, items)
def express_checkout_request_details(order)
{
SetExpressCheckoutRequestDetails: {
InvoiceID: order.number,
@@ -124,7 +87,7 @@ module Spree
LandingPage: payment_method.preferred_landing_page.presence || "Billing",
cppheaderimage: payment_method.preferred_logourl.presence || "",
NoShipping: 1,
PaymentDetails: [payment_details(items)]
PaymentDetails: [payment_details(order)]
}
}
end
@@ -171,11 +134,11 @@ module Spree
payment_method.provider
end
def payment_details(items)
item_sum = items.sum { |i| i[:Quantity] * i[:Amount][:value] }
def payment_details(order)
items = PaypalItemsBuilder.new(order).call
tax_adjustments = current_order.adjustments.tax.additional
tax_adjustments_total = tax_adjustments.sum(:amount)
item_sum = items.sum { |i| i[:Quantity] * i[:Amount][:value] }
tax_adjustments_total = current_order.all_adjustments.tax.additional.sum(:amount)
if item_sum.zero?
# Paypal does not support no items or a zero dollar ItemTotal

View File

@@ -15,7 +15,7 @@ module Stripe
end
redirect_to main_app.edit_admin_enterprise_path(connector.enterprise, anchor: 'payment_methods')
rescue Stripe::StripeError => e
render text: e.message, status: :internal_server_error
render plain: e.message, status: :internal_server_error
end
end
end

View File

@@ -10,7 +10,7 @@ module Stripe
handler = WebhookHandler.new(@event)
result = handler.handle
render nothing: true, status: status_mappings[result] || 200
render body: nil, status: status_mappings[result] || 200
end
private
@@ -20,9 +20,9 @@ module Stripe
signature = request.headers["HTTP_STRIPE_SIGNATURE"]
@event = Webhook.construct_event(payload, signature, Stripe.endpoint_secret)
rescue JSON::ParserError
render nothing: true, status: :bad_request
render body: nil, status: :bad_request
rescue Stripe::SignatureVerificationError
render nothing: true, status: :unauthorized
render body: nil, status: :unauthorized
end
# Stripe interprets a 4xx or 3xx response as a failure to receive the webhook,

View File

@@ -5,9 +5,9 @@ module Admin
# We exclude shipping method adjustments because they are displayed in a
# separate table together with the order line items.
def order_adjustments_for_display(order)
order.adjustments.eligible.reject do |adjustment|
adjustment.originator_type == "Spree::ShippingMethod"
end
order.all_adjustments.enterprise_fee +
order.all_adjustments.payment_fee.eligible +
order.adjustments.admin
end
end
end

View File

@@ -4,10 +4,9 @@ module CheckoutHelper
end
def checkout_adjustments_for(order, opts = {})
adjustments = order.adjustments.eligible
exclude = opts[:exclude] || {}
adjustments = adjustments.to_a + order.shipment_adjustments.to_a
adjustments = order.all_adjustments.eligible.to_a
# Remove empty tax adjustments and (optionally) shipping fees
adjustments.reject! { |a| a.originator_type == 'Spree::TaxRate' && a.amount == 0 }
@@ -26,17 +25,16 @@ module CheckoutHelper
adjustments
end
def display_checkout_admin_and_handling_adjustments_total_for(order)
adjustments = order.adjustments.eligible.where('originator_type = ? AND source_type != ? ', 'EnterpriseFee', 'Spree::LineItem')
Spree::Money.new adjustments.sum(:amount), currency: order.currency
def display_line_item_fees_total_for(order)
Spree::Money.new order.adjustments.enterprise_fee.sum(:amount), currency: order.currency
end
def checkout_line_item_adjustments(order)
order.adjustments.eligible.where(source_type: "Spree::LineItem")
def checkout_line_item_fees(order)
order.line_item_adjustments.enterprise_fee
end
def checkout_subtotal(order)
order.item_total + checkout_line_item_adjustments(order).sum(:amount)
order.item_total + checkout_line_item_fees(order).sum(:amount)
end
def display_checkout_subtotal(order)

View File

@@ -15,4 +15,10 @@ module FooterLinksHelper
target: '_blank',
rel: 'noopener' )
end
def show_social_icons?
ContentConfig.footer_facebook_url.present? || ContentConfig.footer_twitter_url.present? ||
ContentConfig.footer_instagram_url.present? || ContentConfig.footer_linkedin_url.present? ||
ContentConfig.footer_googleplus_url.present? || ContentConfig.footer_pinterest_url.present?
end
end

View File

@@ -2,6 +2,8 @@ require 'open_food_network/enterprise_injection_data'
module InjectionHelper
include SerializerHelper
include EnterprisesHelper
include OrderCyclesHelper
def inject_enterprises(enterprises = nil)
inject_json_array(

View File

@@ -1,6 +1,20 @@
# frozen_string_literal: true
module TermsAndConditionsHelper
def render_terms_and_conditions
if platform_terms_required? && terms_and_conditions_activated?
render("checkout/all_terms_and_conditions")
elsif platform_terms_required?
render "checkout/platform_terms_of_service"
elsif terms_and_conditions_activated?
render "checkout/terms_and_conditions"
end
end
def platform_terms_required?
Spree::Config.shoppers_require_tos
end
def terms_and_conditions_activated?
current_order.distributor.terms_and_conditions.file?
end

View File

@@ -62,12 +62,18 @@ class SubscriptionPlacementJob < ActiveJob::Base
unavailable_stock_lines_for(order).each do |line_item|
changes[line_item.id] = changes[line_item.id] || line_item.quantity
line_item.update(quantity: 0)
Spree::OrderInventory.new(order).verify(line_item, order.shipment)
end
if changes.present?
order.line_items.reload
order.update_order_fees!
end
changes
end
def handle_empty_order(order, changes)
order.reload.adjustments.destroy_all
order.reload.all_adjustments.destroy_all
order.update!
send_empty_email(order, changes)
end

View File

@@ -7,20 +7,18 @@ class ProducerMailer < Spree::BaseMailer
@producer = producer
@order_cycle = order_cycle
with_unscoped_products_and_variants do
load_data
load_data
I18n.with_locale(owner_locale) do
return unless orders?(order_cycle, producer)
I18n.with_locale(owner_locale) do
return unless orders?(order_cycle, producer)
mail(
to: @producer.contact.email,
from: from_address,
subject: subject,
reply_to: @coordinator.contact.email,
cc: @coordinator.contact.email
)
end
mail(
to: @producer.contact.email,
from: from_address,
subject: subject,
reply_to: @coordinator.contact.email,
cc: @coordinator.contact.email
)
end
end
@@ -76,22 +74,4 @@ class ProducerMailer < Spree::BaseMailer
def tax_total_from_line_items(line_items)
Spree::Money.new line_items.to_a.sum(&:included_tax)
end
# This hack makes ActiveRecord skip the default_scope (deleted_at IS NULL)
# when eager loading associations. Further details:
# https://github.com/rails/rails/issues/11036
def with_unscoped_products_and_variants
variant_default_scopes = Spree::Variant.default_scopes
product_default_scopes = Spree::Product.default_scopes
Spree::Variant.default_scopes = []
Spree::Product.default_scopes = []
return_value = yield
Spree::Variant.default_scopes = variant_default_scopes
Spree::Product.default_scopes = product_default_scopes
return_value
end
end

View File

@@ -2,7 +2,7 @@
module Spree
class OrderMailer < BaseMailer
helper ::CheckoutHelper
helper 'checkout'
helper SpreeCurrencyHelper
helper Spree::Admin::PaymentsHelper
helper OrderHelper

View File

@@ -1,5 +1,5 @@
class SubscriptionMailer < Spree::BaseMailer
helper CheckoutHelper
helper 'checkout'
helper MailerHelper
helper ShopMailHelper
helper OrderHelper

View File

@@ -0,0 +1,43 @@
# frozen_string_literal: true
require 'active_support/concern'
# Contains the methods to compute an order balance form the point of view of the enterprise and not
# the individual shopper.
module Balance
FINALIZED_NON_SUCCESSFUL_STATES = %w(canceled returned).freeze
# Returns the order balance by considering the total as money owed to the order distributor aka.
# the shop, and as a positive balance of said enterprise. If the customer pays it all, they
# distributor and customer are even.
#
# Note however, this is meant to be used only in the context of a single order object. When
# working with a collection of orders, such an index controller action, please consider using
# `app/queries/oustanding_balance.rb` instead so we avoid potential N+1s.
def new_outstanding_balance
if state.in?(FINALIZED_NON_SUCCESSFUL_STATES)
-payment_total
else
total - payment_total
end
end
# This method is the one we're gradually replacing with `#new_outstanding_balance`. Having them
# separate enables us to choose which implementation we want depending on the context using
# a feature toggle. This avoids incosistent behavior across the app during that incremental
# refactoring.
#
# It is meant to be removed as soon as we get product approval that the new implementation has
# been working correctly in production.
def outstanding_balance
total - payment_total
end
def outstanding_balance?
!outstanding_balance.zero?
end
def display_outstanding_balance
Spree::Money.new(outstanding_balance, currency: currency)
end
end

View File

@@ -1,8 +0,0 @@
module LineItemBasedAdjustmentHandling
extend ActiveSupport::Concern
included do
has_many :adjustments_for_which_source, class_name: "Spree::Adjustment", as: :source,
dependent: :destroy
end
end

View File

@@ -2,15 +2,15 @@ class Customer < ActiveRecord::Base
acts_as_taggable
belongs_to :enterprise
belongs_to :user, class_name: Spree.user_class
has_many :orders, class_name: Spree::Order
belongs_to :user, class_name: Spree.user_class.to_s
has_many :orders, class_name: "Spree::Order"
before_destroy :check_for_orders
belongs_to :bill_address, foreign_key: :bill_address_id, class_name: Spree::Address
belongs_to :bill_address, foreign_key: :bill_address_id, class_name: "Spree::Address"
alias_attribute :billing_address, :bill_address
accepts_nested_attributes_for :bill_address
belongs_to :ship_address, foreign_key: :ship_address_id, class_name: Spree::Address
belongs_to :ship_address, foreign_key: :ship_address_id, class_name: "Spree::Address"
alias_attribute :shipping_address, :ship_address
accepts_nested_attributes_for :ship_address
@@ -19,7 +19,7 @@ class Customer < ActiveRecord::Base
validates :code, uniqueness: { scope: :enterprise_id, allow_nil: true }
validates :email, presence: true, uniqueness: { scope: :enterprise_id, message: I18n.t('validation_msg_is_associated_with_an_exising_customer') }
validates :enterprise_id, presence: true
validates :enterprise, presence: true
scope :of, ->(enterprise) { where(enterprise_id: enterprise) }

View File

@@ -1,5 +1,5 @@
class DistributorShippingMethod < ActiveRecord::Base
self.table_name = "distributors_shipping_methods"
belongs_to :shipping_method, class_name: Spree::ShippingMethod, touch: true
belongs_to :distributor, class_name: Enterprise, touch: true
belongs_to :shipping_method, class_name: "Spree::ShippingMethod", touch: true
belongs_to :distributor, class_name: "Enterprise", touch: true
end

View File

@@ -250,7 +250,7 @@ class Enterprise < ActiveRecord::Base
def plus_relatives_and_oc_producers(order_cycles)
oc_producer_ids = Exchange.in_order_cycle(order_cycles).incoming.pluck :sender_id
Enterprise.relatives_of_one_union_others(id, oc_producer_ids | [id])
Enterprise.is_primary_producer.relatives_of_one_union_others(id, oc_producer_ids | [id])
end
def relatives_including_self

View File

@@ -41,7 +41,7 @@ class EnterpriseFee < ActiveRecord::Base
}
def self.clear_all_adjustments(order)
order.adjustments.enterprise_fee.destroy_all
order.all_adjustments.enterprise_fee.destroy_all
end
private

View File

@@ -5,7 +5,7 @@ class EnterpriseRelationship < ActiveRecord::Base
belongs_to :child, class_name: 'Enterprise', touch: true
has_many :permissions, class_name: 'EnterpriseRelationshipPermission', dependent: :destroy
validates :parent_id, :child_id, presence: true
validates :parent, :child, presence: true
validates :child_id, uniqueness: {
scope: :parent_id,
message: I18n.t('validation_msg_relationship_already_established')
@@ -81,7 +81,7 @@ class EnterpriseRelationship < ActiveRecord::Base
end
def has_permission?(name)
permissions(:reload).map(&:name).map(&:to_sym).include? name.to_sym
permissions.reload.map(&:name).map(&:to_sym).include? name.to_sym
end
private

View File

@@ -1,8 +1,8 @@
class EnterpriseRole < ActiveRecord::Base
belongs_to :user, class_name: Spree.user_class
belongs_to :user, class_name: Spree.user_class.to_s
belongs_to :enterprise
validates :user_id, :enterprise_id, presence: true
validates :user, :enterprise, presence: true
validates :enterprise_id, uniqueness: { scope: :user_id, message: I18n.t(:enterprise_role_uniqueness_error) }
scope :by_user_email, -> { joins(:user).order('spree_users.email ASC') }

View File

@@ -3,8 +3,8 @@ class InventoryItem < ActiveRecord::Base
belongs_to :variant, class_name: "Spree::Variant"
validates :variant_id, uniqueness: { scope: :enterprise_id }
validates :enterprise_id, presence: true
validates :variant_id, presence: true
validates :enterprise, presence: true
validates :variant, presence: true
validates :visible, inclusion: { in: [true, false], message: I18n.t(:inventory_item_visibility_error) }
scope :visible, -> { where(visible: true) }

View File

@@ -16,8 +16,8 @@ class OrderCycle < ActiveRecord::Base
has_many :suppliers, -> { distinct }, source: :sender, through: :cached_incoming_exchanges
has_many :distributors, -> { distinct }, source: :receiver, through: :cached_outgoing_exchanges
has_many :schedules, through: :order_cycle_schedules
has_many :order_cycle_schedules
has_many :schedules, through: :order_cycle_schedules
has_paper_trail meta: { custom_data: proc { |order_cycle| order_cycle.schedule_ids.to_s } }
attr_accessor :incoming_exchanges, :outgoing_exchanges

View File

@@ -1,10 +1,9 @@
class Schedule < ActiveRecord::Base
has_paper_trail meta: { custom_data: proc { |schedule| schedule.order_cycle_ids.to_s } }
has_many :order_cycles, through: :order_cycle_schedules
has_many :order_cycle_schedules, dependent: :destroy
has_many :coordinators, -> { uniq }, through: :order_cycles
has_many :order_cycles, through: :order_cycle_schedules
has_many :coordinators, -> { distinct }, through: :order_cycles
scope :with_coordinator, lambda { |enterprise| joins(:order_cycles).where('coordinator_id = ?', enterprise.id).select('DISTINCT schedules.*') }

View File

@@ -152,7 +152,9 @@ module Spree
end
def touch_enterprise
enterprise.andand.touch
return unless enterprise&.persisted?
enterprise.touch
end
def render_address(parts)

View File

@@ -36,8 +36,6 @@ module Spree
preference :allow_ssl_in_development_and_test, :boolean, default: false
preference :allow_ssl_in_production, :boolean, default: true
preference :allow_ssl_in_staging, :boolean, default: true
# Automatically capture the credit card (as opposed to just authorize and capture later)
preference :auto_capture, :boolean, default: false
# Replace with the name of a zone if you would like to limit the countries
preference :checkout_zone, :string, default: nil
preference :currency, :string, default: "USD"
@@ -113,6 +111,7 @@ module Spree
# Legal Preferences
preference :footer_tos_url, :string, default: "/Terms-of-service.pdf"
preference :enterprises_require_tos, :boolean, default: false
preference :shoppers_require_tos, :boolean, default: false
preference :privacy_policy_url, :string, default: nil
preference :cookies_consent_banner_toggle, :boolean, default: false
preference :cookies_policy_matomo_section, :boolean, default: false

View File

@@ -31,10 +31,6 @@ module Spree
provider_class.new
end
def auto_capture?
true
end
def method_type
'paypal'
end

View File

@@ -7,10 +7,9 @@ module Spree
class LineItem < ActiveRecord::Base
include VariantUnits::VariantAndLineItemNaming
include LineItemStockChanges
include LineItemBasedAdjustmentHandling
belongs_to :order, class_name: "Spree::Order", inverse_of: :line_items
belongs_to :variant, class_name: "Spree::Variant"
belongs_to :variant, -> { with_deleted }, class_name: "Spree::Variant"
belongs_to :tax_category, class_name: "Spree::TaxCategory"
has_one :product, through: :variant
@@ -154,18 +153,6 @@ module Spree
@preferred_shipment = shipment
end
# Remove product default_scope `deleted_at: nil`
def product
variant.product
end
# This ensures that LineItems always have access to soft-deleted variants.
# In some situations, unscoped super will be nil. In these cases,
# we fetch the variant using variant_id. See issue #4946 for more details.
def variant
Spree::Variant.unscoped { super } || Spree::Variant.unscoped.find(variant_id)
end
def cap_quantity_at_stock!
scoper.scope(variant)
return if variant.on_demand
@@ -174,11 +161,11 @@ module Spree
end
def has_tax?
adjustments.included_tax.any?
adjustments.tax.any?
end
def included_tax
adjustments.included_tax.sum(:included_tax)
adjustments.tax.inclusive.sum(:amount)
end
def tax_rates
@@ -190,9 +177,9 @@ module Spree
# so line_item.adjustments returns an empty array
return 0 if quantity.zero?
line_item_adjustments = OrderAdjustmentsFetcher.new(order).line_item_adjustments(self)
fees = adjustments.enterprise_fee.sum(:amount)
(price + line_item_adjustments.to_a.sum(&:amount) / quantity).round(2)
(price + fees / quantity).round(2)
end
def single_display_amount_with_adjustments
@@ -220,9 +207,9 @@ module Spree
end
def unit_price_price_and_unit
price = Spree::Money.new((rand * 10).round(2), currency: currency)
unit = ["item", "kg"].sample
price.to_html + " / " + unit
unit_price = UnitPrice.new(variant)
Spree::Money.new(price_with_adjustments / unit_price.denominator).to_html +
" / " + unit_price.unit
end
def scoper

View File

@@ -9,7 +9,9 @@ require 'concerns/order_shipment'
module Spree
class Order < ActiveRecord::Base
prepend OrderShipment
include Checkout
include Balance
checkout_flow do
go_to_state :address
@@ -40,16 +42,16 @@ module Spree
as: :adjustable,
dependent: :destroy
has_many :line_item_adjustments, through: :line_items, source: :adjustments
has_many :shipment_adjustments, through: :shipments, source: :adjustments
has_many :all_adjustments, class_name: 'Spree::Adjustment', dependent: :destroy
has_many :shipments, dependent: :destroy do
def states
pluck(:state).uniq
end
end
has_many :line_item_adjustments, through: :line_items, source: :adjustments
has_many :shipment_adjustments, through: :shipments, source: :adjustments
has_many :all_adjustments, class_name: 'Spree::Adjustment', dependent: :destroy
belongs_to :order_cycle
belongs_to :distributor, class_name: 'Enterprise'
belongs_to :customer
@@ -125,7 +127,7 @@ module Spree
}
scope :not_state, lambda { |state|
where("state != ?", state)
where.not(state: state)
}
# All the states an order can be in after completing the checkout
@@ -166,10 +168,6 @@ module Spree
self[:currency] || Spree::Config[:currency]
end
def display_outstanding_balance
Spree::Money.new(outstanding_balance, currency: currency)
end
def display_item_total
Spree::Money.new(item_total, currency: currency)
end
@@ -280,7 +278,7 @@ module Spree
# Spree::OrderContents#add is the more modern version in Spree history
# but this add_variant has been customized for OFN FrontOffice.
def add_variant(variant, quantity = 1, max_quantity = nil, currency = nil)
line_items(:reload)
line_items.reload
current_item = find_line_item_by_variant(variant)
# Notify bugsnag if we get line items with a quantity of zero
@@ -374,14 +372,6 @@ module Spree
Spree::TaxRate.adjust(self)
end
def outstanding_balance
total - payment_total
end
def outstanding_balance?
outstanding_balance != 0
end
def name
address = bill_address || ship_address
return unless address
@@ -476,14 +466,6 @@ module Spree
false
end
def billing_firstname
bill_address.try(:firstname)
end
def billing_lastname
bill_address.try(:lastname)
end
def products
line_items.map(&:product)
end
@@ -638,7 +620,7 @@ module Spree
end
def remove_variant(variant)
line_items(:reload)
line_items.reload
current_item = find_line_item_by_variant(variant)
current_item.andand.destroy
end
@@ -664,15 +646,15 @@ module Spree
end
def shipping_tax
shipment_adjustments(:reload).shipping.sum(:included_tax)
shipment_adjustments.reload.shipping.sum(:included_tax)
end
def enterprise_fee_tax
adjustments(:reload).enterprise_fee.sum(:included_tax)
all_adjustments.reload.enterprise_fee.sum(:included_tax)
end
def total_tax
all_adjustments.sum(:included_tax)
additional_tax_total + included_tax_total
end
def has_taxes_included

View File

@@ -130,22 +130,6 @@ module Spree
steps << "complete" unless steps.include?("complete")
steps
end
def checkout_step?(step)
step.present? ? checkout_steps.include?(step) : false
end
def checkout_step_index(step)
checkout_steps.index(step)
end
def can_go_to_state?(state)
return false unless self.state.present? &&
checkout_step?(state) &&
checkout_step?(self.state)
checkout_step_index(state) > checkout_step_index(self.state)
end
end
end
end

View File

@@ -98,8 +98,7 @@ module Spree
inventory_unit.destroy
removed_quantity += 1
end
shipment.destroy if shipment.inventory_units.count == 0
shipment.destroy if shipment.inventory_units.reload.count == 0
# removing this from shipment, and adding to stock_location
if order.completed?

View File

@@ -20,7 +20,7 @@ module Spree
class_name: "Spree::Payment", foreign_key: :source_id
has_many :log_entries, as: :source, dependent: :destroy
has_one :adjustment, as: :source, dependent: :destroy
has_one :adjustment, as: :adjustable, dependent: :destroy
validate :validate_source
before_create :set_unique_identifier
@@ -135,8 +135,8 @@ module Spree
adjustment.label = adjustment_label
adjustment.save
else
payment_method.create_adjustment(adjustment_label, order, self, true)
association(:adjustment).reload
payment_method.create_adjustment(adjustment_label, self, self, true)
adjustment.reload
end
end
@@ -154,8 +154,10 @@ module Spree
return unless adjustment.try(:reload)
return if adjustment.finalized?
adjustment.update_attribute(:eligible, false)
adjustment.finalize!
adjustment.update(
eligible: false,
state: "finalized"
)
end
def validate_source

View File

@@ -6,22 +6,14 @@ module Spree
def process!
return unless validate!
if payment_method.auto_capture?
purchase!
else
authorize!
end
purchase!
end
def process_offline!
return unless validate!
return if authorization_action_required?
if payment_method.auto_capture?
charge_offline!
else
authorize!
end
charge_offline!
end
def authorize!(return_url = nil)

View File

@@ -89,10 +89,6 @@ module Spree
true
end
def auto_capture?
Spree::Config[:auto_capture]
end
def supports?(_source)
true
end

View File

@@ -52,11 +52,11 @@ module Spree
dependent: :destroy
has_many :variants, -> {
where(is_master: false).order("#{::Spree::Variant.quoted_table_name}.position ASC")
where(is_master: false).order("spree_variants.position ASC")
}, class_name: 'Spree::Variant'
has_many :variants_including_master,
-> { order("#{::Spree::Variant.quoted_table_name}.position ASC") },
-> { order("spree_variants.position ASC") },
class_name: 'Spree::Variant',
dependent: :destroy
@@ -86,11 +86,12 @@ module Spree
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 :shipping_category, 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 :tax_category, presence: true,
if: proc { Spree::Config[:products_require_tax_category] }
validates :variant_unit, presence: true
validates :unit_value, presence: { if: ->(p) { %w(weight volume).include? p.variant_unit } }
@@ -172,7 +173,7 @@ module Spree
scope :in_distributors, lambda { |distributors|
with_order_cycles_outer.
where('(o_exchanges.incoming = ? AND o_exchanges.receiver_id IN (?))', false, distributors).
uniq
distinct
}
# Products supplied by a given enterprise or distributed via that enterprise through an OC
@@ -366,7 +367,7 @@ module Spree
Spree::OptionType.where('name LIKE ?', 'unit_%%')
end
def destroy_with_delete_from_order_cycles
def destroy
transaction do
touch_distributors
@@ -374,10 +375,9 @@ module Spree
where('exchange_variants.variant_id IN (?)', variants_including_master.with_deleted.
select(:id)).destroy_all
destroy_without_delete_from_order_cycles
super
end
end
alias_method_chain :destroy, :delete_from_order_cycles
private

View File

@@ -284,6 +284,10 @@ module Spree
I18n.t('shipping')
end
def can_modify?
!shipped? && !order.canceled?
end
private
def manifest_unstock(item)

View File

@@ -10,10 +10,10 @@ module Spree
default_scope -> { where(deleted_at: nil) }
has_many :shipping_rates, inverse_of: :shipping_method
has_many :shipments, through: :shipping_rates
has_many :shipping_method_categories
has_many :shipping_categories, through: :shipping_method_categories
has_many :shipping_rates, inverse_of: :shipping_method
has_many :distributor_shipping_methods
has_many :distributors, through: :distributor_shipping_methods,
class_name: 'Enterprise',

View File

@@ -20,7 +20,7 @@ module Spree
belongs_to :tax_category, class_name: "Spree::TaxCategory", inverse_of: :tax_rates
validates :amount, presence: true, numericality: true
validates :tax_category_id, presence: true
validates :tax_category, presence: true
validates_with DefaultTaxZoneValidator
scope :by_zone, ->(zone) { where(zone_id: zone) }
@@ -80,13 +80,8 @@ module Spree
create_adjustment(label, order, order)
end
order.adjustments(:reload)
order.line_items(:reload)
# TaxRate adjustments (order.adjustments.tax)
# and line item adjustments (tax included on line items) consist of 100% tax
(order.adjustments.tax + order.line_item_adjustments.reload).each do |adjustment|
adjustment.set_absolute_included_tax! adjustment.amount
end
order.adjustments.reload
order.line_items.reload
end
def default_zone_or_zone_match?(order)

View File

@@ -109,7 +109,7 @@ module Spree
end
def can_own_more_enterprises?
owned_enterprises(:reload).size < enterprise_limit
owned_enterprises.reload.size < enterprise_limit
end
def default_card

View File

@@ -13,7 +13,8 @@ module Spree
acts_as_paranoid
belongs_to :product, touch: true, class_name: 'Spree::Product'
belongs_to :product, -> { with_deleted }, 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
@@ -109,12 +110,13 @@ module Spree
}
scope :not_hidden_for, lambda { |enterprise|
return where("1=0") if enterprise.blank?
enterprise_id = enterprise&.id.to_i
return none if enterprise_id < 1
joins("
LEFT OUTER JOIN (SELECT *
FROM inventory_items
WHERE enterprise_id = #{sanitize enterprise.andand.id})
WHERE enterprise_id = #{enterprise_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)
@@ -187,13 +189,6 @@ module Spree
price_in(currency).try(:amount)
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)
@@ -244,7 +239,7 @@ module Spree
end
def destruction
exchange_variants(:reload).destroy_all
exchange_variants.reload.destroy_all
yield
end

View File

@@ -8,8 +8,8 @@ class Subscription < ActiveRecord::Base
belongs_to :schedule
belongs_to :shipping_method, class_name: 'Spree::ShippingMethod'
belongs_to :payment_method, class_name: 'Spree::PaymentMethod'
belongs_to :bill_address, foreign_key: :bill_address_id, class_name: Spree::Address
belongs_to :ship_address, foreign_key: :ship_address_id, class_name: Spree::Address
belongs_to :bill_address, foreign_key: :bill_address_id, class_name: "Spree::Address"
belongs_to :ship_address, foreign_key: :ship_address_id, class_name: "Spree::Address"
has_many :subscription_line_items, inverse_of: :subscription
has_many :order_cycles, through: :schedule
has_many :proxy_orders

View File

@@ -1,3 +1,7 @@
# frozen_string_literal: true
require 'spree/localized_number'
class VariantOverride < ActiveRecord::Base
extend Spree::LocalizedNumber
include StockSettingsOverrideValidation
@@ -7,8 +11,8 @@ class VariantOverride < ActiveRecord::Base
belongs_to :hub, class_name: 'Enterprise'
belongs_to :variant, class_name: 'Spree::Variant'
validates :hub_id, presence: true
validates :variant_id, presence: true
validates :hub, presence: true
validates :variant, presence: true
# Default stock can be nil, indicating stock should not be reset or zero, meaning reset to zero. Need to ensure this can be set by the user.
validates :default_stock, numericality: { greater_than_or_equal_to: 0 }, allow_nil: true

View File

@@ -0,0 +1,15 @@
# frozen_string_literal: true
class CompleteVisibleOrders
def initialize(order_permissions)
@order_permissions = order_permissions
end
def query
order_permissions.visible_orders.complete
end
private
attr_reader :order_permissions
end

View File

@@ -8,6 +8,9 @@
# cases.
#
# See CompleteOrdersWithBalance or CustomersWithBalance as examples.
#
# Note this query object and `app/models/concerns/balance.rb` should implement the same behavior
# until we find a better way. If you change one, please, change the other too.
class OutstandingBalance
# All the states of a finished order but that shouldn't count towards the balance (the customer
# didn't get the order for whatever reason). Note it does not include complete
@@ -27,8 +30,8 @@ class OutstandingBalance
# a little longer. See https://github.com/rails/arel/pull/400 for details.
def statement
<<-SQL.strip_heredoc
CASE WHEN state IN #{non_fulfilled_states_group.to_sql} THEN payment_total
WHEN state IS NOT NULL THEN payment_total - total
CASE WHEN "spree_orders"."state" IN #{non_fulfilled_states_group.to_sql} THEN "spree_orders"."payment_total"
WHEN "spree_orders"."state" IS NOT NULL THEN "spree_orders"."payment_total" - "spree_orders"."total"
ELSE 0 END
SQL
end

View File

@@ -12,7 +12,7 @@ module Api
def adjustments
adjustments = object.all_adjustments.where(
adjustable_type: ["Spree::Order", "Spree::Shipment"]
adjustable_type: ["Spree::Order", "Spree::Shipment", "Spree::Payment"]
).order(label: :desc)
ActiveModel::ArraySerializer.new(adjustments, each_serializer: Api::AdjustmentSerializer)
end

View File

@@ -41,10 +41,16 @@ class Api::VariantSerializer < ActiveModel::Serializer
end
def unit_price_price
(rand * 10).round(2)
price_with_fees / (unit_price.denominator || 1)
end
def unit_price_unit
rand > 0.5 ? "item" : "kg"
unit_price.unit
end
private
def unit_price
@unit_price ||= UnitPrice.new(object)
end
end

View File

@@ -1,4 +1,8 @@
class InvoiceRenderer
def initialize(renderer = ApplicationController.new)
@renderer = renderer
end
def render_to_string(order)
renderer.instance_variable_set(:@order, order)
renderer.render_to_string(args(order))
@@ -15,9 +19,7 @@ class InvoiceRenderer
private
def renderer
@renderer ||= ApplicationController.new
end
attr_reader :renderer
def invoice_template
if Spree::Config.invoice_style2?

View File

@@ -29,20 +29,12 @@ class OrderAdjustmentsFetcher
sum_adjustments "shipping"
end
def line_item_adjustments(line_item)
if adjustments_eager_loaded?
adjustments.select{ |adjustment| adjustment.source_id == line_item.id }
else
adjustments.where(source_id: line_item.id)
end
end
private
attr_reader :order
def adjustments
order.adjustments
order.all_adjustments
end
def adjustments_eager_loaded?

View File

@@ -13,7 +13,7 @@ class OrderCheckoutRestart
clear_shipments
clear_payments
order.reload
order.reload.update!
end
private

View File

@@ -19,6 +19,9 @@ class OrderFeesHandler
create_line_item_fees!
create_order_fees!
order.updater.update_totals
order.updater.persist_totals
end
order.update!

View File

@@ -21,7 +21,6 @@ class OrderTaxAdjustmentsFetcher
def all
Spree::Adjustment
.with_tax
.where(order_adjustments.or(line_item_adjustments).or(shipment_adjustments))
.order('created_at ASC')
end
@@ -50,11 +49,27 @@ class OrderTaxAdjustmentsFetcher
Hash[tax_rates.collect do |tax_rate|
tax_amount = if tax_rates.one?
adjustment.included_tax
adjustment_tax_amount(adjustment)
else
tax_rate.compute_tax(adjustment.amount)
end
[tax_rate, tax_amount]
end]
end
def adjustment_tax_amount(adjustment)
if no_tax_adjustments?(adjustment)
adjustment.included_tax
else
adjustment.amount
end
end
def no_tax_adjustments?(adjustment)
# Enterprise Fees, Admin Adjustments, and Shipping Fees currently do not have tax adjustments.
# The tax amount is stored in the included_tax attribute.
adjustment.originator_type == "EnterpriseFee" ||
adjustment.originator_type == "Spree::ShippingMethod" ||
(adjustment.source_type.nil? && adjustment.originator_type.nil?)
end
end

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