@spree/docs 0.1.228 → 0.1.229
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -35,6 +35,7 @@ A query names what to measure and how to slice it. This is the whole surface:
|
|
|
35
35
|
"filters": [{ "dimension": "channel", "op": "eq", "value": "ch_86Rf07xd4z" }],
|
|
36
36
|
"time_range": { "preset": "last_4_weeks" },
|
|
37
37
|
"compare": "previous_period",
|
|
38
|
+
"currency": "EUR",
|
|
38
39
|
"sort": "-total_sales",
|
|
39
40
|
"limit": 50
|
|
40
41
|
}
|
|
@@ -47,6 +48,7 @@ A query names what to measure and how to slice it. This is the whole surface:
|
|
|
47
48
|
| `filters` | `eq` or `in` against a dimension. Values are prefixed IDs where the dimension identifies a record. |
|
|
48
49
|
| `time_range` | A named preset, or `since`/`until` as ISO 8601. A bare date covers the store's whole day. |
|
|
49
50
|
| `compare` | `previous_period` adds `previous` and `growth` to every metric. |
|
|
51
|
+
| `currency` | ISO 4217 code, e.g. `"EUR"`. Defaults to the store's own. Applies only to a query containing money — see [Metrics](#metrics). The values a store accepts are in the schema's `supported_currencies`. |
|
|
50
52
|
| `sort` / `limit` | Ranking controls; ignored for time series, which are always chronological and complete. |
|
|
51
53
|
|
|
52
54
|
Unknown members are rejected, never dropped. A malformed query answers 422,
|
|
@@ -88,12 +90,20 @@ Spree.reporting.metric :total_sales,
|
|
|
88
90
|
a `:percent` metric arrives as the number a merchant reads (`42.5`), not the
|
|
89
91
|
fraction.
|
|
90
92
|
|
|
91
|
-
Amounts are **never converted**. A query answers in one
|
|
92
|
-
it names, or the store's default — and every base a money
|
|
93
|
-
|
|
94
|
-
store selling in several therefore has as many answers as it
|
|
95
|
-
currencies, which is why the home screen offers a currency alongside its
|
|
93
|
+
Amounts are **never converted**. A query containing money answers in one
|
|
94
|
+
currency — the one it names, or the store's default — and every base a money
|
|
95
|
+
metric reads filters by it, or two currencies end up added together under one
|
|
96
|
+
symbol. A store selling in several therefore has as many money answers as it
|
|
97
|
+
has currencies, which is why the home screen offers a currency alongside its
|
|
96
98
|
channel and date range.
|
|
99
|
+
|
|
100
|
+
**A query with no money in it is not scoped to a currency at all.** Counts
|
|
101
|
+
and quantities — orders, customers, units sold, payments taken — are not
|
|
102
|
+
amounts, so narrowing them would answer "how many orders did we take" with
|
|
103
|
+
only the share that happened to be priced in one currency. Ask for `orders`
|
|
104
|
+
alone and you get every order; ask for `orders` beside `total_sales` and the
|
|
105
|
+
whole query narrows, because the money figure has to. A ratio counts as
|
|
106
|
+
money when either side is: average order value does, sell-through does not.
|
|
97
107
|
- `ratio: [:numerator, :denominator]` defines a **derived** metric, computed
|
|
98
108
|
after aggregation so it is correct for both rows and totals. Average order
|
|
99
109
|
value is `ratio: %i[total_sales orders]`, never `AVG()`.
|
|
@@ -198,6 +198,18 @@ These are limits of the compiler, not of registration:
|
|
|
198
198
|
Registering a base is otherwise ordinary: declare its family, its table, a
|
|
199
199
|
store-scoped relation, its time column and which bases its dimensions reach.
|
|
200
200
|
|
|
201
|
+
The relation's `currency` argument **is nil when the query contains no money
|
|
202
|
+
metric**, and a base must then not filter by it — a count restricted to one
|
|
203
|
+
currency is a wrong answer, not a narrower one. Guard the filter rather than
|
|
204
|
+
passing nil into `where`, which would match nothing:
|
|
205
|
+
|
|
206
|
+
```ruby
|
|
207
|
+
relation: lambda { |store, range, currency|
|
|
208
|
+
scope = store.subscriptions.where(created_at: range)
|
|
209
|
+
currency ? scope.where(currency: currency) : scope
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
201
213
|
```ruby
|
|
202
214
|
Spree.reporting.base :subscriptions, family: :subscriptions,
|
|
203
215
|
table: '%{subscriptions}',
|