Skip to content

Commit

Permalink
add new all coupons table to marts (#1493)
Browse files Browse the repository at this point in the history
* add new all coupons table to marts and added two columns to orders mart
  • Loading branch information
KatelynGit authored Feb 28, 2025
1 parent 75a7091 commit ae20ced
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/ol_dbt/models/marts/combined/_marts__combined__models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ models:
- name: coupon_id
description: int, foreign key referencing ecommerce_coupon or the b2b coupon table.
For edX.org, it refers to ecommerce_coupon table in MicroMasters application.
- name: b2bcoupon_id
description: int, foreign key to b2becommerce_b2bcoupon
- name: b2border_contract_number
description: string, contract number used to identify the order
- name: coupon_name
description: string, human readable name for the coupon payment
- name: coupon_redeemed_on
Expand Down
12 changes: 12 additions & 0 deletions src/ol_dbt/models/marts/combined/marts__combined__orders.sql
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ with bootcamps__ecommerce_order as (
, mitxpro__ecommerce_order.order_tax_amount
, mitxpro__ecommerce_order.order_total_price_paid_plus_tax
, mitxpro__ecommerce_allorders.coupon_id
, mitxpro__ecommerce_allorders.b2bcoupon_id
, mitxpro__ecommerce_allorders.b2border_contract_number
, mitxpro__ecommerce_allorders.order_id
, mitxpro__ecommerce_order.order_total_price_paid
, mitxpro__ecommerce_order.couponpaymentversion_discount_amount_text as discount
Expand Down Expand Up @@ -209,6 +211,8 @@ with bootcamps__ecommerce_order as (
, user_id
, discount_code as coupon_code
, null as coupon_id
, null as b2bcoupon_id
, null as b2border_contract_number
, null as coupon_name
, discount_redemption_type as coupon_type
, discountredemption_timestamp as coupon_redeemed_on
Expand Down Expand Up @@ -265,6 +269,8 @@ with bootcamps__ecommerce_order as (
, order_purchaser_user_id as user_id
, coupon_code
, coupon_id
, b2bcoupon_id
, b2border_contract_number
, coupon_name
, coupon_type
, coupon_redeemed_on
Expand Down Expand Up @@ -312,6 +318,8 @@ with bootcamps__ecommerce_order as (
, order_purchaser_user_id as user_id
, null as coupon_code
, null as coupon_id
, null as b2bcoupon_id
, null as b2border_contract_number
, null as coupon_name
, null as coupon_type
, null as coupon_redeemed_on
Expand Down Expand Up @@ -359,6 +367,8 @@ with bootcamps__ecommerce_order as (
, user_edxorg_id as user_id
, coupon_code
, coupon_id
, null as b2bcoupon_id
, null as b2border_contract_number
, null as coupon_name
, coupon_type
, redeemedcoupon_created_on as coupon_redeemed_on
Expand Down Expand Up @@ -411,6 +421,8 @@ select
, line_id
, coupon_code
, coupon_id
, b2bcoupon_id
, b2border_contract_number
, coupon_name
, coupon_redeemed_on
, coupon_type
Expand Down
53 changes: 53 additions & 0 deletions src/ol_dbt/models/marts/mitxpro/_marts__mitxpro__models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,56 @@ models:
description: boolean, Public product is purchasable through the bulk form at /ecommerce/bulk
- name: platform_name
description: str, name of the platform

- name: marts__mitxpro_all_coupons
description: B2B and regular coupons combined into one table
columns:
- name: coupon_code
description: string, coupon code for the coupon
tests:
- not_null
- name: coupon_name
description: string, human readable name for the coupon payment
- name: coupon_created_on
description: timestamp, specifying when the coupon was initially created
tests:
- not_null
- name: payment_transaction
description: string, string that identifies the payment invoice for coupon purchases
by companies. This will be null for records sourced from b2b.
- name: discount_amount
description: string, either dollar amount off or percentage discount. If the data
is coming from b2b it is always a percentage.
tests:
- not_null
- name: coupon_type
description: string, one of 'single-use' or 'promo'. Promo coupon codes can be
used multiple times. This will be null for records sourced from b2b.
- name: discount_source
description: string, one of "staff", "marketing", "credit_card", "purchase_order",
"sales". "staff" coupons are used to allow staff to enroll in courses. "marketing"
coupons are promos for discounts generated by marketing. "credit_card", "purchase_order"
and "sales" correspond to different ways that companies can pay for vouchers
for their employees to enroll in courses or programs. This will be null for
records sourced from b2b.
- name: activated_on
description: timestamp, activation timestamp for the coupon
- name: expires_on
description: timestamp, expiration timestamp for the coupon
- name: coupon_source_table
description: string, either "ecommerce_coupon", "b2bcoupon". "ecommerce_coupon"
coupons are sourced from the int__mitxpro__ecommerce_coupon table and are used
to recieve a discount on a course or program. "b2bcoupon" coupons are sourced
from the int__mitxpro__b2becommerce_b2bcoupon table and represent a coupon used
by a business which can include many individuals.
- name: b2bcoupon_id
description: int, foreign key to b2becommerce_b2bcoupon.
- name: coupon_id
description: int, foreign key referencing ecommerce_coupon. This will be null
for records sourced from b2b.
- name: redeemed
description: boolean, set to true if the coupon has at least one redeemed order
otherwise it's false.
tests:
- dbt_expectations.expect_compound_columns_to_be_unique:
column_list: ["b2bcoupon_id", "coupon_id"]
54 changes: 54 additions & 0 deletions src/ol_dbt/models/marts/mitxpro/marts__mitxpro_all_coupons.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
with allcoupons as (
select *
from {{ ref('int__mitxpro__ecommerce_allcoupons') }}
)

, allorders as (
select *
from {{ ref('int__mitxpro__ecommerce_allorders') }}
)

, redeemed_coupons as (
select coupon_id
from allorders
where redeemed = true
group by coupon_id
)

, redeemed_b2b_coupons as (
select b2bcoupon_id
from allorders
where
redeemed = true
and coupon_id is null
group by b2bcoupon_id
)

select
allcoupons.coupon_code
, allcoupons.coupon_name
, allcoupons.coupon_created_on
, allcoupons.payment_transaction
, allcoupons.discount_amount
, allcoupons.coupon_type
, allcoupons.discount_source
, allcoupons.activated_on
, allcoupons.expires_on
, allcoupons.coupon_source_table
, allcoupons.b2bcoupon_id
, allcoupons.coupon_id
, case
when
redeemed_coupons.coupon_id is not null
or redeemed_b2b_coupons.b2bcoupon_id is not null
then true
when
redeemed_coupons.coupon_id is null
and redeemed_b2b_coupons.b2bcoupon_id is null
then false
end as redeemed
from allcoupons
left join redeemed_coupons
on allcoupons.coupon_id = redeemed_coupons.coupon_id
left join redeemed_b2b_coupons
on allcoupons.b2bcoupon_id = redeemed_b2b_coupons.b2bcoupon_id

0 comments on commit ae20ced

Please sign in to comment.