From 2faa47e7cb2c4bcd00247bcd6a0429fe5cdf6771 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Thu, 16 May 2024 18:11:53 +0200 Subject: [PATCH] staging model for credit notes --- models/staging/xero/_xero_sources.yml | 4 ++ .../staging/xero/stg_xero__credit_notes.sql | 37 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 models/staging/xero/stg_xero__credit_notes.sql diff --git a/models/staging/xero/_xero_sources.yml b/models/staging/xero/_xero_sources.yml index eec9672..2d2cf9d 100644 --- a/models/staging/xero/_xero_sources.yml +++ b/models/staging/xero/_xero_sources.yml @@ -15,3 +15,7 @@ sources: identifier: invoices description: | Invoices that we have raised within our accounting books. + - name: credit_notes + identifier: credit_notes + description: | + Credit notes that have been created within our accounting books. diff --git a/models/staging/xero/stg_xero__credit_notes.sql b/models/staging/xero/stg_xero__credit_notes.sql new file mode 100644 index 0000000..bd35342 --- /dev/null +++ b/models/staging/xero/stg_xero__credit_notes.sql @@ -0,0 +1,37 @@ +with + raw_credit_notes as (select * from {{ source("xero", "credit_notes") }}), + stg_xero__credit_notes as ( + select + {{ adapter.quote("CreditNoteID") }} as id_credit_note, + {{ adapter.quote("Reference") }} as reference, + {{ adapter.quote("CreditNoteNumber") }} as credit_note_number, + {{ adapter.quote("Date") }} as credit_note_issued_at_utc, + cast({{ adapter.quote("Date") }} as date) as credit_note_issued_date_utc, + {{ adapter.quote("Type") }} as credit_note_type, + {{ adapter.quote("CurrencyCode") }} as invoice_currency_iso_4217, + 1 / {{ adapter.quote("CurrencyRate") }} as exchange_rate_to_gbp, + {{ adapter.quote("Total") }} as total_amount_local_curr, + {{ adapter.quote("SubTotal") }} as subtotal_local_curr, + {{ adapter.quote("TotalTax") }} as total_tax_local_curr, + {{ adapter.quote("RemainingCredit") }} as remaining_credit_local_curr, + {{ adapter.quote("AppliedAmount") }} as applied_amount, + {{ adapter.quote("Status") }} as credit_note_status, + {{ adapter.quote("Contact") }} as full_contact_details, + {{ adapter.quote("DueDate") }} as credit_note_due_date, + {{ adapter.quote("LineItems") }} as line_items, + {{ adapter.quote("DateString") }} as date_string, + {{ adapter.quote("DueDateString") }} as due_date_string, + {{ adapter.quote("Allocations") }} as allocations, + {{ adapter.quote("SentToContact") }} as has_been_sent_to_contact, + {{ adapter.quote("HasAttachments") }} as has_attachments, + {{ adapter.quote("UpdatedDateUTC") }} as updated_at_utc, + {{ adapter.quote("BrandingThemeID") }} as id_branding_theme, + {{ adapter.quote("FullyPaidOnDate") }} as was_fully_paid_on_date_utc, + {{ adapter.quote("LineAmountTypes") }} as line_amount_tax_inclusiveness, + cast({{ adapter.quote("UpdatedDateUTC") }} as date) as updated_date_utc, + {{ adapter.quote("_airbyte_extracted_at") }} as dwh_extracted_at_utc + + from raw_credit_notes + ) +select * +from stg_xero__credit_notes