Commit 4ff8df82 authored by Taylor A Murphy, PhD's avatar Taylor A Murphy, PhD 🚀

Merge branch '2274-build-refunds-model-in-dbt' into 'master'

Resolve "Build Refunds Model in dbt"

See merge request !1471
parents eab9a1c3 97821546
......@@ -60,6 +60,15 @@ models:
tests:
- not_null
- unique
- name: zuora_refund
description: Base model for Zuora Refunds
columns:
- name: account_id
tests:
- not_null
- name: refund_date
tests:
- not_null
- name: zuora_subscription
description: '{{ doc("zuora_subscription") }}'
columns:
......
......@@ -15,7 +15,7 @@ sources:
freshness:
warn_after: {count: 8, period: hour}
tables:
tables:
- name: account
description: '{{ doc("zuora_account_source") }}'
- name: contact
......@@ -28,6 +28,7 @@ sources:
description: '{{ doc("zuora_rateplan_charge_source") }}'
- name: rateplan
description: '{{ doc("zuora_rateplan_source") }}'
- name: refund
description: '{{ doc("zuora_refund_source") }}'
- name: subscription
description: '{{ doc("zuora_subscription_source") }}'
......@@ -50,10 +50,15 @@ This is the source table for Zuora Rate Plan Charges. [Link to Documentation](ht
{% enddocs %}
{% docs zuora_refund_source %}
This is the source table for Zuora Refunds. [Link to Documentation](https://knowledgecenter.zuora.com/DC_Developers/G_SOAP_API/E1_SOAP_API_Object_Reference/Refund)
{% enddocs %}
{% docs zuora_subscription_source %}
The subscription source table contains info about your products and/or services with recurring charges.
[Link to Documentation](https://www.stitchdata.com/docs/integrations/saas/zuora#subscription)
{% enddocs %}
\ No newline at end of file
{% enddocs %}
{{config({
"schema": "staging"
})
}}
WITH source AS (
SELECT *
FROM {{ source('zuora', 'refund') }}
), renamed AS (
SELECT accountid AS account_id,
accountingcode AS accounting_code,
amount,
billtocontactid AS bill_to_contact_id,
cancelledon AS cancelled_on,
comment,
createdbyid AS created_by_id,
createddate AS created_date,
defaultpaymentmethodid AS default_payment_method_id,
deleted AS is_deleted,
gateway,
gatewayresponse AS gateway_response,
gatewayresponsecode AS gateway_response_code,
gatewaystate AS gateway_state,
id AS refund_id,
methodtype AS method_type,
parentaccountid AS parent_account_id,
paymentmethodid AS payment_method_id,
paymentmethodsnapshotid AS payment_method_snapshot_id,
reasoncode AS reason_code,
referenceid AS reference_id,
refunddate AS refund_date,
refundnumber AS refund_number,
refundtransactiontime AS refund_transaction_time,
secondrefundreferenceid AS second_refund_reference_id,
softdescriptor AS soft_descriptor,
softdescriptorphone AS soft_descriptor_phone,
soldtocontactid AS sold_to_contact_id,
sourcetype AS source_type,
status AS refund_status,
submittedon AS submitted_on,
transferredtoaccounting AS transferred_to_accounting,
type AS refund_type,
updatedbyid AS updated_by_id,
updateddate AS updated_date
FROM source
)
SELECT *
FROM renamed
......@@ -260,3 +260,9 @@ models:
- name: cohort_year
tests:
- not_null
- name: zuora_refund_xf
description: Zuora Refunds
columns:
- name: refund_month
tests:
- not_null
WITH zuora_refund_base AS (
SELECT *
FROM {{ref('zuora_refund')}}
), zuora_account AS (
SELECT * FROM {{ref('zuora_account')}}
)
SELECT zuora_account.sfdc_entity,
zuora_account.account_name,
zuora_account.account_number,
zuora_account.currency,
date_trunc('month',refund_date)::DATE AS refund_month,
amount AS refund_amount,
comment,
reason_code,
is_deleted,
zuora_refund_base.refund_status
FROM zuora_refund_base
LEFT JOIN zuora_account
ON zuora_refund_base.account_id = zuora_account.account_id
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment