From b5d29fc8312d407ea7dd9ab84ee5efadd09fbbfa Mon Sep 17 00:00:00 2001 From: Renee Li Date: Sat, 15 Jun 2024 01:28:18 +0900 Subject: [PATCH] add docs --- .../stripe__common_data_models.yml | 79 +++++++++++++++++++ .../stripe__line_item_enhanced.sql | 13 +-- 2 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 models/common_data_models/stripe__common_data_models.yml diff --git a/models/common_data_models/stripe__common_data_models.yml b/models/common_data_models/stripe__common_data_models.yml new file mode 100644 index 00000000..dc5b6685 --- /dev/null +++ b/models/common_data_models/stripe__common_data_models.yml @@ -0,0 +1,79 @@ +version: 2 + +models: + - name: stripe__line_item_enhanced + description: Add description + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - header_id + - line_item_id + columns: + - name: header_id + description: Id of corresponding invoice. + - name: line_item_id + description: Invoice line item id. + - name: line_item_index + description: Unique index of each line item id for each invoice. + - name: record_type + description: header or line_item + - name: created_at + description: When the invoice was created + - name: header_status + description: Status of the invoice. + - name: billing_type + description: Type of invoice line item. + - name: currency + description: Currency used in the invoice. + - name: product_id + description: Product ID + - name: product_name + description: Product name + - name: product_type + description: Product type + - name: transaction_type + description: Balance transaction type + - name: quantity + description: The number of units of this line item. + - name: unit_amount + description: Amount per unit. + - name: discount_amount + description: The discount amount associated with this invoice. + - name: tax_amount + description: The tax amount associated with this invoice. + - name: total_amount + description: Invoice total + - name: payment_id + description: Payment intent ID + - name: payment_method + description: Payment method type + - name: payment_method_id + description: Payment method ID + - name: payment_at + description: Charge created date + - name: fee_amount + description: Balance transaction fee + - name: refund_amount + description: Refund amount associated with this invoice. + - name: subscription_id + description: Subscription associated with this invoice. + - name: subscription_period_started_at + description: Subscription's current period start + - name: subscription_period_ended_at + description: Subscription's current period end + - name: subscription_status + description: Subscription status + - name: customer_id + description: Customer associated with this invoice. + - name: customer_level + description: Whether 'account' or 'customer'. For Stripe, the level is 'customer'. + - name: customer_name + description: Customer name + - name: customer_company + description: Associated account's company if applicable. + - name: customer_email + description: Customer email + - name: customer_city + description: Customer city + - name: customer_country + description: Customer country \ No newline at end of file diff --git a/models/common_data_models/stripe__line_item_enhanced.sql b/models/common_data_models/stripe__line_item_enhanced.sql index 75c4f078..b59d916e 100644 --- a/models/common_data_models/stripe__line_item_enhanced.sql +++ b/models/common_data_models/stripe__line_item_enhanced.sql @@ -60,8 +60,11 @@ with invoice_line_item as ( ), discount as ( - select * + select + invoice_id, + sum(amount) as total_discount_amount from {{ var('discount') }} + group by 1 ), refund as ( @@ -89,12 +92,12 @@ with invoice_line_item as ( cast(product.type as {{ dbt.type_string() }}) as product_type, cast(invoice_line_item.quantity as {{ dbt.type_numeric() }}) as quantity, cast((invoice_line_item.amount/invoice_line_item.quantity) as {{ dbt.type_numeric() }}) as unit_amount, - cast(discount.amount as {{ dbt.type_numeric() }}) as discount_amount, + cast(discount.total_discount_amount as {{ dbt.type_numeric() }}) as discount_amount, cast(invoice.tax as {{ dbt.type_numeric() }}) as tax_amount, cast(invoice.total as {{ dbt.type_numeric() }}) as total_amount, cast(payment_intent.payment_intent_id as {{ dbt.type_string() }}) as payment_id, cast(payment_method.payment_method_id as {{ dbt.type_string() }}) as payment_method_id, - cast(payment_method.type as {{ dbt.type_string() }}) as payment_method_name, + cast(payment_method.type as {{ dbt.type_string() }}) as payment_method, cast(charge.created_at as {{ dbt.type_timestamp() }}) as payment_at, cast(balance_transaction.fee as {{ dbt.type_numeric() }}) as fee_amount, cast(refund.amount as {{ dbt.type_numeric() }}) as refund_amount, @@ -192,7 +195,7 @@ with invoice_line_item as ( total_amount, payment_id, payment_method_id, - payment_method_name, + payment_method, payment_at, cast(null as {{ dbt.type_numeric() }}) as fee_amount, cast(null as {{ dbt.type_numeric() }}) as refund_amount, @@ -232,7 +235,7 @@ with invoice_line_item as ( cast(null as {{ dbt.type_float() }}) as total_amount, payment_id, payment_method_id, - payment_method_name, + payment_method, payment_at, fee_amount, refund_amount,