Compare commits

...

337 Commits
v4.6 ... v4.6.9

Author SHA1 Message Date
Maikel Linke
2be3f7b86d Update all locales with the latest Transifex translations 2024-10-10 17:08:38 +11:00
Maikel
2d975c5534 Merge pull request #12899 from mkllnk/dfc-stock-check
DFC Orders update for pilot 1 and 2
2024-10-10 17:06:18 +11:00
Maikel Linke
86c91143b7 Update more variant data on import 2024-10-10 16:59:04 +11:00
Maikel Linke
cde757efbd Split growing class 2024-10-10 16:58:01 +11:00
Maikel Linke
260e7ba817 Update products when importing them multiple times
Instead of creating a new variant every time.
2024-10-10 16:57:58 +11:00
Maikel Linke
bda506528f Fix import of zero-weight products
We don't allow variants to have zero weight or volume. But a DFC import
in production showed that some catalogs list products with zero weight.
Despite the products having a weight, it's simpler to treat these as
items.
2024-10-10 14:08:02 +11:00
Maikel Linke
e429cb7198 Style growing class 2024-10-10 14:06:42 +11:00
Maikel Linke
a838ef4a21 DRY DFC product import 2024-10-10 14:04:54 +11:00
Maikel Linke
f0b6403c1d Fix locally flaky spec around date filters
This spec would fail on Australian systems early in the morning or in
other timezones accordingly.
2024-10-10 09:58:01 +11:00
Maikel Linke
71ca292c92 Synchronise stock with DFC catalog during checkout
This will delay the checkout request by a few seconds if there's stock
to sync. But we minimise the chance of missing reduced stock from orders
on another platform.

We still have a gap between the checkout and placing a backorder. In
that time we can't guarantee enough stock. But let's tackle that after
the pilot.
2024-10-09 14:47:07 +11:00
Maikel Linke
adf0340153 Remove duplicate method
The method `CheckoutCallbacks#valid_order_line_items?` was a duplicate
of `OrderStockCheck#valid_order_line_items?`.

Apparently, it had been extracted twice:

 * 1d074c2151
 * 06eb98bdf4

But the first commit duplicated the method while the second moved the
original declaration.
2024-10-08 16:57:36 +11:00
Maikel Linke
664f324db6 Sync stock of multiple linked catalogs
And the logic becomes a bit simpler.
2024-10-08 16:37:35 +11:00
Maikel Linke
c609107379 Avoid race condition between checkout and stock sync 2024-10-08 16:03:10 +11:00
Maikel
6f2c5b5f7f Merge pull request #12888 from mkllnk/dfc-stock
[DFC Orders] Backorder stock controlled products
2024-10-08 10:57:59 +11:00
Gaetan Craig-Riou
e5b7f89b32 Merge pull request #12887 from mkllnk/stock-cleanup2
Remove unneeded StockLocation code
2024-10-07 09:40:46 +11:00
filipefurtad0
b7c34ced26 Update all locales with the latest Transifex translations 2024-10-05 22:35:38 +01:00
Rachel Arnould
f5baa42bfc Merge pull request #12860 from chahmedejaz/bugfix/12852-fix-select2-choices-fixed-height
[BUU] Fix Display ordering in shopfront field to allow re-ordering of the sequence
2024-10-04 16:59:54 +02:00
Maikel Linke
86238cc0ee Update all locales with the latest Transifex translations 2024-10-04 17:10:58 +10:00
Maikel Linke
61aa02b3c3 Sync stock with DFC catalog after cart update 2024-10-04 16:25:17 +10:00
Maikel Linke
4b2099625c Clarify method action with name
Thanks, David.
2024-10-04 14:34:17 +10:00
Maikel Linke
f8bd0a1cc7 Adjust backorder for stock controlled items
We aggregate quantities over the whole order cycle to account for
cancelations and order adjustments by admins.
2024-10-03 15:58:53 +10:00
Maikel Linke
09de223c93 Backorder stock controlled products 2024-10-03 13:30:16 +10:00
Maikel Linke
74c80c9fff Prepare BackorderJob for stock controlled items
We want to trigger the backordering for any linked product now. So let's
do that check early and then select the variants in the background.
It means less data passed to the job and less space for race conditions.
2024-10-03 13:28:20 +10:00
Maikel Linke
11f3bbc566 Remove leftover recording 2024-10-03 13:28:17 +10:00
Maikel Linke
e5ee398f26 Re-use default stock location in specs 2024-10-03 08:24:16 +10:00
Maikel Linke
99c098f567 Ignore StockLocation#active, it's always active 2024-10-03 08:24:16 +10:00
Maikel Linke
4b1d7d8a41 Remove dead permission to access StockLocation
We don't have any UI to edit stock locations. So this ability is unused.
2024-10-03 08:24:15 +10:00
Maikel Linke
1e3c18f3f6 Remove unneeded method StockLocation#propagate_variant 2024-10-03 08:24:15 +10:00
Gaetan Craig-Riou
63a1b390e2 Merge pull request #12885 from mkllnk/stock-cleanup
Remove use of unnecessary backorderable default column
2024-10-02 16:24:08 +10:00
Gaetan Craig-Riou
6eb5986c68 Merge pull request #12884 from mkllnk/oc-index
Add database index to order cycle dates
2024-10-02 16:01:50 +10:00
Maikel Linke
4d9f396f40 Ignore unused column spree_stock_locations.backorderable_default 2024-10-02 15:16:05 +10:00
Maikel Linke
ac3730096f Update specs to assume backorderable default 2024-10-02 15:13:00 +10:00
Maikel Linke
662467a1a4 Use database default value for stock_items.backorderable 2024-10-02 15:09:44 +10:00
Maikel Linke
af07358914 Assume on-demand is false by default
We have only one stock location and that has the default set to false.
Now we can simplify code.

The mentioned Bugsnag notification has not been found. The stock item is
always present in this case but it doesn't hurt to guard against it with
`&.`.
2024-10-02 15:06:48 +10:00
Maikel Linke
8e7e5fc20f Add database index to order cycle dates 2024-10-02 12:05:13 +10:00
Maikel
3c613f80a3 Merge pull request #12875 from macanudo527/docker/upgrade_to_dockerv2
Use Dockerv2
2024-10-02 08:53:24 +10:00
Gaetan Craig-Riou
83b6f58100 Merge pull request #12881 from mkllnk/card-payment-spec
Fix date dependent spec
2024-10-01 13:30:49 +10:00
Maikel Linke
17c32ae09a Spec change more clearly 2024-10-01 13:16:16 +10:00
Maikel Linke
0474c591de Fix date-dependent spec 2024-10-01 13:14:09 +10:00
Maikel
196956140e Merge pull request #12856 from mkllnk/dfc-order
Place backorders for linked products via DFC integration
2024-10-01 10:51:00 +10:00
Gaetan Craig-Riou
91f2ca9286 Merge pull request #12734 from cillian/replace-text-angular-with-trix
Replace text angular editor with trix editor in About Us and Shopfront message fields
2024-09-30 09:40:48 +10:00
filipefurtad0
3015beab99 Update all locales with the latest Transifex translations 2024-09-27 18:02:50 -06:00
Filipe
da0660c119 Merge pull request #12857 from chahmedejaz/task/12626-add-clone-failure-explaination
[BUU] Fix No explanation why cloning failed
2024-09-27 17:58:31 -06:00
Filipe
852dd41f89 Merge pull request #12836 from wandji20/wb-OFN-11600
Add browser unsaved changes modal when navigating from order summary page [OFN-11600]
2024-09-27 17:41:04 -06:00
Filipe
48993232d1 Merge pull request #12833 from dacook/page-titles
[admin] Update page titles
2024-09-27 16:59:43 -06:00
wandji20
0002b2e019 Clean up hardcoded values and improve readability 2024-09-27 16:52:55 -06:00
wandji20
84a2e6c24d Add browser unsaved changes modal when navigation form order sumary page [OFN-11600] 2024-09-27 16:52:55 -06:00
David Cook
be4e0a259e Specify alternate html_title
Because the page title has extra content.
2024-09-27 15:48:28 -06:00
David Cook
c362e8dd0d Use page titles in HTML head
This is much  more meaningful than the controller name, and is helpful for browser tab history.
2024-09-27 15:48:28 -06:00
Ahmed Ejaz
1550ca5da0 fix the choice drag issue
- disabled width on select2-search-choice-close so that it doesn't cover whole option
2024-09-27 16:57:35 +05:00
Cillian O'Ruanaidh
f474afaceb Merge in latest :master and resolve conflict in app/models/enterprise.rb 2024-09-27 10:11:26 +01:00
Sigmund Petersen
8c71760556 Merge pull request #12784 from wandji20/wb-OFN-12774
Make OC edit warning modal cancel button redirect user to OC list [OFN-12774]
2024-09-27 10:42:54 +02:00
wandji20
37ab832b86 Remove window unload event listener from edit order cycle cancel link 2024-09-27 10:02:49 +02:00
wandji20
a11873559b Make OC edit warning modal cancel button redirect user to OC list [OFN-12774] 2024-09-27 10:02:49 +02:00
Maikel Linke
51b3770188 Keep failed backorder job in dead set
From Sidekiq's view, the job is successful when we rescue an error and
it will discard it. But we want the option to inspect the job and retry
it. Failing jobs are also reported to Bugsnag automatically.

I didn't specify `retry: false` because that discards the job as well.
But `retry: 0` should sent it straight to the dead set. No automatic
retries but it's treated like a failed job.
2024-09-26 14:32:55 +10:00
Maikel Linke
989a6d57e0 Notify user of failed backorder completion 2024-09-26 14:32:55 +10:00
Maikel Linke
495634b60c Send error notification to owner 2024-09-26 14:32:55 +10:00
Maikel Linke
49fd1dc4a6 Report backorder errors instead of failing checkout 2024-09-26 14:32:55 +10:00
Maikel Linke
e31e45b875 Place backorders in the background 2024-09-26 14:32:55 +10:00
Maikel Linke
61fec653cf Abstract OrderLocker for re-use 2024-09-26 14:32:55 +10:00
Maikel Linke
eece738865 Restore concurrency spec for the checkout
This was abandoned when the checkout was re-designed. But I want to
refactor the order locking mechanism and it would be good to know that I
don't break anything.
2024-09-26 14:32:55 +10:00
Maikel Linke
2465780c1c Import prices and stock levels from DFC catalog
We were already importing stock levels from offers but now we are
looking at catalog items as well.
2024-09-26 14:32:01 +10:00
Neal Chambers
21b7e6e567 Use Dockerv2 2024-09-26 09:21:00 +09:00
Maikel Linke
9f43244312 Import on-demand stock setting in DFC import 2024-09-25 10:55:41 +10:00
Maikel Linke
66f080232f Import DFC product images 2024-09-25 10:55:41 +10:00
Maikel Linke
7f62b49da5 Move catalog loading to where it's needed 2024-09-25 10:55:41 +10:00
Maikel Linke
070b93c531 Fall back to givin product id w/o retail variant 2024-09-25 10:55:40 +10:00
Maikel Linke
fb96f8f936 Fall back to given product w/o wholesale variant
The class is moving to providing all data with several methods instead
of a data class containing the information. That should be more
flexible. Still some work to do.
2024-09-25 10:55:40 +10:00
Maikel Linke
4303f0e974 Build API URLs to work with any FDC Shopify shop
We can extend this service class when there are other APIs. And
hopefully the DFC will provide a standard for this discovery at some
point.
2024-09-25 10:55:40 +10:00
Maikel Linke
2eec4c73bf Apply 4 hour completion delay only to one enterprise 2024-09-25 10:55:40 +10:00
Maikel Linke
5ef85aef3e Handle backorder cancellations 2024-09-25 10:55:40 +10:00
Maikel Linke
283db8f9d0 Adjust quantities of backorder before completion 2024-09-25 10:55:40 +10:00
Maikel Linke
95e620a78b Add lookup of variants by semantic id 2024-09-25 10:55:40 +10:00
Maikel Linke
c948efd9ce Add structure to adjust final quantities 2024-09-25 10:55:40 +10:00
Maikel Linke
95bc0cc679 Reduce complexity of BackorderJob 2024-09-25 10:55:40 +10:00
Maikel Linke
efe2b724e6 Find wholesale offer for retail variant 2024-09-25 10:55:40 +10:00
Maikel Linke
14c32c0d2e Reduce complexity 2024-09-25 10:55:40 +10:00
Maikel Linke
8f4f873ba0 Move offer finding into separate class
It's going to be more complicated.
2024-09-25 10:55:40 +10:00
Maikel Linke
c0ae2ede2c Complete order 4 hours after order cycle closed 2024-09-25 10:55:40 +10:00
Maikel Linke
3ec53a7d71 Parse updated order result 2024-09-25 10:55:40 +10:00
Maikel Linke
3849db7c48 Simplify order update call 2024-09-25 10:55:39 +10:00
Maikel Linke
7b286ea31d Complete test for FDC Orders API
Previous specs testing the live API assumed an order to be present or
not present. You needed to provide the right state before recording. I
condensed more into one test that completes the cycle and is repeatable,
assuming no order to start with.
2024-09-25 10:55:39 +10:00
Maikel Linke
3e0eb8708e Simplify service with ivar 2024-09-25 10:55:39 +10:00
Maikel Linke
c7fa3ff819 Simplify order update logic 2024-09-25 10:55:39 +10:00
Maikel Linke
f839452df9 Complete an open order 2024-09-25 10:55:39 +10:00
Maikel Linke
a7a38890f4 Add needed quantities to existing line items 2024-09-25 10:55:39 +10:00
Maikel Linke
caa6d284f0 Find and update existing open order 2024-09-25 10:55:39 +10:00
Maikel Linke
827e37cada Start moving backorder logic to service
The job class is getting too big.
2024-09-25 10:55:39 +10:00
Maikel Linke
6c6927af84 Add SaleSession with correct OrderCycle times
Apparently, the FDC implementation uses those dates to finalise orders.
2024-09-25 10:55:39 +10:00
Maikel Linke
439f0cac64 Raise errors on DFC requests
The simplified API was only returning the response body, not allowing us
to inspect if an error occurred. Since an error should be an exception
when communicating with a standardised protocol, we raise an error and
keep our simple API.
2024-09-25 10:55:39 +10:00
Maikel Linke
98966f6b89 Place backorders for DFC products 2024-09-25 10:55:39 +10:00
Maikel Linke
260e4f7b00 Create BackorderJob to place wholesale orders 2024-09-25 10:55:39 +10:00
Gaetan Craig-Riou
099da3fc6c Merge pull request #12872 from mkllnk/enterprise-serialiser
Clean up enterprise serialiser for shop page speed
2024-09-23 10:14:44 +10:00
Gaetan Craig-Riou
7078c4ef03 Merge pull request #12871 from openfoodfoundation/dependabot/npm_and_yarn/body-parser-1.20.3
Bump body-parser from 1.20.2 to 1.20.3
2024-09-23 10:09:49 +10:00
Maikel Linke
318790d207 Remove unused join table
Enterprises used to have products and products have variants. But now
enterprises have variants directly.
2024-09-20 16:44:25 +10:00
Maikel Linke
2be8ef96be Remove unreachable code
These two methods return early if `active` is falsey. So for the rest of
the method we can assume `active` to be truthy.
2024-09-20 16:35:41 +10:00
Maikel Linke
f6e4b107b0 Update all locales with the latest Transifex translations 2024-09-20 09:46:02 +10:00
Filipe
a5d17b4da9 Merge pull request #12459 from mkllnk/description-html
Sanitise HTML in long description of enterprise
2024-09-19 16:12:45 -06:00
Filipe
83ab9594f6 Merge pull request #12854 from chahmedejaz/task/11200-conditionally-hide-producer-column
[BUU2] Hide producer column when there's only one producer in the admin account
2024-09-19 15:42:15 -06:00
Filipe
562a24524b Merge pull request #12848 from rioug/12770-product-preview
Product preview
2024-09-19 15:20:18 -06:00
Filipe
2809194b42 Merge pull request #12847 from dacook/fix-bug-12835
Fix bug #12835 for producer reports
2024-09-19 14:31:04 -06:00
Maikel
7d3eff2abb Merge pull request #12845 from wandji20/wb-OFN-12281
Fix- chore(deps): bump debounced from 0.0.5 to 1.0.2
2024-09-19 11:22:30 +10:00
dependabot[bot]
c0a49df150 Bump body-parser from 1.20.2 to 1.20.3
Bumps [body-parser](https://github.com/expressjs/body-parser) from 1.20.2 to 1.20.3.
- [Release notes](https://github.com/expressjs/body-parser/releases)
- [Changelog](https://github.com/expressjs/body-parser/blob/master/HISTORY.md)
- [Commits](https://github.com/expressjs/body-parser/compare/1.20.2...1.20.3)

---
updated-dependencies:
- dependency-name: body-parser
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-09-18 23:20:33 +00:00
David Cook
f8bb33a9e8 Merge pull request #12869 from openfoodfoundation/dependabot/npm_and_yarn/hotwired/turbo-8.0.10
Bump @hotwired/turbo from 8.0.6 to 8.0.10
2024-09-19 09:19:24 +10:00
dependabot[bot]
24a25d31a0 Bump @hotwired/turbo from 8.0.6 to 8.0.10
Bumps [@hotwired/turbo](https://github.com/hotwired/turbo) from 8.0.6 to 8.0.10.
- [Release notes](https://github.com/hotwired/turbo/releases)
- [Commits](https://github.com/hotwired/turbo/compare/8.0.6...v8.0.10)

---
updated-dependencies:
- dependency-name: "@hotwired/turbo"
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-09-18 09:50:44 +00:00
David Cook
4822a9ebcd Merge pull request #12868 from rioug/fix-buu-permission
[BUU] Add missing permission check on product actions
2024-09-18 17:25:24 +10:00
Gaetan Craig-Riou
68fa903d61 Add missing permission check on buu action
Plus request spec
2024-09-18 10:24:09 +10:00
wandji20
c2e0c94f2e Remove unused debounced plugin 2024-09-17 11:56:07 +01:00
David Cook
296997d558 Test to ensure report abilities 2024-09-17 13:23:14 +10:00
David Cook
a9ad6a2851 Grant product managers ability to create reports
We missed this in c31416c, oops.
2024-09-17 13:08:49 +10:00
David Cook
1078e7cd36 Update specs
The key here is the enterprise_relationship. This is required for the supplier to have permission to see the orders.

Curiously, the unit test still passes. All will be revealed in the next commit..
2024-09-17 12:55:22 +10:00
Gaetan Craig-Riou
40c4d38e45 Add permission check 2024-09-17 12:01:53 +10:00
Gaetan Craig-Riou
a25937321a Remove ability of any admin user to see all product
And fix related spec
2024-09-17 11:46:55 +10:00
wandji20
a8db288425 Improve debounced initialised events 2024-09-17 01:56:44 +01:00
dependabot[bot]
a106eb10b6 Bump debounced from 0.0.5 to 1.0.2
Bumps [debounced](https://github.com/hopsoft/debounced) from 0.0.5 to 1.0.2.
- [Release notes](https://github.com/hopsoft/debounced/releases)
- [Commits](https://github.com/hopsoft/debounced/commits/v1.0.2)

---
updated-dependencies:
- dependency-name: debounced
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-09-17 01:36:37 +01:00
David Cook
a6d71f8dd1 Merge pull request #12861 from openfoodfoundation/dependabot/npm_and_yarn/express-4.21.0
Bump express from 4.19.2 to 4.21.0
2024-09-17 09:26:41 +10:00
David Cook
5c300d6d41 Merge pull request #12864 from openfoodfoundation/dependabot/npm_and_yarn/floating-ui/dom-1.6.11
Bump @floating-ui/dom from 1.6.10 to 1.6.11
2024-09-17 09:26:24 +10:00
dependabot[bot]
bb4ff5adc2 Bump @floating-ui/dom from 1.6.10 to 1.6.11
Bumps [@floating-ui/dom](https://github.com/floating-ui/floating-ui/tree/HEAD/packages/dom) from 1.6.10 to 1.6.11.
- [Release notes](https://github.com/floating-ui/floating-ui/releases)
- [Changelog](https://github.com/floating-ui/floating-ui/blob/master/packages/dom/CHANGELOG.md)
- [Commits](https://github.com/floating-ui/floating-ui/commits/@floating-ui/dom@1.6.11/packages/dom)

---
updated-dependencies:
- dependency-name: "@floating-ui/dom"
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-09-16 09:29:53 +00:00
dependabot[bot]
be548c506d Bump express from 4.19.2 to 4.21.0
Bumps [express](https://github.com/expressjs/express) from 4.19.2 to 4.21.0.
- [Release notes](https://github.com/expressjs/express/releases)
- [Changelog](https://github.com/expressjs/express/blob/4.21.0/History.md)
- [Commits](https://github.com/expressjs/express/compare/4.19.2...4.21.0)

---
updated-dependencies:
- dependency-name: express
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-09-15 23:49:21 +00:00
Gaetan Craig-Riou
955f8ba5ae Merge pull request #12858 from openfoodfoundation/dependabot/npm_and_yarn/hotwired/turbo-8.0.6
Bump @hotwired/turbo from 8.0.5 to 8.0.6
2024-09-16 09:48:22 +10:00
Konrad
ad94da975a Add hint about the required Transifex Client 2024-09-14 21:30:54 +02:00
drummer83
f33eb23909 Update all locales with the latest Transifex translations 2024-09-14 20:50:45 +02:00
Ahmed Ejaz
9d5806b858 12626: remove invalid_fields_error locale 2024-09-14 18:10:58 +05:00
Ahmed Ejaz
35f9c420fd 12852: remove unnecessary !important 2024-09-14 18:04:52 +05:00
Ahmed Ejaz
052e3b6380 12852: add remove choice icon for select2 2024-09-14 17:42:10 +05:00
Ahmed Ejaz
1545708d4e 12852: remove fix height for the select2-choices 2024-09-14 17:18:09 +05:00
Ahmed Ejaz
2a4d275f4b 12626: use rails default error messages 2024-09-14 02:44:43 +05:00
dependabot[bot]
9ead14b8a0 Bump @hotwired/turbo from 8.0.5 to 8.0.6
Bumps [@hotwired/turbo](https://github.com/hotwired/turbo) from 8.0.5 to 8.0.6.
- [Release notes](https://github.com/hotwired/turbo/releases)
- [Commits](https://github.com/hotwired/turbo/compare/v8.0.5...8.0.6)

---
updated-dependencies:
- dependency-name: "@hotwired/turbo"
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-09-13 09:26:22 +00:00
Gaetan Craig-Riou
38721d9f36 Per review, fix the tab spec
Both tabs have the product name, so add check got the image on the
product details tab.
2024-09-13 14:33:46 +10:00
Gaetan Craig-Riou
3f6aaa74cc Remove duplicated styling for tabs
It uses the same styling as #admin now share via mixins
2024-09-13 14:14:30 +10:00
Ahmed Ejaz
c08683412c 12626: add a fallback message 2024-09-13 01:43:37 +05:00
Ahmed Ejaz
4a38d7ef57 12626: add explaination for clone failure 2024-09-12 03:47:53 +05:00
Ahmed Ejaz
243a4a55b4 11200: add spec for display producer column 2024-09-11 12:03:49 +05:00
Ahmed Ejaz
5be53a40a9 11200: rename products scope 2024-09-11 11:54:38 +05:00
Ahmed Ejaz
76fdf3725a 11200: add explanations 2024-09-11 11:41:01 +05:00
Gaetan Craig-Riou
67f037280a Add comment in shop view file
It wasn't possible to directly reuse the shopfront views because they
are still using angular.
2024-09-11 14:50:37 +10:00
Gaetan Craig-Riou
776b9fcdab Re enable images partial import 2024-09-11 14:24:24 +10:00
Gaetan Craig-Riou
7e84d41e8c Simplify modal opening by just rendering the modal in turbo stream 2024-09-11 14:20:41 +10:00
Gaetan Craig-Riou
68491559f3 Merge pull request #12790 from filipefurtad0/revisit_Orders_and_Distributors_report
Improves test coverage on Orders and Distributors report
2024-09-11 10:28:55 +10:00
Ahmed Ejaz
f8d3467d46 11200: add specs 2024-09-11 01:59:43 +05:00
Ahmed Ejaz
1580d539df 11200: coniditonally hide producer column 2024-09-11 00:56:52 +05:00
Maikel
e2aac8ca1d Merge pull request #12851 from openfoodfoundation/dependabot/npm_and_yarn/jasmine-core-5.3.0
Bump jasmine-core from 5.2.0 to 5.3.0
2024-09-10 13:50:11 +10:00
Maikel
15a2513815 Merge pull request #12849 from openfoodfoundation/dependabot/npm_and_yarn/turbo_power-0.7.0
Bump turbo_power from 0.6.2 to 0.7.0
2024-09-10 13:49:26 +10:00
Gaetan Craig-Riou
00768f6ba0 Add sytem spec for product preview on product edit page 2024-09-10 13:29:40 +10:00
Gaetan Craig-Riou
908caa984b Add system spec for product preview 2024-09-10 13:29:40 +10:00
Gaetan Craig-Riou
6993750757 Fix product v3 action system spec 2024-09-10 13:29:40 +10:00
Gaetan Craig-Riou
379e5acfe5 Fix product preview modal opening
The previous solution failed to take into account that it would have been
trigger on any turbo steam rendering action, not just the product preview
one. Now the open event is dispatched when the product preview
controller is connected, which happens when the modal html is rendered.
2024-09-10 13:29:40 +10:00
Gaetan Craig-Riou
5bf6bdf7f0 Fix some display issue with long description 2024-09-10 13:29:40 +10:00
Gaetan Craig-Riou
8de7c304fe Add AdminTooltipComponent
I left the stimulus controller separated as it is generic enough
2024-09-10 13:29:40 +10:00
Gaetan Craig-Riou
b6695ba9a2 Add product preview on product edit page
Plus translation
2024-09-10 13:29:40 +10:00
Gaetan Craig-Riou
e8de76dc46 Add style for Shop
As before, move imported css to partials to avoid duplication. And use
mixin and variable to handle tooltip styling
2024-09-10 13:29:40 +10:00
Gaetan Craig-Riou
55733555bf Add style for Product details
Only import relevant css, which has been move to their own partial to
avoid duplication
2024-09-10 13:29:40 +10:00
Gaetan Craig-Riou
f59ee96011 Copy foundation-sites css relevant to the modal
The frontend is based on fondation-sites to provide responsive design,
we can't just import in the backend. So opted for copying the part we
needed
2024-09-10 13:29:40 +10:00
Gaetan Craig-Riou
2b74bbd45d Add styling for tabs 2024-09-10 13:29:40 +10:00
Gaetan Craig-Riou
d56ab9257b Add tab switch and shop tab 2024-09-10 13:29:40 +10:00
Gaetan Craig-Riou
f24a4edc68 Add product detail to the modal 2024-09-10 13:29:39 +10:00
Gaetan Craig-Riou
27dd5def57 Open modal before rendering the received html
This way we don't see a blank modal waiting for the content to load
2024-09-10 13:29:39 +10:00
Gaetan Craig-Riou
561f4648d2 Improve tooltip partial
Set up default value optiona locals variable
2024-09-10 13:29:39 +10:00
Gaetan Craig-Riou
64d3091db9 Add product preview modal
Plus open modal when clicking on "preview" link.
It's using event to communicate between stimulus controller :
https://stimulus.hotwired.dev/reference/controllers#cross-controller-coordination-with-events
2024-09-10 13:29:39 +10:00
Gaetan Craig-Riou
0a9b858f2a Add the ability to pass options ModalComponent
Now you can add another stimulus controller or action to the modal
2024-09-10 13:29:39 +10:00
Gaetan Craig-Riou
4756ab47c2 Wire preview link via turbo-stream 2024-09-10 13:29:39 +10:00
Gaetan Craig-Riou
0a04342712 Remove event listener on disconnect
It prevents memory leak
2024-09-10 13:29:39 +10:00
filipefurtad0
556539d1b1 Removes pending from fixed issue
The pending was not signalling the bug fix as ordering needed to be corrected
2024-09-09 18:07:57 -06:00
filipefurtad0
b7aaab204c Adds timer restriction with Timecop
The datet-time-picker test case was failing for me locally, but passing on GH-Actions. Controlling the time should prevent this type of flakyness
2024-09-09 18:07:57 -06:00
filipefurtad0
632184b0a8 Addresses Davids review 2024-09-09 18:07:57 -06:00
filipefurtad0
8500f6c198 Addresses reviews. The biggest change is moving the table CSS
into its helper, which touches other system specs (namely orders_and_fulfillment_spec.rb).

Rubocop fixup
2024-09-09 18:07:57 -06:00
filipefurtad0
ec4dba71c2 Adds flatpickr test 2024-09-09 18:07:57 -06:00
filipefurtad0
6117d70fae Replaces code with shared examples
This spec was appearently flaky, let's see if this change stabilizes it. It came up here: https://github.com/openfoodfoundation/openfoodnetwork/actions/runs/10639846576/job/29498582671?pr=12790

Removes CSV tests based on permissions

Not sure we need these tests, proposing to remove them and use shared examples to test file download
2024-09-09 18:07:57 -06:00
filipefurtad0
2e5c526170 Adds basic coverage on report file download
Moves file download into report helper

Removes pdf file assertation

Removes test on PDF file on sales tax report

Removes PDF testing from helper
2024-09-09 18:07:57 -06:00
filipefurtad0
32e32117e3 Adds test case around hub filters 2024-09-09 18:07:57 -06:00
filipefurtad0
2a1d494301 Adds coverage for table contents 2024-09-09 18:07:57 -06:00
filipefurtad0
fd45dea9f7 Moves report test case into dedicated file
Sets up an enterprise user instead of an admin user
2024-09-09 18:07:57 -06:00
filipefurtad0
9073f0e5a8 Update all locales with the latest Transifex translations 2024-09-09 10:13:11 -06:00
dependabot[bot]
c4f2c1c3ca Bump jasmine-core from 5.2.0 to 5.3.0
Bumps [jasmine-core](https://github.com/jasmine/jasmine) from 5.2.0 to 5.3.0.
- [Release notes](https://github.com/jasmine/jasmine/releases)
- [Changelog](https://github.com/jasmine/jasmine/blob/main/RELEASE.md)
- [Commits](https://github.com/jasmine/jasmine/compare/v5.2.0...v5.3.0)

---
updated-dependencies:
- dependency-name: jasmine-core
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-09-09 09:12:18 +00:00
dependabot[bot]
a23bbf8537 Bump turbo_power from 0.6.2 to 0.7.0
Bumps [turbo_power](https://github.com/marcoroth/turbo_power) from 0.6.2 to 0.7.0.
- [Release notes](https://github.com/marcoroth/turbo_power/releases)
- [Commits](https://github.com/marcoroth/turbo_power/compare/v0.6.2...v0.7.0)

---
updated-dependencies:
- dependency-name: turbo_power
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-09-09 09:11:49 +00:00
Konrad
6fac32b446 Merge pull request #12799 from chahmedejaz/bugfix/12777-incorrect-invoice-unit-display
Fix Display Unit As field is not Displaying on Invoice and Report
2024-09-06 12:55:03 +02:00
Konrad
cf21c03619 Merge pull request #12827 from johansenja/only-fetch-active-open-shops
Optimise shops page: Only inject distributors with active order cycles
2024-09-05 13:04:17 +02:00
David Cook
0f7f1130f1 Update spec/system/admin/invoice_print_spec.rb 2024-09-05 10:49:45 +02:00
Ahmed Ejaz
009d033e4c 12777: add specs 2024-09-05 10:49:45 +02:00
Ahmed Ejaz
983addff0d 12777: use unit_to_display method for variant unit
- This method prioritize display_as and after that considers options_text
2024-09-05 10:49:45 +02:00
Maikel Linke
d061fe8ad9 Remove unnecessary sanitising
Existing descriptions have been sanitised in a migration. New
descriptions are sanitised when assigned. That should cover everything.
2024-09-05 12:38:33 +10:00
Maikel Linke
53286c22ba Sanitise existing long descriptions of enterprises 2024-09-05 12:07:05 +10:00
Maikel
0cf8f079e4 Merge pull request #12840 from openfoodfoundation/dependabot/github_actions/dot-github/workflows/actions/download-artifact-4.1.7
Bump actions/download-artifact from 3 to 4.1.7 in /.github/workflows
2024-09-05 10:26:20 +10:00
Maikel
f2163a42c4 Merge pull request #12841 from filipefurtad0/reproduce_#12835
Reproduces bug #12835
2024-09-05 10:04:34 +10:00
Maikel Linke
05b25c78bb Bump all artifact actions to v4 2024-09-05 09:57:05 +10:00
filipefurtad0
cc3181c820 Adds unit spec regression test 2024-09-04 16:51:33 -06:00
Joseph Johansen
9cd39d5c91 Improve specificity of closed_shops API test data 2024-09-04 11:46:44 +01:00
Joseph Johansen
7d2f3bfa2f Ensure excluded shops are captured by #closed_shops 2024-09-04 11:46:44 +01:00
Joseph Johansen
6df0b24bcf Add implementation 2024-09-04 11:46:44 +01:00
Joseph Johansen
cf5e182cf7 Add specs for ShopsListService 2024-09-04 11:46:44 +01:00
dependabot[bot]
74bbc7c3c0 Bump actions/download-artifact from 3 to 4.1.7 in /.github/workflows
Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 3 to 4.1.7.
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](https://github.com/actions/download-artifact/compare/v3...v4.1.7)

---
updated-dependencies:
- dependency-name: actions/download-artifact
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-09-04 07:13:07 +00:00
filipefurtad0
4773d1c82e Reproduces bug #12835 2024-09-03 20:15:29 -06:00
Maikel
fde18ebf24 Merge pull request #12839 from johansenja/include-hidden-files-code-cov-chunk-upload
Enable include-hidden-files for uploading code coverage chunks
2024-09-04 10:19:47 +10:00
Joseph Johansen
fd2cbb67db Enable include-hidden-files for upload code coverage chunks 2024-09-03 18:50:34 +01:00
Maikel
3f1d99d77c Merge pull request #12831 from mkllnk/anonymous-orders
Share anonymised sales data on DFC API with authorised users
2024-09-03 10:59:30 +10:00
David Cook
9cfcab4f02 Merge pull request #12834 from rioug/12832-Fix-karma-test
Fix karma test
2024-09-02 14:08:23 +10:00
Gaetan Craig-Riou
703ad26773 Fix spec to make the test usefull 2024-09-02 12:23:27 +10:00
Gaetan Craig-Riou
627c9eede2 Fix spec using confirm pop up
For some reason, karma hang and fails with a timeout error if javascrpit
`confirm` pop up isn't mocked.

Plus fix spec to actually check the pop up has been displayed
2024-09-02 12:18:44 +10:00
David Cook
f9a76342f8 Merge pull request #12830 from filipefurtad0/remove_pdf_file_test_from_reports
Removes test on PDF file on sales tax report
2024-09-02 11:15:13 +10:00
Maikel Linke
d52134dad8 Filter sales data by dates 2024-08-30 15:00:06 +10:00
Maikel Linke
1016656781 Publish data only of participating distributors 2024-08-30 14:34:39 +10:00
Maikel Linke
bd1611630f Build DFC data for sales 2024-08-30 14:34:32 +10:00
Maikel Linke
ce28c10c7e Move sales data generation to a service object
There will be lots and lots. The sales data root object is also the
authenticated person. The data has its own URL (semantic id) which
doens't need to contain the user id.

The service object can also be tested more easily. I'm setting up the
test data here.
2024-08-30 14:30:46 +10:00
Maikel Linke
4342d3b912 Add DFC API endpoint for sales data 2024-08-30 14:30:46 +10:00
Maikel Linke
af3aed827a Update all locales with the latest Transifex translations 2024-08-30 09:59:49 +10:00
Maikel
f73be6447e Merge pull request #12824 from chahmedejaz/task/12823-fully-enable-admin-style-v3
[BUU] Fully enable admin_style_v3
2024-08-30 09:56:23 +10:00
Filipe
98eabc9d0f Merge pull request #12826 from chahmedejaz/bugfix/12815-fix-inconsistent-unit-values
Fix Inconsistent Behavior When Editing Products to mg Units in Hungarian Locale
2024-08-29 17:47:44 -06:00
Filipe
169cbbe1a1 Merge pull request #12793 from rioug/12768_fix_bulk_coop_report
Fix bulk coop report
2024-08-29 15:20:48 -06:00
filipefurtad0
72a503c3c1 Removes test on PDF file on sales tax report 2024-08-29 11:46:22 -06:00
Konrad
afc4c1e967 Merge pull request #12760 from wandji20/wb-OFN-12744
UX improvements for creation of new products [OFN-12744]
2024-08-29 17:22:36 +02:00
Rachel Arnould
d76c4bddb0 Merge pull request #12806 from drummer83/typo
Fix typos in "category" and unify capitals on "Back To Xyz List" buttons
2024-08-29 16:40:35 +02:00
Konrad
ae993784d8 Merge pull request #12813 from chahmedejaz/task/12810-increase-price-column-width
[BUU] Fix the too Narrow Price field
2024-08-29 15:22:27 +02:00
Filipe
d1abe22c32 Merge pull request #12805 from mkllnk/update-wicked-pdf-config-syntax
Update deprecated WickedPdf config syntax
2024-08-28 21:35:40 -06:00
Filipe
2817b8891e Merge pull request #12814 from dacook/buu/cell-padding
Increase column space in bulk products table
2024-08-28 21:30:03 -06:00
Filipe
ab87610d91 Merge pull request #12807 from kernal053/fix-broken-column-after-cloning
Fix broken column after cloning product
2024-08-28 21:03:53 -06:00
David Cook
54252f5444 Add comment 2024-08-29 09:42:59 +10:00
Ahmed Ejaz
7b6b0dbb78 12815: use en formatting for unit value conversion 2024-08-29 03:36:46 +05:00
Maikel
b2e15f52cf Merge pull request #12822 from johansenja/include-coverage-assets
Fix artifact path for simplecov report upload
2024-08-29 08:10:38 +10:00
Ahmed Ejaz
5d18c48b6c 12823: fully enable admin_style_v3 flag 2024-08-29 02:09:29 +05:00
Konrad
0c2dcbc50d Merge pull request #12812 from chahmedejaz/bugfix/12809-irresponsive-products-column-widths
[BUU] Fix Table width not responsive to the amount of selected columns
2024-08-28 16:45:07 +02:00
Joseph Johansen
4a028b2238 Fix artifact path for simplecov report upload 2024-08-28 11:09:01 +01:00
Maikel
43a366005c Merge pull request #12798 from johansenja/enable-simplecov
Set up code coverage metrics with simplecov
2024-08-28 12:07:53 +10:00
Maikel Linke
64470e977a Avoid name clash in simplecov task
A variable and a method were called the same.
Also made method calls more obvious with parenthesis.
2024-08-28 11:31:01 +10:00
Maikel Linke
a696c66857 Clean up tmp dir after test and avoid collisions
Best viewed ignoring whitespace changes.
2024-08-28 11:27:42 +10:00
Maikel Linke
cfeb0afbd4 Update all locales with the latest Transifex translations 2024-08-28 09:45:24 +10:00
Maikel Linke
4968e3dc8d Update all locales with the latest Transifex translations 2024-08-28 09:12:52 +10:00
David Cook
5324747f89 Reduce cell padding
This is closer to the original design:
* 6px between inputs
* 6px vertical padding on condensed rows
* 12px vertical padding on relaxed rows

Note that 'relaxed' rows are now smaller than the regular rows, which was not the original intention. But we haven't got spare time to do a broader review of table styles right now.
2024-08-26 16:53:19 +10:00
Gaetan Craig-Riou
ef2856d169 Remove added eventListener on disconnect
It's good practise to remove added event listener to avoid memory leak
2024-08-26 11:15:26 +10:00
Ahmed Ejaz
d9c79ee49c 12810: increase price width
- make it to 10% which makes sure that any price value acceptable by the system is displayed fully
- Reduce On Hand to 8% to make up for some space for the above
2024-08-24 17:37:59 +05:00
Ahmed Ejaz
d1f9b0855d 12809: fix the class name for the producer column in product 2024-08-24 02:05:04 +05:00
drummer83
b82726e7ba Unify the capital letters of the "Back To Xyz List" buttons and update specs
I decided to use the most frequently used version as the default, which is every word beginning with a capital letter
2024-08-23 13:23:57 +02:00
drummer83
7e7ab2e36d Fix typo in "categeory" (additional e) and update specs 2024-08-23 13:20:46 +02:00
kernal053
e35a5179bb Fix broken column after cloning product 2024-08-23 16:01:56 +05:30
Joseph Johansen
85385a1989 Rename uploads so combined report is listed first alphabetically 2024-08-23 11:26:45 +01:00
Joseph Johansen
a816814819 Update CI workflow to upload results and call rake task 2024-08-23 11:26:41 +01:00
Cillian O'Ruanaidh
60afa4d465 Revert whitespace changes in config/locales/en.yml 2024-08-23 10:07:32 +01:00
Cillian O'Ruanaidh
dd5175558e Don't make any changes to non :en locales. 2024-08-23 10:03:34 +01:00
wandji20
94b98867d8 Revert use of searchableDropdownComponent for product unit 2024-08-23 09:57:37 +01:00
wandji20
35ef1b9c7f Refactor new product dropdown to use SeachableDropdown component [OFN-12744] 2024-08-23 09:57:37 +01:00
wandji20
8badfb2505 Allow extra attributes to be passed to searchable dropdown component [OFN-12744] 2024-08-23 09:57:37 +01:00
wandji20
d61acd2cc1 Unify error messages and display on new product form [OFN-12744] 2024-08-23 09:57:37 +01:00
wandji20
7417cee20a Fix leaked trix editor event listener [OFN-12744] 2024-08-23 09:57:37 +01:00
Cillian O'Ruanaidh
98951161b1 Revert "Add Trix translations for all the different English locale regions"
This reverts commit 70ca03173c.
2024-08-23 09:54:23 +01:00
Cillian O'Ruanaidh
a745249f3b Revert "Reuse 'Please insert a URL' translation from text angular editor in the Trix editor" for all locales except :en
This reverts commit 2d6ffc0ca1.
2024-08-23 09:52:57 +01:00
Cillian O'Ruanaidh
63c62cae08 Simplify setting of Trix editor translations
Co-authored-by: David Cook <david@redcliffs.net>
2024-08-23 09:47:48 +01:00
Maikel Linke
d489c77efe Update deprecated WickedPdf config syntax
Avoids warning:

> WickedPdf.config= is deprecated and will be removed in future versions. Use WickedPdf.configure instead.
2024-08-23 15:57:59 +10:00
Maikel
e2423ad612 Merge pull request #12800 from filipefurtad0/adds_retry_option_on_edit_spec
Adds retry option to flaky edit_spec.rb
2024-08-23 12:02:59 +10:00
filipefurtad0
8b036113d9 Update all locales with the latest Transifex translations 2024-08-22 17:33:21 -06:00
Maikel
7f09044ae1 Merge pull request #12755 from johansenja/optimise-shops-page6
Optimise shops page: Enable injected enterprise data to be scoped to specific enterprise ids
2024-08-23 09:26:22 +10:00
Maikel
e9c7e1778c Merge pull request #12782 from mkllnk/reports
Add fallback report loading in case websockets fail
2024-08-23 09:23:42 +10:00
filipefurtad0
32cd14ef54 Adds slep(2) 2024-08-22 15:55:31 -06:00
filipefurtad0
ad585f1eab Adds retry option to flaky test case
...does so on another flaky test case
2024-08-22 15:55:31 -06:00
Filipe
d9368c1bfc Merge pull request #12781 from wandji20/wb-OFN-12775
Add warning popup to order cycle list [OFN-12775]
2024-08-22 15:39:27 -06:00
wandji20
b6bfb4e866 Refactor order cycle same_dates method 2024-08-22 22:21:17 +01:00
wandji20
4d222c61c6 Improve readability of order_cycle_set process method 2024-08-22 22:17:12 +01:00
wandji20
d599cf77a2 Fix failing specs 2024-08-22 22:17:12 +01:00
wandji20
8f7505d53d Refactor oc datetime content partial and include warning modal in oc list [OFN-12775] 2024-08-22 22:17:12 +01:00
wandji20
867e17301f Support passing oc confirmation params for oc list [OFN-12775] 2024-08-22 22:17:12 +01:00
wandji20
95135ca526 Move order_cycle datetime verification logic to service files [OFN-12775] 2024-08-22 22:17:12 +01:00
wandji20
de063fecb1 Move same_datetime_value method to OrderCycle model [OFN-12775] 2024-08-22 22:17:12 +01:00
Filipe
ef9ca33913 Merge pull request #12772 from drummer83/E500_sub
Display admin order page instead of shopfront order page to avoid error 500
2024-08-22 13:26:20 -06:00
Konrad
2710eafc33 Merge pull request #12779 from EdwardLi-coder/clearer_error_message_and_clean_up
Clearer error message and clean up for Product Categories
2024-08-22 18:15:50 +02:00
Joseph Johansen
4718fdb0be Optimise Spree::Taxon.supplied_taxons 2024-08-22 17:41:00 +02:00
Joseph Johansen
ce6ae04147 Add spec for confirming correct values when scoped 2024-08-22 17:41:00 +02:00
johansenja
1621f97fdb Use subject method in spec
Co-authored-by: Gaetan Craig-Riou <40413322+rioug@users.noreply.github.com>
2024-08-22 17:41:00 +02:00
Joseph Johansen
96f9894f41 Add enterprise_ids to cache key 2024-08-22 17:41:00 +02:00
Joseph Johansen
66b519bd1c Undo minor unneeded changes 2024-08-22 17:41:00 +02:00
Joseph Johansen
1b8e256e8a Add unit tests 2024-08-22 17:41:00 +02:00
Joseph Johansen
b73e529bfc Scope injected enterprise properties to specific enterprises 2024-08-22 17:41:00 +02:00
Konrad
25b1620707 Merge pull request #12743 from wandji20/wb-OFN-12214
(Fix) chore(deps): bump wicked_pdf from 2.6.3 to 2.8.0 [OFN-12214]
2024-08-22 17:34:20 +02:00
Joseph Johansen
5f9b14df9f Implement rake task to combine results 2024-08-21 13:02:31 +01:00
Joseph Johansen
922b853e3a Define specs for rake task to combine results 2024-08-21 13:02:31 +01:00
Joseph Johansen
8d747a2508 Enable coverage in base_spec_helper 2024-08-21 13:02:31 +01:00
Gaetan Craig-Riou
a50be52cde Merge pull request #12792 from openfoodfoundation/dependabot/npm_and_yarn/elliptic-6.5.7
Bump elliptic from 6.5.4 to 6.5.7
2024-08-21 09:56:19 +10:00
Gaetan Craig-Riou
d62d002bc5 Merge pull request #12780 from dacook/optimise-12714
Optimise subscriptions admin
2024-08-21 09:50:27 +10:00
Maikel
0c7448ba43 Merge pull request #12726 from mkllnk/order-stock-spec
Track (negative) stock for on-demand products and overrides
2024-08-20 15:05:16 +10:00
Gaetan Craig-Riou
24afd40414 Fix bulk coop supplier report 2024-08-20 14:32:35 +10:00
Maikel
524aec7868 Merge pull request #12788 from openfoodfoundation/dependabot/npm_and_yarn/mrujs-1.0.2
Bump mrujs from 1.0.1 to 1.0.2
2024-08-20 14:30:47 +10:00
David Cook
f2eb4b05f4 Avoid copying gigantic array 2024-08-20 14:00:13 +10:00
David Cook
ffaf1b4ea0 Cache distributor 2024-08-20 14:00:13 +10:00
David Cook
eb547f4861 Add test on number of db queries
Hmm, I think I seen an opportunity to clean up already.
2024-08-20 14:00:13 +10:00
David Cook
c9daca22d5 Rename spec to match class name 2024-08-20 14:00:13 +10:00
dependabot[bot]
7b22740289 Bump elliptic from 6.5.4 to 6.5.7
Bumps [elliptic](https://github.com/indutny/elliptic) from 6.5.4 to 6.5.7.
- [Commits](https://github.com/indutny/elliptic/compare/v6.5.4...v6.5.7)

---
updated-dependencies:
- dependency-name: elliptic
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-08-20 03:52:13 +00:00
Maikel
66c8a5c424 Merge pull request #12789 from chahmedejaz/bugfix/12783-fix-artifact-upload-names-conflict
Fix Artifact Upload Conflicts with Unique Node-Based Names
2024-08-20 13:51:13 +10:00
David Cook
cfeac651b6 Merge pull request #12785 from filipefurtad0/spec_for_#12768
Reproduces S2 bug #12768
2024-08-20 13:45:07 +10:00
EdwardLi-coder
05315ff8e0 delete spree.new_taxon 2024-08-20 08:11:49 +08:00
EdwardLi-coder
c4ee6b14ff clear error message and clean up 2024-08-20 08:11:49 +08:00
filipefurtad0
a78f46259c Asserts on the flash warning first
The warning first displays "Saving..." before confirming changes are saved.
I'm not entirelly sure, but it seems that asserting on this first, before asserting on other page elements stabilizes the spec.
2024-08-19 13:58:03 -06:00
filipefurtad0
1e79fde236 Reproduces S2 bug #12768 2024-08-19 13:58:03 -06:00
Ahmed Ejaz
a9fe52a4ff Revert "12783 - validate artifact upload"
This reverts commit 075f5499f8.
2024-08-19 23:29:12 +05:00
Ahmed Ejaz
075f5499f8 12783 - validate artifact upload 2024-08-19 23:16:39 +05:00
Ahmed Ejaz
ed61f7e7bc 12783: use unique artifact name based on node index 2024-08-19 22:57:04 +05:00
dependabot[bot]
bd6019036e Bump mrujs from 1.0.1 to 1.0.2
Bumps [mrujs](https://github.com/KonnorRogers/mrujs) from 1.0.1 to 1.0.2.
- [Changelog](https://github.com/KonnorRogers/mrujs/blob/main/CHANGELOG.md)
- [Commits](https://github.com/KonnorRogers/mrujs/compare/v1.0.1...v1.0.2)

---
updated-dependencies:
- dependency-name: mrujs
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-08-19 09:31:52 +00:00
Konrad
0bbc3d2758 Merge pull request #12766 from mkllnk/magick-dep
Remove direct dependency on MiniMagick
2024-08-18 18:39:48 +02:00
Konrad
ae6182579b Merge pull request #12762 from EdwardLi-coder/change_colour_of_complete_order
change colour of "complete order"
2024-08-18 15:08:46 +02:00
Konrad
1e05811917 Merge pull request #12745 from johansenja/optimise-shops-page5
Improve effiency of OrderCycle.earliest_closing_times
2024-08-18 14:40:49 +02:00
Konrad
5f86a26f42 Merge pull request #12733 from wandji20/wb-OFN-6567
Update product variant unit display name, price, and total price width on different screen sizes [OFN-6567]
2024-08-18 13:25:24 +02:00
Konrad
3f1b907ef2 Merge pull request #12740 from wandji20/wb-OFN-12532-v1
Pluralize admin products search result [OFN-12532-v1]
2024-08-18 12:18:18 +02:00
Cillian O'Ruanaidh
08ab405893 Rename method for looking up trix attribute or action by translation key 2024-08-16 17:02:03 +01:00
Cillian O'Ruanaidh
ae2e92f09d Don't need to set value on hidden fields for Trix editors, it will be set automatically 2024-08-16 16:20:53 +01:00
Cillian O'Ruanaidh
b174080e29 Fix Layout/LineLength Rubocop violation in spec/system/admin/enterprises_spec.rb 2024-08-16 16:08:41 +01:00
Cillian O'Ruanaidh
a2c3ac2f60 Fix expected placeholder in test after updating translation 2024-08-16 16:00:08 +01:00
Cillian O'Ruanaidh
429e2b0a86 Fix issue where Trix editor translations were not being set correctly in Chrome 2024-08-16 15:44:09 +01:00
Cillian O'Ruanaidh
70ca03173c Add Trix translations for all the different English locale regions 2024-08-16 15:43:09 +01:00
Cillian O'Ruanaidh
7961ff7976 Don't add translations for Trix buttons and functions we are not using 2024-08-16 15:33:49 +01:00
Cillian O'Ruanaidh
2d6ffc0ca1 Reuse 'Please insert a URL' translation from text angular editor in the Trix editor 2024-08-16 15:31:59 +01:00
Maikel Linke
d9c296cdb3 Stabilise flaky report specs
It looks like we have a new race condition that may only be a problem in
specs. If you trigger one report, it displays via websockets and then
you trigger the next report, there may still be some Javascript active
that displays the first report while the second one is loading. I'm not
sure if users would navigate that fast though.

To minimise the problem, I adjusted the polling to leave more room for
the default websockets response.
2024-08-16 17:08:57 +10:00
Maikel Linke
23aa762be2 Add fallback report loading in case websockets fail
This also resolves a race condition scenario. Even if the report gets
rendered via websockets before the controller response is rendered then
the fallback script loads the report again. It's not the most beautiful
but probably okay until we replace websockts altogether.

I'm leaving websockets in at the moment because it can render the report
much quicker than polling can.
2024-08-16 15:24:34 +10:00
Maikel Linke
61f2954973 Add TurboPower Rails gem for nice helpers
The helpers are more convenient but also allow us to add options like
smooth scrolling. I thought that looked nicer and is less confusing.

Please note that the `scroll_into_view` helper uses the `targets`
attribute instead of `target`. That attribute needs CSS selectors with a
leading `#` for ids.
2024-08-16 14:37:57 +10:00
Maikel Linke
d354317c73 Replace cable_ready report loading w/ Turbo stream
I'm adding TurboPower for the scroll_into_view action. It adds all the
nice CableReady actions to Turbo Streams.

Note that I omitted `block: "start"` because that option is the default
in Javascript. And the generic `action` method doesn't support
parameters like this anyway. I'll work on that in the next commit.

I also re-introduced a race condition by rendering the "loading"
indicator after triggering the report rendering job. I'm planning to
resolve that later.
2024-08-16 14:37:57 +10:00
Maikel Linke
19ef047193 Create observable reports blob early
This will allow us to check for completion of the report later in case
websockets fail.
2024-08-16 14:37:57 +10:00
Maikel Linke
037eb456c0 Remove unused controller ivar 2024-08-16 14:37:57 +10:00
Maikel Linke
aed78f3138 Simplify reports controller code branching 2024-08-16 14:37:57 +10:00
Maikel Linke
c31416c536 Separate showing and rendering report 2024-08-16 14:37:57 +10:00
drummer83
f154de66f9 Display admin order page instead of shopfront order page to avoid error 500 2024-08-14 14:44:59 +02:00
wandji20
4a30493716 Improve code style [OFN-12214] 2024-08-13 18:29:27 +01:00
wandji20
f325857e1f Strip end of long invoice table header names due to names not properly parsed when converting pdf to text [OFN-12214] 2024-08-13 18:23:27 +01:00
wandji20
58872a7017 Include mail stylsheet tag in invoice pdf files and mailer layout [OFN-12214] 2024-08-13 18:23:18 +01:00
wandji20
7392079d4d Move mail related styles to asset pipeline [OFN-12214] 2024-08-13 17:11:29 +01:00
wandji20
506126c1d3 Bump wicked_pdf to version 2.8.1 2024-08-13 17:11:29 +01:00
wandji20
fa004d0897 Remove wicked pdf stylsheet include tag in order report pdf [OFN-12214] 2024-08-13 17:11:29 +01:00
dependabot[bot]
db7add88fe chore(deps): bump wicked_pdf from 2.6.3 to 2.8.0
Bumps [wicked_pdf](https://github.com/mileszs/wicked_pdf) from 2.6.3 to 2.8.0.
- [Release notes](https://github.com/mileszs/wicked_pdf/releases)
- [Changelog](https://github.com/mileszs/wicked_pdf/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mileszs/wicked_pdf/commits)

---
updated-dependencies:
- dependency-name: wicked_pdf
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-08-13 17:11:29 +01:00
Maikel Linke
f21aca234c Remove direct dependency on MiniMagick
We still depend on it as long as we set it as image processor but now we
can switch to another image processor without changing the code around
error handling.

We now rescue from unknown errors during image processing which should
make the app more robust.
2024-08-13 15:25:58 +10:00
EdwardLi-coder
93a6ff4b50 remove background-color 2024-08-13 09:38:20 +08:00
EdwardLi-coder
97a72dfde7 change colour of "complete order" 2024-08-12 12:01:02 +08:00
Cillian O'Ruanaidh
a6d3909e95 Replace text-angular editor with trix editor in fields for shop messages and about fields for enterprises and enterprise groups 2024-08-09 10:37:23 +01:00
Joseph Johansen
5ca7f40a4e Add unit test 2024-08-06 16:12:13 +01:00
Joseph Johansen
a2f4df191a Improve effiency of OrderCycle.earliest_closing_times 2024-08-06 16:12:13 +01:00
wandji20
b49da46842 Pluralize admin products search result [OFN-12532-v1] 2024-08-06 08:52:51 +01:00
wandji20
2d24593403 Update product variant unit display name, price, and total price widths on different screen sizes [OFN-6567] 2024-08-02 13:03:42 +01:00
Maikel Linke
2201d2e8c2 VariantOverride with on_demand now overriding stock
Otherwise we would try to take stock from the producer stock level
without respecting their on-demand settings. So from now on:
If stock level or on_demand are set on the override then it's not using
producer stock levels.
2024-08-02 14:40:17 +10:00
Maikel Linke
b6c407971d Allow on-demand VariantOverride to track stock
We allowed this for producer stock and need to do the same for inventory
stock. This will allow us to create backorders for missing, but promised
stock.
2024-08-02 14:40:17 +10:00
Maikel Linke
cd8dc41b15 Update stock specs and add pending cases 2024-08-02 14:40:17 +10:00
Maikel Linke
a1887bdc76 Update stock levels of on-demand items
We weren't bothering with stock when items were on demand anyway. But we
want to track stock now so that we can backorder more when local stock
levels become negative.
2024-08-02 14:40:17 +10:00
Maikel Linke
e9f89362f4 Remove validation of positive stock when on demand
We weren't allowing negative stock to stop any bug from accidentally
drawing too much stock. But now we want to implement a backordering
logic that depends on negative stock levels to know how much is needed
to replenish stock levels.
2024-08-02 14:40:17 +10:00
Maikel Linke
675b7febdf Test stock logic on variant level
VariantOverrides are bolted onto variants to change their logic.
2024-08-02 14:40:17 +10:00
Maikel Linke
90fdf59415 Test current stock logic on shipment level
During checkout, stock is adjusted when a shipment is finalised. The
chain is:

* Order state change to complete.
* Trigger Order#finalize! which updates shipments.
* Trigger Shipment#finalize! which adjusts stock on the variant.
* A variant holds stock in stock items or in a variant override.
2024-08-02 14:40:17 +10:00
344 changed files with 9781 additions and 4953 deletions

View File

@@ -11,6 +11,7 @@ assignees: ''
- [ ] Merge pull requests in the [Ready To Go] column
- [ ] Include translations: `script/release/update_locales`
- You need the [Transifex Client] installed on your local dev environement to run the script.
- [ ] Increment version number: `git push upstream HEAD:refs/tags/vX.Y.Z`
- Major: if server changes are required (eg. provision with ofn-install)
- Minor: larger change that is irreversible (eg. migration deleting data)
@@ -53,3 +54,4 @@ The full process is described at https://github.com/openfoodfoundation/openfoodn
[#global-community]: https://app.slack.com/client/T02G54U79/C59ADD8F2
[Create issue]: https://github.com/openfoodfoundation/openfoodnetwork/issues/new?assignees=&labels=&projects=&template=release.md&title=Release
[#core-devs]: https://openfoodnetwork.slack.com/archives/GK2T38QPJ
[Transifex Client]: https://developers.transifex.com/docs/cli

View File

@@ -3,7 +3,7 @@ name: Build
on:
workflow_dispatch:
push:
branches-ignore:
branches-ignore:
- 'dependabot/**'
pull_request:
@@ -47,7 +47,7 @@ jobs:
- name: Setup redis
uses: supercharge/redis-github-action@1.4.0
with:
with:
redis-version: 6
- name: Set up Ruby
@@ -81,11 +81,20 @@ jobs:
# RSpec split test files by test examples feature - it's optional
# https://knapsackpro.com/faq/question/how-to-split-slow-rspec-test-files-by-test-examples-by-individual-it
#KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES: true
KNAPSACK_PRO_TEST_FILE_PATTERN: "{spec/controllers/**/*_spec.rb}"
KNAPSACK_PRO_TEST_FILE_PATTERN: "{spec/controllers/**/*_spec.rb}"
run: |
git show --no-patch # the commit being tested (which is often a merge due to actions/checkout@v3)
bin/rake knapsack_pro:rspec
- name: Save SimpleCov file
uses: actions/upload-artifact@v4
with:
name: simplecov-chunk-controllers-${{ matrix.ci_node_index }}
path: coverage/*.*
retention-days: 2 # doesn't need to be long, because it's the combined results that matter
if-no-files-found: ignore
include-hidden-files: true
models:
runs-on: ubuntu-22.04
services:
@@ -116,7 +125,7 @@ jobs:
- name: Setup redis
uses: supercharge/redis-github-action@1.4.0
with:
with:
redis-version: 6
- name: Set up Ruby
@@ -141,10 +150,19 @@ jobs:
# RSpec split test files by test examples feature - it's optional
# https://knapsackpro.com/faq/question/how-to-split-slow-rspec-test-files-by-test-examples-by-individual-it
#KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES: true
KNAPSACK_PRO_TEST_FILE_PATTERN: "{spec/models/**/*_spec.rb}"
KNAPSACK_PRO_TEST_FILE_PATTERN: "{spec/models/**/*_spec.rb}"
run: |
bin/rake knapsack_pro:rspec
- name: Save SimpleCov file
uses: actions/upload-artifact@v4
with:
name: simplecov-chunk-models-${{ matrix.ci_node_index }}
path: coverage/*.*
retention-days: 2 # doesn't need to be long, because it's the combined results that matter
if-no-files-found: ignore
include-hidden-files: true
system_admin:
runs-on: ubuntu-22.04
services:
@@ -175,7 +193,7 @@ jobs:
- name: Setup redis
uses: supercharge/redis-github-action@1.4.0
with:
with:
redis-version: 6
- name: Set up Ruby
@@ -209,16 +227,25 @@ jobs:
# RSpec split test files by test examples feature - it's optional
# https://knapsackpro.com/faq/question/how-to-split-slow-rspec-test-files-by-test-examples-by-individual-it
#KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES: true
KNAPSACK_PRO_TEST_FILE_PATTERN: "{spec/system/admin/**/*_spec.rb}"
KNAPSACK_PRO_TEST_FILE_PATTERN: "{spec/system/admin/**/*_spec.rb}"
run: |
bin/rake knapsack_pro:queue:rspec
- name: Save SimpleCov file
uses: actions/upload-artifact@v4
with:
name: simplecov-chunk-system-admin-${{ matrix.ci_node_index }}
path: coverage/*.*
retention-days: 2 # doesn't need to be long, because it's the combined results that matter
if-no-files-found: ignore
include-hidden-files: true
- name: Archive failed tests screenshots
if: failure()
uses: actions/upload-artifact@v4
with:
name: failed-admin-tests-screenshots
name: failed-admin_${{ matrix.ci_node_index }}-tests-screenshots
path: tmp/capybara/screenshots/*.png
retention-days: 7
if-no-files-found: ignore
@@ -247,13 +274,13 @@ jobs:
ci_node_total: [12]
# Indexes for parallel jobs (starting from zero).
# E.g. use [0, 1] for 2 parallel jobs, [0, 1, 2] for 3 parallel jobs, etc.
ci_node_index: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
ci_node_index: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
steps:
- uses: actions/checkout@v3
- name: Setup redis
uses: supercharge/redis-github-action@1.4.0
with:
with:
redis-version: 6
- name: Set up Ruby
@@ -287,16 +314,25 @@ jobs:
# RSpec split test files by test examples feature - it's optional
# https://knapsackpro.com/faq/question/how-to-split-slow-rspec-test-files-by-test-examples-by-individual-it
#KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES: true
KNAPSACK_PRO_TEST_FILE_PATTERN: "{spec/system/consumer/**/*_spec.rb}"
KNAPSACK_PRO_TEST_FILE_PATTERN: "{spec/system/consumer/**/*_spec.rb}"
run: |
bin/rake knapsack_pro:queue:rspec
- name: Save SimpleCov file
uses: actions/upload-artifact@v4
with:
name: simplecov-chunk-system-consumer-${{ matrix.ci_node_index }}
path: coverage/*.*
retention-days: 2 # doesn't need to be long, because it's the combined results that matter
if-no-files-found: ignore
include-hidden-files: true
- name: Archive failed tests screenshots
if: failure()
uses: actions/upload-artifact@v4
with:
name: failed-consumer-tests-screenshots
name: failed-consumer_${{ matrix.ci_node_index }}-tests-screenshots
path: tmp/capybara/screenshots/*.png
retention-days: 7
if-no-files-found: ignore
@@ -331,7 +367,7 @@ jobs:
- name: Setup redis
uses: supercharge/redis-github-action@1.4.0
with:
with:
redis-version: 6
- name: Set up Ruby
@@ -371,6 +407,15 @@ jobs:
run: |
bin/rake knapsack_pro:rspec
- name: Save SimpleCov file
uses: actions/upload-artifact@v4
with:
name: simplecov-chunk-engines-${{ matrix.ci_node_index }}
path: coverage/*.*
retention-days: 2 # doesn't need to be long, because it's the combined results that matter
if-no-files-found: ignore
include-hidden-files: true
test_the_rest:
runs-on: ubuntu-22.04
services:
@@ -401,7 +446,7 @@ jobs:
- name: Setup redis
uses: supercharge/redis-github-action@1.4.0
with:
with:
redis-version: 6
- name: Set up Ruby
@@ -439,6 +484,15 @@ jobs:
run: |
bin/rake knapsack_pro:rspec
- name: Save SimpleCov file
uses: actions/upload-artifact@v4
with:
name: simplecov-chunk-the-rest-${{ matrix.ci_node_index }}
path: coverage/*.*
retention-days: 2 # doesn't need to be long, because it's the combined results that matter
if-no-files-found: ignore
include-hidden-files: true
non_knapsack_jest_karma:
runs-on: ubuntu-22.04
services:
@@ -476,3 +530,39 @@ jobs:
- name: Run jest tests
run: yarn jest
collate_simplecov_results:
runs-on: ubuntu-22.04
needs:
- controllers
- models
- engines
- system_admin
- system_consumer
- test_the_rest
steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Download individual results from individual runners
uses: actions/download-artifact@v4
with:
pattern: simplecov-chunk-*
path: tmp/simplecov
merge-multiple: true
- name: collate results from each of the workers
run: bundle exec rake 'simplecov:collate_results[tmp/simplecov]'
- name: Upload collated results
uses: actions/upload-artifact@v4
with:
name: combined-simplecov-report
path: coverage/**/*.*
retention-days: 7
if-no-files-found: ignore
include-hidden-files: true

View File

@@ -14,12 +14,12 @@ jobs:
steps:
- uses: actions/checkout@v3
- run: docker/build
- run: docker-compose up --detach
- run: docker compose up --detach
- run: until curl -f -s http://localhost:3000; do echo "waiting for api server"; sleep 1; done
- run: docker-compose exec -T db psql postgresql://ofn:f00d@localhost:5432/open_food_network_dev --command="update spree_users set spree_api_key='testing' where login='ofn@example.com'"
- run: docker compose exec -T db psql postgresql://ofn:f00d@localhost:5432/open_food_network_dev --command="update spree_users set spree_api_key='testing' where login='ofn@example.com'"
# equivalent to Flipper.enable(:api_v1)
- run: docker-compose exec -T db psql postgresql://ofn:f00d@localhost:5432/open_food_network_dev --command="insert into flipper_features (key, created_at, updated_at) values ('api_v1', localtimestamp, localtimestamp)"
- run: docker-compose exec -T db psql postgresql://ofn:f00d@localhost:5432/open_food_network_dev --command="insert into flipper_gates (feature_key, key, value, created_at, updated_at) values ('api_v1', 'boolean', 'true', localtimestamp, localtimestamp)"
- run: docker compose exec -T db psql postgresql://ofn:f00d@localhost:5432/open_food_network_dev --command="insert into flipper_features (key, created_at, updated_at) values ('api_v1', localtimestamp, localtimestamp)"
- run: docker compose exec -T db psql postgresql://ofn:f00d@localhost:5432/open_food_network_dev --command="insert into flipper_gates (feature_key, key, value, created_at, updated_at) values ('api_v1', 'boolean', 'true', localtimestamp, localtimestamp)"
# Run Mayhem for API
- name: Run Mayhem for API

View File

@@ -14,4 +14,6 @@ SimpleCov.start 'rails' do
add_filter '/log'
add_filter '/db'
add_filter '/lib/tasks/sample_data/'
formatter SimpleCov::Formatter::SimpleFormatter
end

View File

@@ -104,6 +104,7 @@ gem 'sidekiq-scheduler'
gem "cable_ready"
gem "stimulus_reflex"
gem "turbo_power"
gem "turbo-rails"
gem 'combine_pdf'

View File

@@ -785,6 +785,8 @@ GEM
actionpack (>= 6.0.0)
activejob (>= 6.0.0)
railties (>= 6.0.0)
turbo_power (0.6.2)
turbo-rails (>= 1.3.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
@@ -835,7 +837,7 @@ GEM
websocket-extensions (0.1.5)
whenever (1.0.0)
chronic (>= 0.6.3)
wicked_pdf (2.6.3)
wicked_pdf (2.8.1)
activesupport
wkhtmltopdf-binary (0.12.6.7)
xml-simple (1.1.8)
@@ -973,6 +975,7 @@ DEPENDENCIES
stripe
timecop
turbo-rails
turbo_power
valid_email2
validates_lengths_from_database
vcr

View File

@@ -14,6 +14,7 @@
//= require angular
//= require angular-resource
//= require angular-animate
//= require angular-sanitize
//= require angularjs-file-upload
//= require ../shared/ng-infinite-scroll.min.js
//= require ../shared/ng-tags-input.min.js
@@ -60,11 +61,6 @@
//= require ./variant_overrides/variant_overrides
// text, dates and translations
//= require textAngular-rangy.min.js
// This replaces angular-sanitize. We should include only one.
// https://github.com/textAngular/textAngular#where-to-get-it
//= require textAngular-sanitize.min.js
//= require textAngular.min.js
//= require i18n/translations
//= require darkswarm/i18n.translate.js

View File

@@ -1 +1 @@
angular.module("admin.enterprise_groups", ["admin.side_menu", "admin.users", "textAngular"])
angular.module("admin.enterprise_groups", ["admin.side_menu", "admin.users", "ngSanitize"])

View File

@@ -3,7 +3,6 @@ angular.module("admin.enterprises", [
"admin.utils",
"admin.shippingMethods",
"admin.users",
"textAngular",
"admin.side_menu",
"admin.taxons",
'admin.indexUtils',
@@ -11,16 +10,3 @@ angular.module("admin.enterprises", [
'admin.dropdown',
'ngSanitize']
)
# For more options: https://github.com/textAngular/textAngular/blob/master/src/textAngularSetup.js
.config [
'$provide', ($provide) ->
$provide.decorator 'taTranslations', [
'$delegate'
(taTranslations) ->
taTranslations.insertLink = {
tooltip: t('admin.enterprises.form.shop_preferences.shopfront_message_link_tooltip'),
dialogPrompt: t('admin.enterprises.form.shop_preferences.shopfront_message_link_prompt')
}
taTranslations
]
]

View File

@@ -1,7 +1,11 @@
angular.module("admin.orderCycles").controller "OrderCyclesCtrl", ($scope, $q, Columns, StatusMessage, RequestMonitor, OrderCycles, Enterprises, Schedules, Dereferencer) ->
$scope.RequestMonitor = RequestMonitor
$scope.columns = Columns.columns
$scope.saveAll = -> OrderCycles.saveChanges($scope.order_cycles_form)
$scope.saveAll = ($event) ->
trigger_action = $($event.target).data('trigger-action')
confirm = $($event.target).data('confirm')
OrderCycles.saveChanges($scope.order_cycles_form, { trigger_action, confirm })
$scope.ordersCloseAtLimit = -31 # days
$scope.resetSelectFilters = ->

View File

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

View File

@@ -29,13 +29,13 @@ angular.module("admin.resources").factory 'OrderCycles', ($q, $injector, OrderCy
deferred.reject(response)
deferred.promise
saveChanges: (form) ->
saveChanges: (form, params = {}) ->
changed = {}
for id, orderCycle of @byID when not @saved(orderCycle)
changed[Object.keys(changed).length] = @changesFor(orderCycle)
if Object.keys(changed).length > 0
StatusMessage.display('progress', "Saving...")
OrderCycleResource.bulkUpdate { order_cycle_set: { collection_attributes: changed } }, (data) =>
OrderCycleResource.bulkUpdate { order_cycle_set: { collection_attributes: changed }, confirm: params['confirm'], trigger_action: params['trigger_action'] }, (data) =>
for orderCycle in data
delete orderCycle.coordinator
delete orderCycle.producers
@@ -47,8 +47,10 @@ angular.module("admin.resources").factory 'OrderCycles', ($q, $injector, OrderCy
, (response) =>
if response.data.errors?
StatusMessage.display('failure', response.data.errors[0])
else if (response.data.trigger_action)
StatusMessage.display('notice', t('js.order_cycles.unsaved_changes'), response.data.trigger_action)
else
StatusMessage.display('failure', "Oh no! I was unable to save your changes.")
StatusMessage.display('failure', t('js.order_cycles.bulk_save_error'))
saved: (order_cycle) ->
@diff(order_cycle).length == 0

View File

@@ -1,6 +0,0 @@
angular.module("admin.utils").directive "textangularLinksTargetBlank", () ->
restrict: 'CA'
link: (scope, element, attrs) ->
setTimeout ->
element.find(".ta-editor").scope().defaultTagAttributes.a.target = '_blank'
, 500

View File

@@ -1,11 +0,0 @@
angular.module("admin.utils").directive "textangularStrip", () ->
restrict: 'CA'
link: (scope, element, attrs) ->
scope.stripFormatting = ($html) ->
element = document.createElement("div")
element.innerHTML = String($html)
allTags = element.getElementsByTagName("*")
for child in allTags
child.removeAttribute("style")
child.removeAttribute("class")
return element.innerHTML

View File

@@ -9,6 +9,7 @@ angular.module("admin.utils")
$window.onbeforeunload = @onBeforeUnloadHandler
$rootScope.$on "$locationChangeStart", @locationChangeStartHandler
$window.onBeforeUnloadHandler = @onBeforeUnloadHandler
# Action for regular browser navigation.
onBeforeUnloadHandler: ($event) =>

View File

@@ -1,2 +1,3 @@
- # NOTE: make sure that any changes in this template are reflected in app/views/admin/products_v3/product_preview.turbo_stream.haml
%li{ "ng-class": "{active: selector.active}" }
%a{ tooltip: "{{selector.object.value}}", "tooltip-placement": "bottom", "ng-transclude": true, "ng-class": "{active: selector.active, 'has-tip': selector.object.value}" }

View File

@@ -1,3 +1,4 @@
- # NOTE: make sure that any changes in this template are reflected in app/views/admin/products_v3/product_preview.turbo_stream.haml
%ul
%active-selector{ "ng-repeat": "selector in allSelectors", "ng-show": "ifDefined(selector.fits, true)" }
%span{"ng-bind" => "::selector.object.name"}

View File

@@ -1,3 +1,4 @@
- # NOTE: make sure that any changes in this template are reflected in app/views/admin/products_v3/product_preview.turbo_stream.haml
.row
.columns.small-12.medium-6.large-6.product-header
%h3{"ng-bind" => "::product.name"}

View File

@@ -0,0 +1 @@
@import './mail/all.scss';

View File

@@ -0,0 +1,3 @@
@import '../../../webpacker/css/admin/globals/palette.scss';
@import 'email';
@import 'payments_list';

View File

@@ -0,0 +1,11 @@
# frozen_string_literal: true
class AdminTooltipComponent < ViewComponent::Base
def initialize(text:, link_text:, placement: "top", link: "", link_class: "")
@text = text
@link_text = link_text
@placement = placement
@link = link
@link_class = link_class
end
end

View File

@@ -0,0 +1,8 @@
%div{"data-controller": "tooltip", "data-tooltip-placement-value": @placement }
%a{"data-tooltip-target": "element", href: @link, class: @link_class}
= @link_text
.tooltip-container
.tooltip{"data-tooltip-target": "tooltip"}
= sanitize @text
.arrow{"data-tooltip-target": "arrow"}

View File

@@ -1,11 +1,15 @@
# frozen_string_literal: true
class ModalComponent < ViewComponent::Base
def initialize(id:, close_button: true, instant: false, modal_class: :small)
def initialize(id:, close_button: true, instant: false, modal_class: :small, **options)
@id = id
@close_button = close_button
@instant = instant
@modal_class = modal_class
@options = options
@data_controller = "modal #{@options.delete(:'data-controller')}".squish
@data_action =
"keyup@document->modal#closeIfEscapeKey #{@options.delete(:'data-action')}".squish
end
private

View File

@@ -1,4 +1,4 @@
%div{ id: @id, "data-controller": "modal", "data-action": "keyup@document->modal#closeIfEscapeKey", "data-modal-instant-value": @instant }
%div{ id: @id, "data-controller": @data_controller, "data-action": @data_action, "data-modal-instant-value": @instant, **@options }
.reveal-modal-bg.fade{ "data-modal-target": "background", "data-action": "click->modal#close" }
.reveal-modal.fade.modal-component{ "data-modal-target": "modal", class: @modal_class }
= content

View File

@@ -11,7 +11,8 @@ class SearchableDropdownComponent < ViewComponent::Base
selected_option:,
placeholder_value:,
include_blank: false,
aria_label: ''
aria_label: '',
other_attrs: {}
)
@f = form
@name = name
@@ -20,11 +21,13 @@ class SearchableDropdownComponent < ViewComponent::Base
@placeholder_value = placeholder_value
@include_blank = include_blank
@aria_label = aria_label
@other_attrs = other_attrs
end
private
attr_reader :f, :name, :options, :selected_option, :placeholder_value, :include_blank, :aria_label
attr_reader :f, :name, :options, :selected_option, :placeholder_value, :include_blank,
:aria_label, :other_attrs
def classes
"fullwidth #{remove_search_plugin? ? 'no-input' : ''}"

View File

@@ -1 +1 @@
= f.select name, options_for_select(options, selected_option), { include_blank: }, class: classes, data:, 'aria-label': aria_label
= f.select name, options_for_select(options, selected_option), { include_blank: }, class: classes, data:, 'aria-label': aria_label, **other_attrs

View File

@@ -8,6 +8,10 @@ export default class extends Controller {
window.addEventListener("click", this.#hideIfClickedOutside);
}
disconnect() {
window.removeEventListener("click", this.#hideIfClickedOutside);
}
toggle() {
this.contentTarget.classList.toggle("show");
}

View File

@@ -26,7 +26,15 @@ module Admin
# * First step: import all products for given enterprise.
# * Second step: render table and let user decide which ones to import.
imported = graph.map do |subject|
import_product(subject, enterprise)
next unless subject.is_a? DataFoodConsortium::Connector::SuppliedProduct
existing_variant = enterprise.supplied_variants.linked_to(subject.semanticId)
if existing_variant
SuppliedProductBuilder.update_product(subject, existing_variant)
else
SuppliedProductBuilder.store_product(subject, enterprise)
end
end
@count = imported.compact.count
@@ -37,18 +45,5 @@ module Admin
def fetch_catalog(url)
DfcRequest.new(spree_current_user).call(url)
end
# Most of this code is the same as in the DfcProvider::SuppliedProductsController.
def import_product(subject, enterprise)
return unless subject.is_a? DataFoodConsortium::Connector::SuppliedProduct
variant = SuppliedProductBuilder.import_variant(subject, enterprise)
product = variant.product
product.save! if product.new_record?
variant.save! if variant.new_record?
variant
end
end
end

View File

@@ -2,6 +2,8 @@
module Admin
class OrderCyclesController < Admin::ResourceController
class DateTimeChangeError < StandardError; end
include ::OrderCyclesHelper
include PaperTrailLogging
@@ -11,7 +13,6 @@ module Admin
before_action :remove_protected_attrs, only: [:update]
before_action :require_order_cycle_set_params, only: [:bulk_update]
around_action :protect_invalid_destroy, only: :destroy
before_action :verify_datetime_change, only: :update
def index
respond_to do |format|
@@ -63,9 +64,7 @@ module Admin
end
def update
@order_cycle_form = OrderCycles::FormService.new(@order_cycle, order_cycle_params,
spree_current_user)
@order_cycle_form = set_order_cycle_form
if @order_cycle_form.save
update_nil_subscription_line_items_price_estimate(@order_cycle)
respond_to do |format|
@@ -78,6 +77,9 @@ module Admin
elsif request.format.json?
render json: { errors: @order_cycle.errors.full_messages }, status: :unprocessable_entity
end
rescue DateTimeChangeError
render json: { trigger_action: params[:trigger_action] },
status: :unprocessable_entity
end
def bulk_update
@@ -91,6 +93,9 @@ module Admin
order_cycle = order_cycle_set.collection.find{ |oc| oc.errors.present? }
render json: { errors: order_cycle.errors.full_messages }, status: :unprocessable_entity
end
rescue DateTimeChangeError
render json: { trigger_action: params[:trigger_action] },
status: :unprocessable_entity
end
def bulk_update_nil_subscription_line_items_price_estimate
@@ -271,7 +276,10 @@ module Admin
end
def order_cycle_set
@order_cycle_set ||= Sets::OrderCycleSet.new(@order_cycles, order_cycle_bulk_params)
@order_cycle_set ||= Sets::OrderCycleSet.new(
@order_cycles, { **order_cycle_bulk_params,
confirm_datetime_change: params[:confirm], error_class: DateTimeChangeError }
)
end
def require_order_cycle_set_params
@@ -296,21 +304,13 @@ module Admin
).to_h.with_indifferent_access
end
# Check that order cycle datetime values changed if it has existing orders
def verify_datetime_change
return unless params[:order_cycle][:confirm]
return unless @order_cycle.orders.exists?
return if same_dates(@order_cycle.orders_open_at, order_cycle_params[:orders_open_at]) &&
same_dates(@order_cycle.orders_close_at, order_cycle_params[:orders_close_at])
render json: { trigger_action: params[:order_cycle][:trigger_action] },
status: :unprocessable_entity
end
def same_dates(date, string)
false unless date && string
DateTime.parse(string).to_fs(:short) == date.to_fs(:short)
def set_order_cycle_form
OrderCycles::FormService.new(
@order_cycle, order_cycle_params.merge(
{ confirm_datetime_change: params[:order_cycle][:confirm],
error_class: DateTimeChangeError }
), spree_current_user
)
end
end
end

View File

@@ -0,0 +1,22 @@
# frozen_string_literal: true
module Admin
class ProductPreviewController < Spree::Admin::BaseController
def show
@product = Spree::Product.find(params[:id])
authorize! :show, @product
respond_with do |format|
format.turbo_stream {
render "admin/products_v3/product_preview", status: :ok
}
end
end
private
def model_class
Spree::Product
end
end
end

View File

@@ -40,6 +40,8 @@ module Admin
{ id: params[:id] }
).find_product
authorize! :delete, @record
@record.destroyed_by = spree_current_user
status = :ok
@@ -74,6 +76,8 @@ module Admin
def clone
@product = Spree::Product.find(params[:id])
authorize! :clone, @product
status = :ok
begin
@@ -84,8 +88,8 @@ module Admin
@producer_options = producers
@category_options = categories
@tax_category_options = tax_category_options
rescue ActiveRecord::ActiveRecordError => _e
flash.now[:error] = t('.error')
rescue ActiveRecord::ActiveRecordError => e
flash.now[:error] = clone_error_message(e)
status = :unprocessable_entity
@product_index = "-1" # Create a unique enough index
end
@@ -209,6 +213,15 @@ module Admin
params.permit(products: ::PermittedAttributes::Product.attributes)
.to_h.with_indifferent_access
end
def clone_error_message(error)
case error
when ActiveRecord::RecordInvalid
error.record.errors.full_messages.to_sentence
else
t('.error')
end
end
end
end
# rubocop:enable Metrics/ClassLength

View File

@@ -6,7 +6,7 @@ module Admin
include ReportsActions
helper ReportsHelper
before_action :authorize_report, only: [:show]
before_action :authorize_report, only: [:show, :create]
# Define model class for Can? permissions
def model_class
@@ -20,14 +20,17 @@ module Admin
end
def show
@report = report_class.new(spree_current_user, params, render: render_data?)
@rendering_options = rendering_options # also stores user preferences
@report = report_class.new(spree_current_user, params, render: false)
@rendering_options = rendering_options
if render_data?
render_in_background
else
show_report
end
show_report
end
def create
@report = report_class.new(spree_current_user, params, render: true)
update_rendering_options
render_in_background
end
private
@@ -54,31 +57,15 @@ module Admin
@variant_serialized = Api::Admin::VariantSerializer.new(variant)
end
def render_data?
request.post?
end
def render_in_background
cable_ready[ScopedChannel.for_id(params[:uuid])]
.inner_html(
selector: "#report-go",
html: helpers.button(t(:go), "report__submit-btn", "submit", disabled: true)
).inner_html(
selector: "#report-table",
html: render_to_string(partial: "admin/reports/loading")
).scroll_into_view(
selector: "#report-table",
block: "start"
).broadcast
@blob = ReportBlob.create_for_upload_later!(report_filename)
ReportJob.perform_later(
report_class:, user: spree_current_user, params:,
format: report_format,
filename: report_filename,
blob: @blob,
channel: ScopedChannel.for_id(params[:uuid]),
)
head :no_content
end
end
end

View File

@@ -11,6 +11,8 @@ class CartController < BaseController
order.cap_quantity_at_stock!
order.recreate_all_fees!
StockSyncJob.sync_linked_catalogs(order)
render json: { error: false, stock_levels: stock_levels(order) }, status: :ok
else
render json: { error: cart_service.errors.full_messages.join(",") },

View File

@@ -9,6 +9,12 @@ module CheckoutCallbacks
# Otherwise we fail on duplicate indexes or end up with negative stock.
prepend_around_action CurrentOrderLocker, only: [:edit, :update]
# We want to download the latest stock data before anything else happens.
# We don't want it to be in the same database transaction as the order
# locking because this action locks a different set of variants and it
# could cause race conditions.
prepend_around_action :sync_stock, only: :update
prepend_before_action :check_hub_ready_for_checkout
prepend_before_action :check_order_cycle_expiry
prepend_before_action :require_order_cycle
@@ -25,6 +31,14 @@ module CheckoutCallbacks
private
def sync_stock
if current_order&.state == "confirmation"
StockSyncJob.sync_linked_catalogs_now(current_order)
end
yield
end
def load_order
@order = current_order
@order.manual_shipping_selection = true
@@ -63,12 +77,6 @@ module CheckoutCallbacks
end
end
def valid_order_line_items?
@order.insufficient_stock_lines.empty? &&
OrderCycles::DistributedVariantsService.new(@order.order_cycle, @order.distributor).
distributes_order_variants?(@order)
end
def ensure_order_not_completed
redirect_to main_app.cart_path if @order.completed?
end

View File

@@ -88,14 +88,10 @@ module ReportsActions
display_header_row: false
}
end
update_rendering_options
@rendering_options
end
def update_rendering_options
return unless request.post?
@rendering_options.update(
rendering_options.update(
options: {
fields_to_show: params[:fields_to_show],
display_summary_row: params[:display_summary_row].present?,

View File

@@ -10,8 +10,11 @@ module Admin
end
end
def prepare_new_variant(product)
product.variants.build
def prepare_new_variant(product, producer_options)
# e.g producer_options = [['producer name', id]]
product.variants.build do |new_variant|
new_variant.supplier_id = producer_options.first.second if producer_options.one?
end
end
def unit_value_with_description(variant)
@@ -37,5 +40,11 @@ module Admin
"#{admin_products_path}#{url_filters.empty? ? '' : "#?#{url_filters.to_query}"}"
end
# if user hasn't saved any preferences on products page and there's only one producer;
# we need to hide producer column
def hide_producer_column?(producer_options)
spree_current_user.column_preferences.bulk_edit_product.empty? && producer_options.one?
end
end
end

View File

@@ -61,15 +61,6 @@ module ApplicationHelper
classes << shopfront_layout
end
def pdf_stylesheet_pack_tag(source)
if running_in_development?
options = { media: "all", host: "#{Webpacker.dev_server.host}:#{Webpacker.dev_server.port}" }
stylesheet_pack_tag(source, **options)
else
wicked_pdf_stylesheet_pack_tag(source)
end
end
def cache_with_locale(key = nil, options = {}, &block)
cache(cache_key_with_locale(key, I18n.locale), options) do
yield(block)

View File

@@ -8,11 +8,13 @@ module InjectionHelper
include OrderCyclesHelper
def inject_enterprises(enterprises = nil)
enterprises ||= default_enterprise_query
inject_json_array(
"enterprises",
enterprises || default_enterprise_query,
enterprises,
Api::EnterpriseSerializer,
enterprise_injection_data,
enterprise_injection_data(enterprises.map(&:id)),
)
end
@@ -57,15 +59,16 @@ module InjectionHelper
inject_json_array "enterprises",
enterprises_and_relatives,
Api::EnterpriseSerializer,
enterprise_injection_data
enterprise_injection_data(enterprises_and_relatives.map(&:id))
end
def inject_group_enterprises(group)
enterprises = group.enterprises.activated.visible.all
inject_json_array(
"enterprises",
group.enterprises.activated.visible.all,
enterprises,
Api::EnterpriseSerializer,
enterprise_injection_data,
enterprise_injection_data(enterprises.map(&:id)),
)
end
@@ -73,7 +76,7 @@ module InjectionHelper
inject_json "currentHub",
current_distributor,
Api::EnterpriseSerializer,
enterprise_injection_data
enterprise_injection_data(current_distributor ? [current_distributor.id] : nil)
end
def inject_current_order
@@ -153,7 +156,9 @@ module InjectionHelper
Enterprise.activated.includes(address: [:state, :country]).all
end
def enterprise_injection_data
@enterprise_injection_data ||= { data: OpenFoodNetwork::EnterpriseInjectionData.new }
def enterprise_injection_data(enterprise_ids)
{
data: OpenFoodNetwork::EnterpriseInjectionData.new(enterprise_ids)
}
end
end

135
app/jobs/backorder_job.rb Normal file
View File

@@ -0,0 +1,135 @@
# frozen_string_literal: true
class BackorderJob < ApplicationJob
# In the current FDC project, one shop wants to review and adjust orders
# before finalising. They also run a market stall and need to adjust stock
# levels after the market. This should be done within four hours.
SALE_SESSION_DELAYS = {
# https://openfoodnetwork.org.uk/handleyfarm/shop
"https://openfoodnetwork.org.uk/api/dfc/enterprises/203468" => 4.hours,
}.freeze
queue_as :default
sidekiq_options retry: 0
def self.check_stock(order)
links = SemanticLink.where(variant_id: order.line_items.select(:variant_id))
perform_later(order) if links.exists?
rescue StandardError => e
# Errors here shouldn't affect the checkout. So let's report them
# separately:
Bugsnag.notify(e) do |payload|
payload.add_metadata(:order, order)
end
end
def perform(order)
OrderLocker.lock_order_and_variants(order) do
place_backorder(order)
end
rescue StandardError
# If the backordering fails, we need to tell the shop owner because they
# need to organgise more stock.
BackorderMailer.backorder_failed(order).deliver_later
raise
end
def place_backorder(order)
user = order.distributor.owner
items = backorderable_items(order)
# We are assuming that all variants are linked to the same wholesale
# shop and its catalog:
reference_link = items[0].variant.semantic_links[0].semantic_id
urls = FdcUrlBuilder.new(reference_link)
orderer = FdcBackorderer.new(user, urls)
backorder = orderer.find_or_build_order(order)
broker = load_broker(order.distributor.owner, urls)
ordered_quantities = {}
items.each do |item|
retail_quantity = add_item_to_backorder(item, broker, backorder, orderer)
ordered_quantities[item] = retail_quantity
end
place_order(user, order, orderer, backorder)
items.each do |item|
variant = item.variant
variant.on_hand += ordered_quantities[item] if variant.on_demand
end
end
# We look at linked variants which are either stock controlled or
# are on demand with negative stock.
def backorderable_items(order)
order.line_items.select do |item|
# TODO: scope variants to hub.
# We are only supporting producer stock at the moment.
variant = item.variant
variant.semantic_links.present? &&
(variant.on_demand == false || variant.on_hand&.negative?)
end
end
def add_item_to_backorder(line_item, broker, backorder, orderer)
variant = line_item.variant
needed_quantity = needed_quantity(line_item)
solution = broker.best_offer(variant.semantic_links[0].semantic_id)
# The number of wholesale packs we need to order to fulfill the
# needed quantity.
# For example, we order 2 packs of 12 cans if we need 15 cans.
wholesale_quantity = (needed_quantity.to_f / solution.factor).ceil
# The number of individual retail items we get with the wholesale order.
# For example, if we order 2 packs of 12 cans, we will get 24 cans
# and we'll account for that in our stock levels.
retail_quantity = wholesale_quantity * solution.factor
line = orderer.find_or_build_order_line(backorder, solution.offer)
line.quantity = line.quantity.to_i + wholesale_quantity
retail_quantity
end
# We have two different types of stock management:
#
# 1. on demand
# We don't restrict sales but account for the quantity sold in our local
# stock level. If it goes negative, we need more stock and trigger a
# backorder.
# 2. limited stock
# The local stock level is a copy from another catalog. We limit sales
# according to that stock level. Every order reduces the local stock level
# and needs to trigger a backorder of the same quantity to stay in sync.
def needed_quantity(line_item)
variant = line_item.variant
if variant.on_demand
-1 * variant.on_hand # on_hand is negative and we need to replenish it.
else
line_item.quantity # We need to order exactly what's we sold.
end
end
def load_broker(user, urls)
FdcOfferBroker.new(user, urls)
end
def place_order(user, order, orderer, backorder)
placed_order = orderer.send_order(backorder)
return unless orderer.new?(backorder)
delay = SALE_SESSION_DELAYS.fetch(backorder.client, 1.minute)
wait_until = order.order_cycle.orders_close_at + delay
CompleteBackorderJob.set(wait_until:)
.perform_later(
user, order.distributor, order.order_cycle, placed_order.semanticId
)
end
end

View File

@@ -0,0 +1,79 @@
# frozen_string_literal: true
# After an order cycle closed, we need to finalise open draft orders placed
# to replenish stock.
class CompleteBackorderJob < ApplicationJob
sidekiq_options retry: 0
# Required parameters:
#
# * user: to authenticate DFC requests
# * distributor: to reconile with its catalog
# * order_cycle: to scope the catalog when looking up variants
# Multiple variants can be linked to the same remote product.
# To reduce ambiguity, we'll reconcile only with products
# from the given distributor in a given order cycle for which
# the remote backorder was placed.
# * order_id: the remote semantic id of a draft order
# Having the id makes sure that we don't accidentally finalise
# someone else's order.
def perform(user, distributor, order_cycle, order_id)
order = FdcBackorderer.new(user, nil).find_order(order_id)
urls = FdcUrlBuilder.new(order.lines[0].offer.offeredItem.semanticId)
variants = order_cycle.variants_distributed_by(distributor)
adjust_quantities(order_cycle, user, order, urls, variants)
FdcBackorderer.new(user, urls).complete_order(order)
rescue StandardError
BackorderMailer.backorder_incomplete(user, distributor, order_cycle, order_id).deliver_later
raise
end
# Check if we have enough stock to reduce the backorder.
#
# Our local stock can increase when users cancel their orders.
# But stock levels could also have been adjusted manually. So we review all
# quantities before finalising the order.
def adjust_quantities(order_cycle, user, order, urls, variants)
broker = FdcOfferBroker.new(user, urls)
order.lines.each do |line|
line.quantity = line.quantity.to_i
wholesale_product_id = line.offer.offeredItem.semanticId
transformation = broker.wholesale_to_retail(wholesale_product_id)
linked_variant = variants.linked_to(transformation.retail_product_id)
# Find all line items for this order cycle
# Update quantity accordingly
if linked_variant.on_demand
release_superfluous_stock(line, linked_variant, transformation)
else
aggregate_final_quantities(order_cycle, line, linked_variant, transformation)
end
end
# Clean up empty lines:
order.lines.reject! { |line| line.quantity.zero? }
end
def release_superfluous_stock(line, linked_variant, transformation)
# Note that a division of integers dismisses the remainder, like `floor`:
wholesale_items_contained_in_stock = linked_variant.on_hand / transformation.factor
# But maybe we didn't actually order that much:
deductable_quantity = [line.quantity, wholesale_items_contained_in_stock].min
line.quantity -= deductable_quantity
retail_stock_changes = deductable_quantity * transformation.factor
linked_variant.on_hand -= retail_stock_changes
end
def aggregate_final_quantities(order_cycle, line, variant, transformation)
orders = order_cycle.orders.invoiceable
quantity = Spree::LineItem.where(order: orders, variant:).sum(:quantity)
wholesale_quantity = (quantity.to_f / transformation.factor).ceil
line.quantity = wholesale_quantity
end
end

View File

@@ -9,12 +9,12 @@ class ReportJob < ApplicationJob
NOTIFICATION_TIME = 5.seconds
def perform(report_class:, user:, params:, format:, filename:, channel: nil)
def perform(report_class:, user:, params:, format:, blob:, channel: nil)
start_time = Time.zone.now
report = report_class.new(user, params, render: true)
result = report.render_as(format)
blob = ReportBlob.create!(filename, result)
blob.store(result)
execution_time = Time.zone.now - start_time

View File

@@ -0,0 +1,79 @@
# frozen_string_literal: true
class StockSyncJob < ApplicationJob
# No retry but stay as failed job:
sidekiq_options retry: 0
# We synchronise stock of stock-controlled variants linked to a remote
# product. These variants are rare though and we check first before we
# enqueue a new job. That should save some time loading the order with
# all the stock data to make this decision.
def self.sync_linked_catalogs(order)
user = order.distributor.owner
catalog_ids(order).each do |catalog_id|
perform_later(user, catalog_id)
end
rescue StandardError => e
# Errors here shouldn't affect the shopping. So let's report them
# separately:
Bugsnag.notify(e) do |payload|
payload.add_metadata(:order, order)
end
end
def self.sync_linked_catalogs_now(order)
user = order.distributor.owner
catalog_ids(order).each do |catalog_id|
perform_now(user, catalog_id)
end
rescue StandardError => e
# Errors here shouldn't affect the shopping. So let's report them
# separately:
Bugsnag.notify(e) do |payload|
payload.add_metadata(:order, order)
end
end
def self.catalog_ids(order)
stock_controlled_variants = order.variants.reject(&:on_demand)
links = SemanticLink.where(variant_id: stock_controlled_variants.map(&:id))
semantic_ids = links.pluck(:semantic_id)
semantic_ids.map do |product_id|
FdcUrlBuilder.new(product_id).catalog_url
end.uniq
end
def perform(user, catalog_id)
products = load_products(user, catalog_id)
products_by_id = products.index_by(&:semanticId)
product_ids = products_by_id.keys
variants = linked_variants(user.enterprises, product_ids)
# Avoid race condition between checkout and stock sync.
Spree::Variant.transaction do
variants.order(:id).lock.each do |variant|
next if variant.on_demand
product = products_by_id[variant.semantic_links[0].semantic_id]
catalog_item = product&.catalogItems&.first
CatalogItemBuilder.apply_stock(catalog_item, variant)
variant.stock_items[0].save!
end
end
end
def load_products(user, catalog_id)
json_catalog = DfcRequest.new(user).call(catalog_id)
graph = DfcIo.import(json_catalog)
graph.select do |subject|
subject.is_a? DataFoodConsortium::Connector::SuppliedProduct
end
end
def linked_variants(enterprises, product_ids)
Spree::Variant.where(supplier: enterprises)
.includes(:semantic_links).references(:semantic_links)
.where(semantic_links: { semantic_id: product_ids })
end
end

View File

@@ -0,0 +1,24 @@
# frozen_string_literal: true
class BackorderMailer < ApplicationMailer
include I18nHelper
def backorder_failed(order)
@order = order
@linked_variants = order.variants
I18n.with_locale valid_locale(order.distributor.owner) do
mail(to: order.distributor.owner.email)
end
end
def backorder_incomplete(user, distributor, order_cycle, order_id)
@distributor = distributor
@order_cycle = order_cycle
@order_id = order_id
I18n.with_locale valid_locale(user) do
mail(to: user.email)
end
end
end

View File

@@ -15,10 +15,11 @@ class ColumnPreference < ApplicationRecord
validates :column_name, presence: true, inclusion: { in: proc { |p|
valid_columns_for(p.action_name)
} }
scope :bulk_edit_product, -> { where(action_name: 'products_v3_index') }
def self.for(user, action_name)
stored_preferences = where(user_id: user.id, action_name:)
default_preferences = __send__("#{action_name}_columns")
default_preferences = get_default_preferences(action_name, user)
filter(default_preferences, user, action_name)
default_preferences.each_with_object([]) do |(column_name, default_attributes), preferences|
stored_preference = stored_preferences.find_by(column_name:)
@@ -36,7 +37,7 @@ class ColumnPreference < ApplicationRecord
end
def self.valid_columns_for(action_name)
__send__("#{action_name}_columns").keys.map(&:to_s)
get_default_preferences(action_name, Spree::User.new).keys.map(&:to_s)
end
def self.known_actions
@@ -52,4 +53,13 @@ class ColumnPreference < ApplicationRecord
default_preferences.delete(:schedules)
end
def self.get_default_preferences(action_name, user)
case action_name
when 'products_v3_index'
products_v3_index_columns(user)
else
__send__("#{action_name}_columns")
end
end
end

View File

@@ -6,14 +6,14 @@
# `count_on_hand` can either be: nil or a number
#
# This means that a variant override can be in six different stock states
# but only three of them are valid.
# but only four of them are valid.
#
# | on_demand | count_on_hand | stock_overridden? | use_producer_stock_settings? | valid? |
# |-----------|---------------|-------------------|------------------------------|--------|
# | 1 | nil | false | false | true |
# | 1 | nil | true | false | true |
# | 0 | x | true | false | true |
# | nil | nil | false | true | true |
# | 1 | x | ? | ? | false |
# | 1 | x | true | false | true |
# | 0 | nil | ? | ? | false |
# | nil | x | ? | ? | false |
#
@@ -27,7 +27,6 @@ module StockSettingsOverrideValidation
def require_compatible_on_demand_and_count_on_hand
disallow_count_on_hand_if_using_producer_stock_settings
disallow_count_on_hand_if_on_demand
require_count_on_hand_if_limited_stock
end
@@ -39,14 +38,6 @@ module StockSettingsOverrideValidation
errors.add(:count_on_hand, error_message)
end
def disallow_count_on_hand_if_on_demand
return unless on_demand? && count_on_hand.present?
error_message = I18n.t("count_on_hand.on_demand_but_count_on_hand_set",
scope: i18n_scope_for_stock_settings_override_validation_error)
errors.add(:count_on_hand, error_message)
end
def require_count_on_hand_if_limited_stock
return unless on_demand == false && count_on_hand.blank?

View File

@@ -43,19 +43,9 @@ module VariantStock
def on_demand
# A variant that has not been saved yet or has been soft-deleted doesn't have a stock item
# This provides a default value for variant.on_demand
# using Spree::StockLocation.backorderable_default
return Spree::StockLocation.first.backorderable_default if new_record? || deleted?
return false if new_record? || deleted?
# This can be removed unless we have seen this error in Bugsnag recently
if stock_item.nil?
Bugsnag.notify(
RuntimeError.new("Variant #stock_item called, but the stock_item does not exist!"),
object: as_json
)
return Spree::StockLocation.first.backorderable_default
end
stock_item.backorderable?
stock_item&.backorderable?
end
# Sets whether the variant can be ordered on demand or not. Note that
@@ -96,7 +86,7 @@ module VariantStock
# Here we depend only on variant.total_on_hand and variant.on_demand.
# This way, variant_overrides only need to override variant.total_on_hand and variant.on_demand.
def fill_status(quantity)
on_hand = if total_on_hand >= quantity || on_demand
on_hand = if total_on_hand.to_i >= quantity || on_demand
quantity
else
[0, total_on_hand].max
@@ -112,8 +102,7 @@ module VariantStock
#
# This enables us to override this behaviour for variant overrides
def move(quantity, originator = nil)
# Don't change variant stock if variant is on_demand or has been deleted
return if on_demand || deleted_at
return if deleted_at
raise_error_if_no_stock_item_available

View File

@@ -1,7 +1,5 @@
# frozen_string_literal: false
require "mini_magick"
class Enterprise < ApplicationRecord
SELLS = %w(unspecified none own any).freeze
ENTERPRISE_SEARCH_RADIUS = 100
@@ -249,14 +247,17 @@ class Enterprise < ApplicationRecord
count(distinct: true)
end
# Remove any unsupported HTML.
def long_description
HtmlSanitizer.sanitize(super)
def long_description=(html)
super(HtmlSanitizer.sanitize_and_enforce_link_target_blank(html))
end
# Remove any unsupported HTML.
def long_description=(html)
super(HtmlSanitizer.sanitize(html))
def preferred_shopfront_message=(html)
self.prefers_shopfront_message = HtmlSanitizer.sanitize_and_enforce_link_target_blank(html)
end
def preferred_shopfront_closed_message=(html)
self.prefers_shopfront_closed_message =
HtmlSanitizer.sanitize_and_enforce_link_target_blank(html)
end
def contact
@@ -479,7 +480,7 @@ class Enterprise < ApplicationRecord
return unless image.variable?
image_variant_url_for(image.variant(name))
rescue ActiveStorage::Error, MiniMagick::Error, ActionView::Template::Error => e
rescue StandardError => e
Bugsnag.notify "Enterprise ##{id} #{image.try(:name)} error: #{e.message}"
Rails.logger.error(e.message)

View File

@@ -76,12 +76,12 @@ class EnterpriseGroup < ApplicationRecord
# Remove any unsupported HTML.
def long_description
HtmlSanitizer.sanitize(super)
HtmlSanitizer.sanitize_and_enforce_link_target_blank(super)
end
# Remove any unsupported HTML.
def long_description=(html)
super(HtmlSanitizer.sanitize(html))
super(HtmlSanitizer.sanitize_and_enforce_link_target_blank(html))
end
private

View File

@@ -148,17 +148,20 @@ class OrderCycle < ApplicationRecord
# Find the earliest closing times for each distributor in an active order cycle, and return
# them in the format {distributor_id => closing_time, ...}
def self.earliest_closing_times
Hash[
Exchange.
outgoing.
joins(:order_cycle).
merge(OrderCycle.active).
group('exchanges.receiver_id').
select("exchanges.receiver_id AS receiver_id,
MIN(order_cycles.orders_close_at) AS earliest_close_at").
map { |ex| [ex.receiver_id, ex.earliest_close_at.to_time] }
]
#
# Optionally, specify some distributor_ids as a parameter to scope the results
def self.earliest_closing_times(distributor_ids = nil)
cycles = Exchange.
outgoing.
joins(:order_cycle).
merge(OrderCycle.active).
group('exchanges.receiver_id')
cycles = cycles.where(receiver_id: distributor_ids) if distributor_ids.present?
cycles.pluck("exchanges.receiver_id AS receiver_id",
"MIN(order_cycles.orders_close_at) AS earliest_close_at")
.to_h
end
def attachable_distributor_payment_methods
@@ -314,6 +317,13 @@ class OrderCycle < ApplicationRecord
coordinator.sells == 'own'
end
def same_datetime_value(attribute, string)
return true if self[attribute].blank? && string.blank?
return false if self[attribute].blank? || string.blank?
DateTime.parse(string).to_fs(:short) == self[attribute]&.to_fs(:short)
end
private
def opening?

View File

@@ -5,7 +5,7 @@ class ReportBlob < ActiveStorage::Blob
# AWS S3 limits URL expiry to one week.
LIFETIME = 1.week
def self.create!(filename, content)
def self.create_locally!(filename, content)
create_and_upload!(
io: StringIO.new(content),
filename:,
@@ -15,11 +15,34 @@ class ReportBlob < ActiveStorage::Blob
)
end
def self.create_for_upload_later!(filename)
# ActiveStorage discourages modifying a blob later but we need a blob
# before we know anything about the report file. It enables us to use the
# same blob in the controller to read the result.
create_before_direct_upload!(
filename:,
byte_size: 0,
checksum: "0",
content_type: content_type(filename),
service_name: :local,
).tap do |blob|
ActiveStorage::PurgeJob.set(wait: LIFETIME).perform_later(blob)
end
end
def self.content_type(filename)
MIME::Types.of(filename).first&.to_s || "application/octet-stream"
end
def store(content)
io = StringIO.new(content)
upload(io, identify: false)
save!
end
def result
return if checksum == "0"
@result ||= download.force_encoding(Encoding::UTF_8)
end

View File

@@ -29,14 +29,12 @@ module Spree
can :update, Order do |order, token|
order.user == user || (order.token && token == order.token)
end
can [:index, :read], Product
can [:index, :read], ProductProperty
can [:index, :read], Property
can :create, Spree::User
can [:read, :update, :destroy], Spree::User, id: user.id
can [:index, :read], State
can [:index, :read], StockItem
can [:index, :read], StockLocation
can [:index, :read], StockMovement
can [:index, :read], Taxon
can [:index, :read], Variant
@@ -243,8 +241,8 @@ module Spree
can [:admin, :index], ::Admin::DfcProductImportsController
# Reports page
can [:admin, :index, :show], ::Admin::ReportsController
can [:admin, :show, :customers, :orders_and_distributors, :group_buys, :payments,
can [:admin, :index, :show, :create], ::Admin::ReportsController
can [:admin, :show, :create, :customers, :orders_and_distributors, :group_buys, :payments,
:orders_and_fulfillment, :products_and_inventory, :order_cycle_management,
:packing, :enterprise_fee_summary, :bulk_coop], :report
end
@@ -324,7 +322,7 @@ module Spree
end
# Reports page
can [:admin, :index, :show], ::Admin::ReportsController
can [:admin, :index, :show, :create], ::Admin::ReportsController
can [:admin, :customers, :group_buys, :sales_tax, :payments,
:orders_and_distributors, :orders_and_fulfillment, :products_and_inventory,
:order_cycle_management, :xero_invoices, :enterprise_fee_summary, :bulk_coop], :report

View File

@@ -1,7 +1,5 @@
# frozen_string_literal: true
require "mini_magick"
module Spree
class Image < Asset
has_one_attached :attachment, service: image_service do |attachment|
@@ -35,7 +33,7 @@ module Spree
return self.class.default_image_url(size) unless attachment.attached?
image_variant_url_for(variant(size))
rescue ActiveStorage::Error, MiniMagick::Error, ActionView::Template::Error => e
rescue StandardError => e
Bugsnag.notify "Product ##{viewable_id} Image ##{id} error: #{e.message}"
Rails.logger.error(e.message)

View File

@@ -388,6 +388,8 @@ module Spree
deliver_order_confirmation_email
BackorderJob.check_stock(self)
state_changes.create(
previous_state: 'cart',
next_state: 'complete',

View File

@@ -263,10 +263,12 @@ module Spree
# Format as per WeightsAndMeasures (todo: re-orgnaise maybe after product/variant refactor)
def variant_unit_with_scale
# Our code is based upon English based number formatting with a period `.`
scale_clean = ActiveSupport::NumberHelper.number_to_rounded(variant_unit_scale,
precision: nil,
significant: false,
strip_insignificant_zeros: true)
strip_insignificant_zeros: true,
locale: :en)
[variant_unit, scale_clean].compact_blank.join("_")
end
@@ -295,14 +297,8 @@ module Spree
# eg clone product. Will raise error if clonning a product with no variant
return if variants.first&.valid?
unless Spree::Taxon.find_by(id: primary_taxon_id)
errors.add(:primary_taxon_id,
I18n.t('activerecord.errors.models.spree/product.must_exist'))
end
return if Enterprise.find_by(id: supplier_id)
errors.add(:supplier_id,
I18n.t('activerecord.errors.models.spree/product.must_exist'))
errors.add(:primary_taxon_id, :blank) unless Spree::Taxon.find_by(id: primary_taxon_id)
errors.add(:supplier_id, :blank) unless Enterprise.find_by(id: supplier_id)
end
def update_units

View File

@@ -87,16 +87,20 @@ module Spree
# Return the services (pickup, delivery) that different distributors provide, in the format:
# {distributor_id => {pickup: true, delivery: false}, ...}
def self.services
Hash[
Spree::ShippingMethod.
joins(:distributor_shipping_methods).
group('distributor_id').
select("distributor_id").
select("BOOL_OR(spree_shipping_methods.require_ship_address = 'f') AS pickup").
select("BOOL_OR(spree_shipping_methods.require_ship_address = 't') AS delivery").
map { |sm| [sm.distributor_id.to_i, { pickup: sm.pickup, delivery: sm.delivery }] }
]
#
# Optionally, specify some distributor_ids as a parameter to scope the results
def self.services(distributor_ids = nil)
methods = Spree::ShippingMethod.joins(:distributor_shipping_methods).group('distributor_id')
if distributor_ids.present?
methods = methods.where(distributor_shipping_methods: { distributor_id: distributor_ids })
end
methods.
pluck(Arel.sql("distributor_id"),
Arel.sql("BOOL_OR(spree_shipping_methods.require_ship_address = 'f') AS pickup"),
Arel.sql("BOOL_OR(spree_shipping_methods.require_ship_address = 't') AS delivery")).
to_h { |(distributor_id, pickup, delivery)| [distributor_id.to_i, { pickup:, delivery: }] }
end
def self.backend

View File

@@ -7,7 +7,7 @@ module Spree
def initialize(variant)
@variant = variant
@stock_items = fetch_stock_items
@stock_items = @variant.stock_items
end
def total_on_hand
@@ -25,16 +25,6 @@ module Spree
def can_supply?(required)
total_on_hand >= required || backorderable?
end
private
def fetch_stock_items
# Don't re-fetch associated stock items from the DB if we've already eager-loaded them
return @variant.stock_items if @variant.stock_items.loaded?
Spree::StockItem.joins(:stock_location).
where(:variant_id => @variant, Spree::StockLocation.table_name => { active: true })
end
end
end
end

View File

@@ -3,6 +3,7 @@
module Spree
class StockLocation < ApplicationRecord
self.belongs_to_required_by_default = false
self.ignored_columns += [:backorderable_default, :active]
has_many :stock_items, dependent: :delete_all, inverse_of: :stock_location
has_many :stock_movements, through: :stock_items
@@ -12,15 +13,9 @@ module Spree
validates :name, presence: true
scope :active, -> { where(active: true) }
after_create :create_stock_items
# Wrapper for creating a new stock item respecting the backorderable config
def propagate_variant(variant)
stock_items.create!(variant:, backorderable: backorderable_default)
end
def stock_item(variant)
stock_items.where(variant_id: variant).order(:id).first
end
@@ -56,7 +51,7 @@ module Spree
private
def create_stock_items
Variant.find_each { |variant| propagate_variant(variant) }
Variant.find_each { |variant| stock_items.create!(variant:) }
end
end
end

View File

@@ -25,18 +25,19 @@ module Spree
# Find all the taxons of supplied products for each enterprise, indexed by enterprise.
# Format: {enterprise_id => [taxon_id, ...]}
def self.supplied_taxons
taxons = {}
#
# Optionally, specify some enterprise_ids to scope the results
def self.supplied_taxons(enterprise_ids = nil)
taxons = Spree::Taxon.joins(variants: :supplier)
Spree::Taxon.
joins(variants: :supplier).
select('spree_taxons.*, enterprises.id AS enterprise_id').
each do |t|
taxons[t.enterprise_id.to_i] ||= Set.new
taxons[t.enterprise_id.to_i] << t.id
end
taxons = taxons.where(enterprises: { id: enterprise_ids }) if enterprise_ids.present?
taxons
.pluck('spree_taxons.id, enterprises.id AS enterprise_id')
.each_with_object({}) do |(taxon_id, enterprise_id), collection|
collection[enterprise_id.to_i] ||= Set.new
collection[enterprise_id.to_i] << taxon_id
end
end
# Find all the taxons of distributed products for each enterprise, indexed by enterprise.
@@ -44,7 +45,9 @@ module Spree
# or :current taxons (distributed in an open order cycle).
#
# Format: {enterprise_id => [taxon_id, ...]}
def self.distributed_taxons(which_taxons = :all)
#
# Optionally, specify some enterprise_ids to scope the results
def self.distributed_taxons(which_taxons = :all, enterprise_ids = nil)
ents_and_vars = ExchangeVariant.joins(exchange: :order_cycle).merge(Exchange.outgoing)
.select("DISTINCT variant_id, receiver_id AS enterprise_id")
@@ -57,6 +60,10 @@ module Spree
INNER JOIN (#{ents_and_vars.to_sql}) AS ents_and_vars
ON spree_variants.id = ents_and_vars.variant_id")
if enterprise_ids.present?
taxons = taxons.where(ents_and_vars: { enterprise_id: enterprise_ids })
end
taxons.each_with_object({}) do |t, ts|
ts[t.enterprise_id.to_i] ||= Set.new
ts[t.enterprise_id.to_i] << t.id

View File

@@ -42,6 +42,7 @@ module Spree
has_many :credit_cards, dependent: :destroy
has_many :report_rendering_options, class_name: "::ReportRenderingOptions", dependent: :destroy
has_many :webhook_endpoints, dependent: :destroy
has_many :column_preferences, dependent: :destroy
has_one :oidc_account, dependent: :destroy
accepts_nested_attributes_for :enterprise_roles, allow_destroy: true

View File

@@ -170,6 +170,11 @@ module Spree
select("spree_variants.id") })
end
def self.linked_to(semantic_id)
includes(:semantic_links).references(:semantic_links)
.where(semantic_links: { semantic_id: }).first
end
def tax_category
super || TaxCategory.find_by(is_default: true)
end
@@ -235,8 +240,10 @@ module Spree
end
def create_stock_items
return unless stock_items.empty?
StockLocation.find_each do |stock_location|
stock_location.propagate_variant(self)
stock_items.create!(stock_location:)
end
end

View File

@@ -15,7 +15,9 @@ class VariantOverride < ApplicationRecord
# Need to ensure this can be set by the user.
validates :default_stock, numericality: { greater_than_or_equal_to: 0 }, allow_nil: true
validates :price, numericality: { greater_than_or_equal_to: 0 }, allow_nil: true
validates :count_on_hand, numericality: { greater_than_or_equal_to: 0 }, allow_nil: true
validates :count_on_hand, numericality: {
greater_than_or_equal_to: 0, unless: :on_demand?
}, allow_nil: true
default_scope { where(permission_revoked_at: nil) }
@@ -36,9 +38,8 @@ class VariantOverride < ApplicationRecord
end
def stock_overridden?
# If count_on_hand is present, it means on_demand is false
# See StockSettingsOverrideValidation for details
count_on_hand.present?
# Testing for not nil because for a boolean `false.present?` is false.
!on_demand.nil? || !count_on_hand.nil?
end
def use_producer_stock_settings?

View File

@@ -95,9 +95,7 @@ module Api
.merge(Exchange.to_enterprise(enterprise))
.select('DISTINCT spree_properties.*')
return properties.merge(OrderCycle.active) if active
properties
properties.merge(OrderCycle.active)
end
def distributed_producer_properties
@@ -106,16 +104,14 @@ module Api
properties = Spree::Property
.joins(
producer_properties: {
producer: { supplied_products: { variants: { exchanges: :order_cycle } } }
producer: { supplied_variants: { exchanges: :order_cycle } }
}
)
.merge(Exchange.outgoing)
.merge(Exchange.to_enterprise(enterprise))
.select('DISTINCT spree_properties.*')
return properties.merge(OrderCycle.active) if active
properties
properties.merge(OrderCycle.active)
end
def active

View File

@@ -7,7 +7,7 @@ module Api
attributes :orders_close_at, :active
def orders_close_at
options[:data].earliest_closing_times[object.id]
options[:data].earliest_closing_times[object.id]&.to_time
end
def active

View File

@@ -10,33 +10,6 @@ class CurrentOrderLocker
# https://guides.rubyonrails.org/action_controller_overview.html#filters
#
def self.around(controller, &)
lock_order_and_variants(controller.current_order, &)
OrderLocker.lock_order_and_variants(controller.current_order, &)
end
# Locking will not prevent all access to these rows. Other processes are
# only waiting if they try to lock one of these rows as well.
#
# https://api.rubyonrails.org/classes/ActiveRecord/Locking/Pessimistic.html
#
def self.lock_order_and_variants(order)
return yield if order.nil?
order.with_lock do
lock_variants_of(order)
yield
end
end
private_class_method :lock_order_and_variants
# There are many places in which stock is stored in the database. Row locking
# on variant level ensures that there are no conflicts even when an item is
# sold through multiple shops.
def self.lock_variants_of(order)
variant_ids = order.line_items.select(:variant_id)
# Ordering the variants by id prevents deadlocks. Plucking the ids sends
# the locking query without building Spree::Variant objects.
Spree::Variant.where(id: variant_ids).order(:id).lock.pluck(:id)
end
private_class_method :lock_variants_of
end

View File

@@ -0,0 +1,133 @@
# frozen_string_literal: true
# Place and update orders based on missing stock.
class FdcBackorderer
attr_reader :user, :urls
def initialize(user, urls)
@user = user
@urls = urls
end
def find_or_build_order(ofn_order)
find_open_order || build_new_order(ofn_order)
end
def build_new_order(ofn_order)
OrderBuilder.new_order(ofn_order, urls.orders_url).tap do |order|
order.saleSession = build_sale_session(ofn_order)
end
end
def find_open_order
graph = import(urls.orders_url)
open_orders = graph&.select do |o|
o.semanticType == "dfc-b:Order" && o.orderStatus[:path] == "Held"
end
return if open_orders.blank?
# If there are multiple open orders, we don't know which one to choose.
# We want the order we placed for the same distributor in the same order
# cycle before. So here are some assumptions for this to work:
#
# * We see only orders for our distributor. The endpoint URL contains the
# the distributor name and is currently hardcoded.
# * There's only one open order cycle at a time. Otherwise we may select
# an order of an old order cycle.
# * Orders are finalised when the order cycle closes. So _Held_ orders
# always belong to an open order cycle.
# * We see only our own orders. This assumption is wrong. The Shopify
# integration places held orders as well and they are visible to us.
#
# Unfortunately, the endpoint doesn't tell who placed the order.
# TODO: We need to remember the link to the order locally.
# Or the API is updated to include the orderer.
#
# For now, we just guess:
open_orders.last.tap do |order|
# The DFC Connector doesn't recognise status values properly yet.
# So we are overriding the value with something that can be exported.
order.orderStatus = "dfc-v:Held"
end
end
def find_order(semantic_id)
find_subject(import(semantic_id), "dfc-b:Order")
end
def find_or_build_order_line(order, offer)
find_order_line(order, offer) || build_order_line(order, offer)
end
def build_order_line(order, offer)
# Order lines are enumerated in the FDC API and we must assign a unique
# semantic id. We need to look at current ids to avoid collisions.
# existing_ids = order.lines.map do |line|
# line.semanticId.match(/[0-9]+$/).to_s.to_i
# end
# next_id = existing_ids.max.to_i + 1
# Suggested by FDC team:
next_id = order.lines.count + 1
OrderLineBuilder.build(offer, 0).tap do |line|
line.semanticId = "#{order.semanticId}/OrderLines/#{next_id}"
order.lines << line
end
end
def find_order_line(order, offer)
order.lines.find do |line|
line.offer.offeredItem.semanticId == offer.offeredItem.semanticId
end
end
def find_subject(object_or_graph, type)
if object_or_graph.is_a?(Array)
object_or_graph.find { |i| i.semanticType == type }
else
object_or_graph
end
end
def import(url)
api = DfcRequest.new(user)
json = api.call(url)
DfcIo.import(json)
end
def send_order(backorder)
lines = backorder.lines
offers = lines.map(&:offer)
products = offers.map(&:offeredItem)
sessions = [backorder.saleSession].compact
json = DfcIo.export(backorder, *lines, *offers, *products, *sessions)
api = DfcRequest.new(user)
method = if new?(backorder)
:post # -> create
else
:put # -> update
end
result = api.call(backorder.semanticId, json, method:)
find_subject(DfcIo.import(result), "dfc-b:Order")
end
def complete_order(backorder)
backorder.orderStatus = "dfc-v:Complete"
send_order(backorder)
end
def new?(order)
order.semanticId == urls.orders_url
end
def build_sale_session(order)
SaleSessionBuilder.build(order.order_cycle).tap do |session|
session.semanticId = urls.sale_session_url
end
end
end

View File

@@ -0,0 +1,89 @@
# frozen_string_literal: true
# Finds wholesale offers for retail products.
class FdcOfferBroker
# TODO: Find a better way to provide this data.
Solution = Struct.new(:product, :factor, :offer)
RetailSolution = Struct.new(:retail_product_id, :factor)
def self.load_catalog(user, urls)
api = DfcRequest.new(user)
catalog_json = api.call(urls.catalog_url)
DfcIo.import(catalog_json)
end
def initialize(user, urls)
@user = user
@urls = urls
end
def catalog
@catalog ||= self.class.load_catalog(@user, @urls)
end
def best_offer(product_id)
Solution.new(
wholesale_product(product_id),
contained_quantity(product_id),
offer_of(wholesale_product(product_id))
)
end
def wholesale_product(product_id)
production_flow = catalog_item("#{product_id}/AsPlannedProductionFlow")
if production_flow
wholesale_product_id = production_flow.product
catalog_item(wholesale_product_id)
else
# We didn't find a wholesale variant, falling back to the given product.
catalog_item(product_id)
end
end
def contained_quantity(product_id)
consumption_flow = catalog_item("#{product_id}/AsPlannedConsumptionFlow")
# If we don't find a transformation, we return the original product,
# which contains exactly one of itself (identity).
consumption_flow&.quantity&.value&.to_i || 1
end
def wholesale_to_retail(wholesale_product_id)
production_flow = flow_producing(wholesale_product_id)
return RetailSolution.new(wholesale_product_id, 1) if production_flow.nil?
consumption_flow = catalog_item(
production_flow.semanticId.sub("AsPlannedProductionFlow", "AsPlannedConsumptionFlow")
)
retail_product_id = consumption_flow.product
contained_quantity = consumption_flow.quantity.value.to_i
RetailSolution.new(retail_product_id, contained_quantity)
end
def offer_of(product)
product&.catalogItems&.first&.offers&.first&.tap do |offer|
# Unfortunately, the imported catalog doesn't provide the reverse link:
offer.offeredItem = product
end
end
def catalog_item(id)
@catalog_by_id ||= catalog.index_by(&:semanticId)
@catalog_by_id[id]
end
def flow_producing(wholesale_product_id)
@production_flows_by_product_id ||= production_flows.index_by(&:product)
@production_flows_by_product_id[wholesale_product_id]
end
def production_flows
@production_flows ||= catalog.select do |i|
i.semanticType == "dfc-b:AsPlannedProductionFlow"
end
end
end

View File

@@ -0,0 +1,16 @@
# frozen_string_literal: true
# The DFC standard doesn't include endpoint discovery yet.
# So for now we are guessing URLs based on our FDC pilot project.
class FdcUrlBuilder
attr_reader :catalog_url, :orders_url, :sale_session_url
# At the moment, we start with a product link like this:
#
# https://env-0105831.jcloud-ver-jpe.ik-server.com/api/dfc/Enterprises/test-hodmedod/SuppliedProducts/44519466467635
def initialize(semantic_id)
@catalog_url, _slash, _id = semantic_id.rpartition("/")
@orders_url = @catalog_url.sub("/SuppliedProducts", "/Orders")
@sale_session_url = @catalog_url.sub("/SuppliedProducts", "/SalesSession/#")
end
end

View File

@@ -18,4 +18,16 @@ class HtmlSanitizer
html, tags: ALLOWED_TAGS, attributes: (ALLOWED_ATTRIBUTES + ALLOWED_TRIX_DATA_ATTRIBUTES)
)
end
def self.sanitize_and_enforce_link_target_blank(html)
sanitize(enforce_link_target_blank(html))
end
def self.enforce_link_target_blank(html)
return if html.nil?
Nokogiri::HTML::DocumentFragment.parse(html).tap do |document|
document.css("a").each { |link| link["target"] = "_blank" }
end.to_s
end
end

View File

@@ -7,6 +7,8 @@ module OrderCycles
class FormService
def initialize(order_cycle, order_cycle_params, user)
@order_cycle = order_cycle
@confirm_datetime_change = order_cycle_params.delete :confirm_datetime_change
@error_class = order_cycle_params.delete :error_class
@order_cycle_params = order_cycle_params
@specified_params = order_cycle_params.keys
@user = user
@@ -21,6 +23,9 @@ module OrderCycles
end
def save
# Check that order cycle datetime values changed if it has existing orders
verify_datetime_change!
schedule_ids = build_schedule_ids
order_cycle.assign_attributes(order_cycle_params)
return false unless order_cycle.valid?
@@ -229,5 +234,16 @@ module OrderCycles
DistributorShippingMethod.where(distributor_id: user_distributors_ids)
.pluck(:id)
end
def verify_datetime_change!
return unless @confirm_datetime_change
return unless @order_cycle.orders.exists?
return if @order_cycle.same_datetime_value(:orders_open_at,
@order_cycle_params[:orders_open_at]) &&
@order_cycle.same_datetime_value(:orders_close_at,
@order_cycle_params[:orders_close_at])
raise @error_class
end
end
end

View File

@@ -0,0 +1,33 @@
# frozen_string_literal: true
# Locks an order including its variants.
#
# It should be used when making major changes like checking out the order.
# It can keep stock checking in sync and prevent overselling of an item.
class OrderLocker
# Locking will not prevent all access to these rows. Other processes are
# only waiting if they try to lock one of these rows as well.
#
# https://api.rubyonrails.org/classes/ActiveRecord/Locking/Pessimistic.html
#
def self.lock_order_and_variants(order)
return yield if order.nil?
order.with_lock do
lock_variants_of(order)
yield
end
end
# There are many places in which stock is stored in the database. Row locking
# on variant level ensures that there are no conflicts even when an item is
# sold through multiple shops.
def self.lock_variants_of(order)
variant_ids = order.line_items.select(:variant_id)
# Ordering the variants by id prevents deadlocks. Plucking the ids sends
# the locking query without building Spree::Variant objects.
Spree::Variant.where(id: variant_ids).order(:id).lock.pluck(:id)
end
private_class_method :lock_variants_of
end

View File

@@ -9,7 +9,7 @@ module PermittedAttributes
:unit_description, :variant_unit_name,
:display_as, :sku, :group_buy, :group_buy_unit_size,
:taxon_ids, :primary_taxon_id, :tax_category_id, :supplier_id,
:meta_keywords, :notes, :inherits_properties,
:meta_keywords, :notes, :inherits_properties, :shipping_category_id,
{ product_properties_attributes: [:id, :property_name, :value],
variants_attributes: [PermittedAttributes::Variant.attributes],
image_attributes: [:attachment] }

View File

@@ -3,7 +3,31 @@
module Sets
class OrderCycleSet < ModelSet
def initialize(collection, attributes = {})
@confirm_datetime_change = attributes.delete :confirm_datetime_change
@error_class = attributes.delete :error_class
super(OrderCycle, collection, attributes)
end
def process(order_cycle, attributes)
if @confirm_datetime_change &&
order_cycle.orders.exists? &&
datetime_value_changed(order_cycle, attributes)
raise @error_class
end
super
end
private
def datetime_value_changed(order_cycle, attributes)
# return true if either key is present in params and change in values detected
return true if attributes.key?(:orders_open_at) &&
!order_cycle.same_datetime_value(:orders_open_at, attributes[:orders_open_at])
attributes.key?(:orders_close_at) &&
!order_cycle.same_datetime_value(:orders_close_at, attributes[:orders_close_at])
end
end
end

View File

@@ -1,12 +1,17 @@
# frozen_string_literal: true
class ShopsListService
# shops that are ready for checkout, and have an order cycle that is currently open
def open_shops
shops_list.ready_for_checkout.all
shops_list.
ready_for_checkout.
distributors_with_active_order_cycles
end
# shops that are either not ready for checkout, or don't have an open order cycle; the inverse of
# #open_shops
def closed_shops
shops_list.not_ready_for_checkout.all
shops_list.where.not(id: open_shops.reselect("enterprises.id"))
end
private

View File

@@ -26,9 +26,15 @@ class WeightsAndMeasures
def self.variant_unit_options
available_units_sorted.flat_map do |measurement, measurement_info|
measurement_info.filter_map do |scale, unit_info|
# Our code is based upon English based number formatting
# Some language locales like +hu+ uses a comma(,) for decimal separator
# While in English, decimal separator is represented by a period.
# e.g. en: 0.001, hu: 0,001
# Hence the results become "weight_0,001" for hu while or code recognizes "weight_0.001"
scale_clean =
ActiveSupport::NumberHelper.number_to_rounded(scale, precision: nil, significant: false,
strip_insignificant_zeros: true)
strip_insignificant_zeros: true,
locale: :en)
[
"#{I18n.t(measurement)} (#{unit_info['name']})", # Label (eg "Weight (g)")
"#{measurement}_#{scale_clean}", # Scale ID (eg "weight_1")

View File

@@ -1,6 +1,5 @@
%fieldset.alpha.no-border-bottom#about_panel{ data: { "tabs-and-panels-target": "panel" } }
%legend= t('.about')
= f.field_container :long_description do
%text-angular{'id' => 'enterprise_group_long_description', 'name' => 'enterprise_group[long_description]', 'class' => 'text-angular', "textangular-links-target-blank" => true,
'ta-toolbar' => "[['h1','h2','h3','h4','p'],['bold','italics','underline','clear'],['insertLink']]"}
!= @enterprise_group[:long_description]
= f.hidden_field :long_description, id: "enterprise_group_long_description"
%trix-editor{ input: "enterprise_group_long_description", "data-controller": "trixeditor" }

View File

@@ -4,14 +4,7 @@
.omega.eight.columns
= f.text_field :description, maxlength: 255, placeholder: t('.desc_short_placeholder')
.row
.alpha.three.columns
.alpha.eleven.columns
= f.label :long_description, t('.desc_long')
.omega.eight.columns
-# textAngular toolbar options, add to the ta-toolbar array below and separate into groups with extra ],[ if needed:
-# ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'pre', 'quote'],
-# ['bold', 'italics', 'underline', 'strikeThrough', 'ul', 'ol', 'redo', 'undo', 'clear'],
-# ['justifyLeft','justifyCenter','justifyRight','indent','outdent'],
-# ['html', 'insertImage', 'insertLink', 'insertVideo']
%text-angular{'ng-model' => 'Enterprise.long_description', 'id' => 'enterprise_long_description', 'name' => 'enterprise[long_description]', 'class' => 'text-angular', "textangular-links-target-blank" => true,
'ta-toolbar' => "[['h1','h2','h3','h4','p'],['bold','italics','underline','clear'],['insertLink']]",
'placeholder' => t('.desc_long_placeholder')}
= f.hidden_field :long_description, id: "enterprise_long_description"
%trix-editor{ input: "enterprise_long_description", "data-controller": "trixeditor" }

View File

@@ -1,17 +1,13 @@
.row
.three.columns.alpha
.eleven.columns.alpha
= f.label "enterprise_preferred_shopfront_message", t('.shopfront_message')
.eight.columns.omega
%text-angular{'ng-model' => 'Enterprise.preferred_shopfront_message', 'id' => 'enterprise_preferred_shopfront_message', 'name' => 'enterprise[preferred_shopfront_message]', 'class' => 'text-angular textangular-strip', 'ta-paste' => "stripFormatting($html)", "textangular-links-target-blank" => true,
'ta-toolbar' => "[['h1','h2','h3','h4','p'],['bold','italics','underline','clear'],['insertLink']]",
'placeholder' => t('.shopfront_message_placeholder')}
= f.hidden_field :preferred_shopfront_message, id: "enterprise_preferred_shopfront_message"
%trix-editor{ input: "enterprise_preferred_shopfront_message", "data-controller": "trixeditor", placeholder: t('.shopfront_message_placeholder') }
.row
.three.columns.alpha
.eleven.columns.alpha
= f.label "enterprise_preferred_shopfront_closed_message", t('.shopfront_closed_message')
.eight.columns.omega
%text-angular{'ng-model' => 'Enterprise.preferred_shopfront_closed_message', 'id' => 'enterprise_preferred_shopfront_closed_message', 'name' => 'enterprise[preferred_shopfront_closed_message]', 'class' => 'text-angular textangular-strip', 'ta-paste' => "stripFormatting($html)", "textangular-links-target-blank" => true,
'ta-toolbar' => "[['h1','h2','h3','h4','p'],['bold','italics','underline','clear'],['insertLink']]",
'placeholder' => t('.shopfront_closed_message_placeholder')}
= f.hidden_field :preferred_shopfront_closed_message, id: "enterprise_preferred_shopfront_closed_message"
%trix-editor{ input: "enterprise_preferred_shopfront_closed_message", "data-controller": "trixeditor", placeholder: t('.shopfront_closed_message_placeholder') }
.row
.text-normal
@@ -77,7 +73,7 @@
= f.radio_button :preferred_product_low_stock_display, true, 'ng-model' => 'Enterprise.preferred_product_low_stock_display', 'ng-value' => 'true'
= f.label :preferred_product_low_stock_display, t('.enabled'), value: :true
.five.columns.omega
= f.radio_button :preferred_product_low_stock_display, false, 'ng-model' => 'Enterprise.preferred_product_low_stock_display', 'ng-value' => 'false'
= f.radio_button :preferred_product_low_stock_display, false, 'ng-model' => 'Enterprise.preferred_product_low_stock_display', 'ng-value' => 'false'
= f.label :preferred_product_low_stock_display, t('.disabled'), value: :false
.row

View File

@@ -4,11 +4,16 @@
%div{ style: 'font-size: 1rem;' }
= t('.content')
%p.modal-actions.justify-end.gap-1
%button.button.secondary{ "ng-click": "submit($event, null)", type: "button", style: "display: none;", data: { action: 'click->modal#close', 'trigger-action': 'save' } }
= t('.proceed')
%button.button.secondary{ "ng-click": "submit($event, '#{main_app.admin_order_cycle_incoming_path(@order_cycle)}')", type: "button", style: "display: none;", data: { action: 'click->modal#close', 'trigger-action': 'saveAndNext' } }
= t('.proceed')
%button.button.secondary{ "ng-click": "submit($event, '#{main_app.admin_order_cycles_path}')", type: "button", style: "display: none;", data: { action: 'click->modal#close', 'trigger-action': 'saveAndBack' } }
= t('.proceed')
%button.button.primary{ type: "button", 'data-action': 'click->modal#close' }
= t('.cancel')
- if action == 'simple_update'
%button.button.secondary{ "ng-click": "submit($event, null)", type: "button", style: "display: none;", data: { action: 'click->modal#close', 'trigger-action': 'save' } }
= t('.proceed')
%button.button.secondary{ "ng-click": "submit($event, '#{main_app.admin_order_cycle_incoming_path(@order_cycle)}')", type: "button", style: "display: none;", data: { action: 'click->modal#close', 'trigger-action': 'saveAndNext' } }
= t('.proceed')
%button.button.secondary{ "ng-click": "submit($event, '#{main_app.admin_order_cycles_path}')", type: "button", style: "display: none;", data: { action: 'click->modal#close', 'trigger-action': 'saveAndBack' } }
= t('.proceed')
= link_to t('.cancel'), admin_order_cycles_path, id: 'cancel', class: 'button primary', data: { 'order-cycle-form-target': 'cancel' }
- if action == 'bulk_update'
%button.button.secondary{ "ng-click": "saveAll($event)", type: "button", style: "display: none;", data: { action: 'click->modal#close', trigger_action: 'bulk_save' } }
= t('.proceed')
%button.button.primary{ type: "button", 'data-action': 'click->modal#close' }
= t('.cancel')

View File

@@ -37,4 +37,4 @@
%button.modal-target-trigger{ type: 'button', data: { 'action': 'modal-link#open' }, style: 'display: none;' }
= render ModalComponent.new(id: "linked-order-warning-modal", close_button: false) do
.content.flex-column.gap-2
= render 'date_time_warning_modal_content'
= render 'date_time_warning_modal_content', action: 'simple_update'

View File

@@ -23,12 +23,20 @@
.thirteen.columns.alpha &nbsp;
%columns-dropdown{ action: "#{controller_name}_#{action_name}" }
%form{ name: 'order_cycles_form' }
%save-bar{ dirty: "order_cycles_form.$dirty", persist: "false" }
%input.red{ type: "button", value: t(:save_changes), "ng-click": "saveAll()", "ng-disabled": "!order_cycles_form.$dirty" }
%table.index#listing_order_cycles{ "ng-show": 'orderCycles.length > 0' }
= render 'admin/order_cycles/header' #, simple_index: simple_index
%tbody
= render 'admin/order_cycles/row' #, simple_index: simple_index
= render 'admin/order_cycles/loading_flash'
= render 'admin/order_cycles/show_more'
%div{ data: { controller: 'order-cycle-form' } }
%form{ name: 'order_cycles_form' }
%save-bar{ dirty: "order_cycles_form.$dirty", persist: "false" }
%input.red{ type: "button", value: t(:save_changes), "ng-click": "saveAll($event)", "ng-disabled": "!order_cycles_form.$dirty",
data: { confirm: "true", 'trigger-action': 'bulk_save' } }
%table.index#listing_order_cycles{ "ng-show": 'orderCycles.length > 0' }
= render 'admin/order_cycles/header' #, simple_index: simple_index
%tbody
= render 'admin/order_cycles/row' #, simple_index: simple_index
= render 'admin/order_cycles/loading_flash'
= render 'admin/order_cycles/show_more'
%div.warning-modal{ data: { controller: 'modal modal-link', 'modal-link-target-value': "linked-order-warning-modal" } }
%button.modal-target-trigger{ type: 'button', data: { 'action': 'modal-link#open' }, style: 'display: none;' }
= render ModalComponent.new(id: "linked-order-warning-modal", close_button: false) do
.content.flex-column.gap-2
= render 'date_time_warning_modal_content', action: 'bulk_update'

View File

@@ -25,7 +25,7 @@
-# empty
%td.col-on_hand.align-right
-# empty
%td.col-on_hand.align-right
%td.col-producer.align-right
-# empty
%td.col-category.align-left
-# empty
@@ -40,3 +40,4 @@
"data-modal-link-target-value": "product-delete-modal", "class": "delete",
"data-modal-link-modal-dataset-value": {'data-delete-path': admin_product_destroy_path(product)}.to_json }
= t('admin.products_page.actions.delete')
= link_to t('admin.products_page.actions.preview'), admin_product_preview_path(product), {"data-turbo-stream": "" }

View File

@@ -11,7 +11,7 @@
%tr.condensed{ id: dom_id(variant), 'data-controller': "variant", 'class': "nested-form-wrapper", 'data-new-record': variant.new_record? ? "true" : false }
= render partial: 'variant_row', locals: { variant:, f: variant_form, category_options:, tax_category_options:, producer_options: }
= form.fields_for("products][#{product_index}][variants_attributes][NEW_RECORD", prepare_new_variant(product)) do |new_variant_form|
= form.fields_for("products][#{product_index}][variants_attributes][NEW_RECORD", prepare_new_variant(product, producer_options)) do |new_variant_form|
%template{ 'data-nested-form-target': "template" }
%tr.condensed{ 'data-controller': "variant", 'class': "nested-form-wrapper", 'data-new-record': "true" }
= render partial: 'variant_row', locals: { variant: new_variant_form.object, f: new_variant_form, category_options:, tax_category_options:, producer_options: }

View File

@@ -1,7 +1,7 @@
#sort
%div.pagination-description
- if pagy.present?
= t(".pagination.total_html", total: pagy.count, from: pagy.from, to: pagy.to)
= t(".pagination.products_total_html", count: pagy.count, from: pagy.from, to: pagy.to)
- if search_term.present? || producer_id.present? || category_id.present?
%a{ href: url_for(page: 1), class: "button disruptive", data: { 'turbo-frame': "_self", 'turbo-action': "advance" } }

View File

@@ -13,16 +13,16 @@
= hidden_field_tag :producer_id, @producer_id
= hidden_field_tag :category_id, @category_id
%table.products{ 'data-column-preferences-target': "table" }
%table.products{ 'data-column-preferences-target': "table", class: (hide_producer_column?(producer_options) ? 'hide-producer' : '') }
%colgroup
-# The `min-width` property works in Chrome but not Firefox so is considered progressive enhancement.
%col.col-image{ width:"56px" }= # (image size + padding)
%col.col-image{ width:"44px" }= # (image size + padding)
%col.col-name{ style:"min-width: 6em" }= # (grow to fill)
%col.col-sku{ width:"8%", style:"min-width: 6em" }
%col.col-unit_scale{ width:"8%" }
%col.col-unit{ width:"8%" }
%col.col-price{ width:"5%", style:"min-width: 5em" }
%col.col-on_hand{ width:"10%"}
%col.col-price{ width:"10%", style:"min-width: 5em" }
%col.col-on_hand{ width:"8%" }
%col.col-producer{ style:"min-width: 6em" }= # (grow to fill)
%col.col-category{ width:"8%" }
%col.col-tax_category{ width:"8%" }

View File

@@ -20,3 +20,4 @@
= render partial: 'delete_modal', locals: { object_type: }
#modal-component
#edit_image_modal
#product-preview-modal-container

View File

@@ -0,0 +1,119 @@
= turbo_stream.update "product-preview-modal-container" do
= render ModalComponent.new(id: "product-preview-modal", instant: true, modal_class: "big") do
#product-preview{ "data-controller": "tabs" }
%h1
= t("admin.products_page.product_preview.product_preview")
%dl.admin-tabs
%dd
%a{ data: { "tabs-target": "tab", "action": "tabs#select" } }
= t("admin.products_page.product_preview.shop_tab")
%dd
%a{ data: { "tabs-target": "tab", "action": "tabs#select" } }
= t("admin.products_page.product_preview.product_details_tab")
.tabs-content
.content.active
%div{ data: { "tabs-target": "content" } }
.product-thumb
%a
- if @product.group_buy
%span.product-thumb__bulk-label
= t(".bulk")
= image_tag @product.image&.url(:small) || Spree::Image.default_image_url(:small)
.summary
.summary-header
%h3
%a
%span
= @product.name
- if @product.description
.product-description{ "data-controller": "add-blank-to-link" }
- # description is sanitized in Spree::Product#description method
= @product.description.html_safe
- if @product.variants.first.supplier.visible
%div
.product-producer
= t :products_from
%span
%a
= @product.variants.first.supplier.name
.product-properties.filter-shopfront.property-selectors
.filter-shopfront.property-selectors.inline-block
%ul
- @product.properties_including_inherited.each do |property|
%li
- if property[:value].present?
= render AdminTooltipComponent.new(text: property[:value], link_text: property[:name], placement: "bottom")
- else
%a
%span
= property[:name]
.shop-variants
- @product.variants.sort { |v1, v2| v1.name_to_display <=> v2.name_to_display }.sort { |v1, v2| v1.unit_value <=> v2.unit_value }.each do |variant|
.variants.row
.small-3.columns.variant-name
- if variant.display_name.present?
.inline
= variant.display_name
.variant-unit
= variant.unit_to_display
.small-4.medium-3.columns.variant-price
= number_to_currency(variant.price)
.unit-price.variant-unit-price
= render AdminTooltipComponent.new(text: t("js.shopfront.unit_price_tooltip"), link_text: "", placement: "top", link_class: "question-mark-icon")
- # TODO use an helper
- unit_price = UnitPrice.new(variant)
- price_per_unit = variant.price / (unit_price.denominator || 1)
= "#{number_to_currency(price_per_unit)}&nbsp;/&nbsp;#{unit_price.unit}".html_safe
.medium-3.columns.total-price
%span
= number_to_currency(0.00)
.small-5.medium-3.large-3.columns.variant-quantity-column.text-right
.variant-quantity-inputs
%button.add-variant
= t("js.shopfront.variant.add_to_cart")
- # TODO can't check the shop preferrence here, display by default ?
- if !variant.on_demand && variant.on_hand <= 3
.variant-remaining-stock
= t("js.shopfront.variant.remaining_in_stock", quantity: variant.on_hand)
%div{ data: { "tabs-target": "content" } }
.row
.columns.small-12.medium-6.large-6.product-header
%h3
= @product.name
%span
%em
= t("products_from")
%span
= @product.variants.first.supplier.name
%br
.filter-shopfront.property-selectors.inline-block
%ul
- @product.properties_including_inherited.each do |property|
%li
- if property[:value].present?
= render AdminTooltipComponent.new(text: property[:value], link_text: property[:name], placement: "bottom")
- else
%a
%span
= property[:name]
- if @product.description
.product-description{ 'data-controller': "add-blank-to-link" }
%p.text-small
- # description is sanitized in Spree::Product#description method
= @product.description.html_safe
.columns.small-12.medium-6.large-6.product-img
- if @product.image
%img{ src: @product.image.url(:large) }
-else
%img.placeholder{ src: Spree::Image.default_image_url(:large) }

View File

@@ -0,0 +1,47 @@
.download.hidden
= link_to t("admin.reports.download.button"), file_url, target: "_blank", class: "button icon icon-file"
:javascript
(function () {
const tryDownload = function() {
const link = document.querySelector(".download a");
// If the report was already rendered via web sockets:
if (link == null) return;
fetch(link.href).then((response) => {
if (response.ok) {
response.blob().then((blob) => blob.text()).then((text) => {
const loading = document.querySelector(".loading");
if (loading == null) return;
loading.remove();
document.querySelector("#report-go button").disabled = false;
if (link.href.endsWith(".html")) {
// This replaces the hidden download button with the report:
link.parentElement.outerHTML = text;
} else {
// Or just show the download button when it's ready:
document.querySelector(".download").classList.remove("hidden")
}
});
} else {
setTimeout(tryDownload, 2000);
}
});
}
/*
A lot of reports are rendered within 250ms. Others take at least
2.5 seconds. There's a big gap in between. Observed on:
https://openfoodnetwork.org.au/admin/sidekiq/metrics/ReportJob?period=8h
https://openfoodnetwork.org.uk/admin/sidekiq/metrics/ReportJob?period=8h
https://coopcircuits.fr/admin/sidekiq/metrics/ReportJob?period=8h
But let's leave the timed response to websockets for now and just poll
as a backup mechanism.
*/
setTimeout(tryDownload, 3000);
})();

View File

@@ -0,0 +1,6 @@
= turbo_stream.update "report-go" do
= button t(:go), "report__submit-btn", "submit", disabled: true
= turbo_stream.update "report-table" do
= render "admin/reports/loading"
= render "admin/reports/fallback_display", file_url: @blob.expiring_service_url
= turbo_stream.scroll_into_view("#report-table", behavior: "smooth")

View File

@@ -3,7 +3,7 @@
- content_for :minimal_js, true
= form_for @report.search, { url: url_for, data: { remote: "true" } } do |f|
= form_for @report.search, { url: url_for, data: { turbo: "true" } } do |f|
= hidden_field_tag "uuid", request.uuid
%fieldset.no-border-bottom.print-hidden

View File

@@ -1,7 +0,0 @@
%div{"data-controller": "tooltip"}
%a{"data-tooltip-target": "element", href: link, class: link_class}
= link_text
.tooltip-container
.tooltip{"data-tooltip-target": "tooltip"}
= sanitize tooltip_text
.arrow{"data-tooltip-target": "arrow"}

View File

@@ -1 +1 @@
= render partial: 'admin/shared/tooltip', locals: {link_class: "" ,link: nil, link_text: t('admin.whats_this'), tooltip_text: tooltip_text}
= render AdminTooltipComponent.new(text: tooltip_text, link_text: t('admin.whats_this'), link: nil)

View File

@@ -0,0 +1,16 @@
%h1= t ".headline"
%p= t ".description"
%p= t ".hints"
%p= t ".order", number: @order.number
%table
%tr
%th= t ".stock"
%th= t ".product"
- @linked_variants.each do |variant|
%tr
%td= variant.on_hand
%td= variant.product_and_full_name

View File

@@ -0,0 +1,9 @@
%h1= t ".headline"
%p= t ".description"
%p= t ".hints"
%p= t ".affected", enterprise: @distributor.name, order_cycle: @order_cycle.name
%pre= @order_id

View File

@@ -1,10 +1,10 @@
= form_with url: checkout_update_path(checkout_step), model: @order, method: :put, data: { remote: "true" } do |f|
= form_with url: checkout_update_path(checkout_step), model: @order, method: :put, data: { remote: "true", 'guest-checkout-target': 'summary' } do |f|
.summary-main
= render partial: "checkout/already_ordered" if show_bought_items? && checkout_step?(:summary)
.checkout-substep
.checkout-title
= t("checkout.step3.delivery_details.title")
%a.summary-edit{href: main_app.checkout_step_path(:details)}
%a.summary-edit{ href: main_app.checkout_step_path(:details), data: { action: "guest-checkout#removeUnloadEvent" } }
= t("checkout.step3.delivery_details.edit")
.summary-subtitle
@@ -51,7 +51,7 @@
.checkout-substep
.checkout-title
= t("checkout.step3.payment_method.title")
%a.summary-edit{href: main_app.checkout_step_path(:payment)}
%a.summary-edit{ href: main_app.checkout_step_path(:payment), data: { action: "guest-checkout#removeUnloadEvent" } }
= t("checkout.step3.payment_method.edit")
.two-columns
- payment_method = last_payment_method(@order)
@@ -74,7 +74,7 @@
%div.checkout-substep
%div.checkout-title
= t("checkout.step3.order.title")
%a.summary-edit{href: main_app.cart_path}
%a.summary-edit{ href: main_app.cart_path, data: { action: "guest-checkout#removeUnloadEvent" } }
= t("checkout.step3.order.edit")
= render 'spree/orders/summary', order: @order, display_footer: false
@@ -108,4 +108,4 @@
.checkout-submit
- if any_terms_required?(@order.distributor)
= render partial: "terms_and_conditions", locals: { f: f }
= f.submit t("checkout.step3.submit"), name: "confirm_order", class: "button primary", disabled: @terms_and_conditions_accepted == false || @platform_tos_accepted == false
= f.submit t("checkout.step3.submit"), name: "confirm_order", class: "button primary", disabled: @terms_and_conditions_accepted == false || @platform_tos_accepted == false, data: { action: "click -> guest-checkout#removeUnloadEvent" }

View File

@@ -5,7 +5,7 @@
%meta{:content => "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/
%title
= Spree::Config[:site_name]
= stylesheet_pack_tag 'mail'
= stylesheet_link_tag 'mail'
%body{:bgcolor => "#FFFFFF" }
- unless @hide_ofn_navigation
%table.head-wrap{:bgcolor => "#f2f2f2"}

View File

@@ -1,3 +1,4 @@
- # NOTE: make sure that any changes in this template are reflected in app/views/admin/products_v3/product_preview.turbo_stream.haml
= cache_with_locale do
%form{action: main_app.cart_path}
%products{"ng-init" => "refreshStaleData()", "ng-show" => "order_cycle.order_cycle_id != null", "ng-cloak" => true }

View File

@@ -1,8 +1,9 @@
- # NOTE: make sure that any changes in this template are reflected in app/views/admin/products_v3/product_preview.turbo_stream.haml
= cache_with_locale do
.small-4.medium-4.large-5.columns.variant-name
.small-3.columns.variant-name
.inline{"ng-if" => "::variant.display_name"} {{ ::variant.display_name }}
.variant-unit {{ ::variant.unit_to_display }}
.small-3.medium-3.large-2.columns.variant-price
.small-4.medium-3.columns.variant-price
%price-breakdown{"price-breakdown" => "_", variant: "variant",
"price-breakdown-append-to-body" => "true",
"price-breakdown-placement" => "bottom",
@@ -16,7 +17,7 @@
key: "'js.shopfront.unit_price_tooltip'"}
{{ variant.unit_price_price | localizeCurrency }}&nbsp;/&nbsp;{{ variant.unit_price_unit }}
.medium-2.large-2.columns.total-price
.medium-3.columns.total-price
%span{"ng-class" => "{filled: variant.line_item.total_price}"}
{{ variant.line_item.total_price | localizeCurrency }}
= render partial: "shop/products/shop_variant_no_group_buy"

View File

@@ -1,3 +1,4 @@
- # NOTE: make sure that any changes in this template are reflected in app/views/admin/products_v3/product_preview.turbo_stream.haml
= cache_with_locale do
.small-5.medium-3.large-3.columns.variant-quantity-column.text-right{"ng-if" => "::!variant.product.group_buy"}

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