Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New model for a purchase order reporting structure #24

Closed
wants to merge 12 commits into from
Closed
6 changes: 4 additions & 2 deletions dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: 'xero'
version: '0.4.0'
version: '0.3.0'
config-version: 2
require-dbt-version: [">=1.0.0", "<2.0.0"]
require-dbt-version: ">=0.20.0"

vars:
xero:
Expand All @@ -14,6 +14,8 @@ vars:
organization: "{{ ref('stg_xero__organization') }}"
credit_note: "{{ ref('stg_xero__credit_note') }}"
bank_transaction: "{{ ref('stg_xero__bank_transaction') }}"
purchase_order_line_item: "{{ ref('stg_xero__purchase_order_line_item') }}"
purchase_order: "{{ ref('stg_xero__purchase_order') }}"

models:
xero:
Expand Down
81 changes: 81 additions & 0 deletions models/xero.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ models:
description: Percentage discount being applied to a line item.
- name: invoice_id
description: The Xero identifier for the invoice the line items belongs to.
tests:
- not_null
- name: item_code
description: User defined item code.
- name: line_amount
Expand Down Expand Up @@ -209,3 +211,82 @@ models:
The source where this data was pulled from. If you are making use of the `union_schemas` variable, this will be the source schema.
If you are making use of the `union_databases` variable, this will be the source database. If you are not unioining together multiple
sources, this will be an empty string.


- name: xero__purchase_order_line_items
description: Each record represents a purchase order line item, enriched with account, contact and invoice information.
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- line_item_id
- source_relation
columns:
- name: _fivetran_synced
description: "{{ doc('_fivetran_synced') }}"
- name: description
description: The description of the line item
- name: discount_rate
description: Percentage discount being applied to a purchase order line item.
- name: purchase_order_id
description: The Xero identifier for the purchase order the line items belongs to.
tests:
- not_null
- name: item_code
description: User defined item code.
- name: line_amount
description: The line amount reflects the discounted price if a DiscountRate has been used.
- name: line_item_id
description: Xero identifier for the purchase order line item.
tests:
- not_null
- name: quantity
description: The quantity of the purchase order line item.
- name: tax_amount
description: The tax amount is auto calculated as a percentage of the line amount based on the tax rate.
- name: tax_type
description: Used as an override if the default Tax Code for the selected AccountCode is not correct.
- name: unit_amount
description: The unit amount of each purchase order line item.
- name: purchase_order_date
description: The date the purchase order was issued.
- name: updated_date
description: The date the purchase order was last modified.
- name: delivery_date
description: The expected delivery date of the purchase order goods, when set.
- name: currency_code
description: The currency that purchase order has been raised in
- name: currency_rate
description: The currency rate for a multicurrency purchase order
- name: purchase_order_reference
description: Additional reference number to suit the organisation or supplier.
- name: purchase_order_status
description: The status of the purchase order
- name: type
description: The type of the purchase order.
- name: is_discounted
description: Flags if purchase order items have discounts applied
- name: line_amount_types
description: Tax inclusive, exclusive or no tax
- name: sub_total
description: Purchase order amount before tax
- name: total_tax
description: Purchase order tax amount
- name: total
description: Purchase order total amount including tax
- name: account_id
description: The Xero identifier for the related account.
- name: account_name
description: The name of the account.
- name: account_code
description: Customer defined alpha numeric account code e.g 200 or SALES
- name: account_type
description: The type of account, e.g. CURRENT, EQUITY, SALES
- name: account_class
description: The class of account, e.g. ASSET, EQUITY, EXPENSE, LIABILITY, REVENUE
- name: contact_name
description: The name of the associated contact.
- name: source_relation
description: >
The source where this data was pulled from. If you are making use of the `union_schemas` variable, this will be the source schema.
If you are making use of the `union_databases` variable, this will be the source database. If you are not unioining together multiple
sources, this will be an empty string.
61 changes: 61 additions & 0 deletions models/xero__purchase_order_line_items.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
with line_items as (

select *
from {{ var('purchase_order_line_item') }}

), purchase_orders as (

select *
from {{ var('purchase_order') }}

), accounts as (

select *
from {{ var('account') }}

), contacts as (

select *
from {{ var('contact') }}

), joined as (

select
line_items.*,

purchase_orders.purchase_order_date,
purchase_orders.updated_date,
purchase_orders.delivery_date,
purchase_orders.sub_total,
purchase_orders.total_tax,
purchase_orders.total,
purchase_orders.currency_code,
purchase_orders.currency_rate,
purchase_orders.purchase_order_number,
purchase_orders.purchase_order_status,
purchase_orders.type,
purchase_orders.reference as purchase_order_reference,
purchase_orders.is_discounted,
purchase_orders.line_amount_types,
accounts.account_id,
accounts.account_name,
accounts.account_type,
accounts.account_class,

contacts.contact_name

from line_items
left join purchase_orders
on (line_items.purchase_order_id = purchase_orders.purchase_order_id
and line_items.source_relation = purchase_orders.source_relation)
left join accounts
on (line_items.account_code = accounts.account_code
and line_items.source_relation = accounts.source_relation)
left join contacts
on (purchase_orders.contact_id = contacts.contact_id
and purchase_orders.source_relation = contacts.source_relation)

)

select *
from joined
3 changes: 1 addition & 2 deletions packages.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
packages:
- package: fivetran/xero_source
version: [">=0.4.0", "<0.5.0"]
- git: https://github.com/Project-Rouge/dbt_xero_source