Skip to content

Commit 1ec9d9c

Browse files
Merge pull request #30 from marielestavel/stock_entries_new_model
Introduce `viz_operations__stock_entries_sources` and delete existing models
2 parents d29e2df + dd92c20 commit 1ec9d9c

File tree

5 files changed

+55
-95
lines changed

5 files changed

+55
-95
lines changed

dbt-models/models/schema.yml

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,15 @@ models:
123123
- name: lifetime_visit_count
124124
description: The total number of visits of the member's family since they first visited
125125

126-
- name: viz_operations__stock_entries_collection_dates
127-
description: Model containing stock entries by product on collection days
126+
- name: viz_operations__stock_entries_sources
127+
description: Model containing stock entries metrics by sources at the product-level.
128128
columns:
129129
- name: date_at
130130
description: The date when the operation occurred
131+
- name: source
132+
description: >
133+
The acquisition channel for this operation.
134+
Either 'Pleins Courses', 'Collectes Supermarché' or 'Enlèvements BAPIF'
131135
- name: product_name
132136
description: The name of the product
133137
- name: unit_of_measure
@@ -149,30 +153,3 @@ models:
149153
description: >
150154
The corresponding monetary value in euro of the products brought into stock
151155
calculated based on the average price of a product unit.
152-
153-
- name: viz_operations__stock_entries_shopping_dates
154-
description: Model containing stock entries by product on grocery shopping days
155-
columns:
156-
- name: date_at
157-
description: The date when the operation occurred
158-
- name: product_name
159-
description: The name of the product
160-
- name: unit_of_measure
161-
description: >
162-
Unit of measure for a given product
163-
eg: 'Paquet' for 'Biscuits'
164-
- name: units_per_batch
165-
description: Number of product units given per batch
166-
- name: date_latest_shopping
167-
description: The date of the lastest grocery shopping
168-
- name: unit_entries
169-
description: The quantity of product units entered in stock
170-
- name: batch_quantity
171-
description: >
172-
The corresponding quantity of product units in product batch.
173-
Eg: If diapers are given in batches of 10 to families,
174-
then 10 unit entries correspond to 1 product batch stock entry.
175-
- name: monetary_value_eur
176-
description: >
177-
The corresponding monetary value in euro of the products brought into stock
178-
calculated based on the average price of a product unit.

dbt-models/models/viz_operations__stock_entries_collection_dates.sql

Lines changed: 0 additions & 33 deletions
This file was deleted.

dbt-models/models/viz_operations__stock_entries_shopping_dates.sql

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
with product_operations as (
2+
3+
select * from {{ ref('stg_operations__product_operations') }}
4+
5+
),
6+
7+
dates_per_sources as (
8+
9+
select
10+
*,
11+
'Collectes Supermarché' as source
12+
from {{ ref('seed_collection_dates') }}
13+
union
14+
select
15+
*,
16+
'Pleins Courses' as source
17+
from {{ ref('seed_grocery_shopping_dates') }}
18+
union
19+
select
20+
*,
21+
'Enlèvements BAPIF' as source
22+
from {{ ref('seed_bapif_collection_dates') }}
23+
24+
),
25+
26+
operations_dates_joined as (
27+
28+
select
29+
product_operations.date_at,
30+
dates_per_sources.source,
31+
product_operations.product_name,
32+
product_operations.unit_of_measure,
33+
product_operations.units_per_batch,
34+
max(product_operations.date_at) over (partition by source) as date_latest_collection,
35+
sum(product_operations.quantity_in_unit) as unit_entries,
36+
sum(product_operations.batch_quantity) as batch_quantity,
37+
sum(product_operations.monetary_value_eur) as monetary_value_eur
38+
from product_operations
39+
inner join dates_per_sources
40+
on product_operations.date_at = dates_per_sources.date_at
41+
where operation_type = 'in'
42+
and flow_type = 'inventory'
43+
group by 1,2,3,4,5
44+
45+
)
46+
47+
select * from operations_dates_joined
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
date_at
2+
2023-03-22

0 commit comments

Comments
 (0)