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

Transactions: add accounting category to CSV #520

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/server/controllers/account-transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ export const transactionsFragment = gqlV2/* GraphQL */ `
payoutMethod {
type
}
accountingCategory @include(if: $hasAccountingCategoryField) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice !

id
code
name
}
}
isRefund
isRefunded
Expand Down Expand Up @@ -153,6 +158,7 @@ const transactionsQuery = gqlV2/* GraphQL */ `
$fetchPaymentProcessorFee: Boolean
$fetchTax: Boolean
$fullDescription: Boolean
$hasAccountingCategoryField: Boolean!
) {
transactions(
includeDebts: true
Expand Down Expand Up @@ -196,6 +202,7 @@ const hostTransactionsQuery = gqlV2/* GraphQL */ `
$fetchTax: Boolean
$fullDescription: Boolean
$account: [AccountReferenceInput!]
$hasAccountingCategoryField: Boolean!
) {
transactions(
includeDebts: true
Expand Down Expand Up @@ -241,7 +248,16 @@ const formatAccountName = (account) => {
}
};

const formatAccountingCategory = (accountingCategory) => {
if (!accountingCategory) {
return '';
} else {
return `${accountingCategory.code} - ${accountingCategory.name}`;
}
};

const csvMapping = {
accountingCategory: (t) => formatAccountingCategory(get(t, 'expense.accountingCategory')),
date: (t) => moment.utc(t.createdAt).format('YYYY-MM-DD'),
datetime: (t) => moment.utc(t.createdAt).format('YYYY-MM-DDTHH:mm:ss'),
id: 'id',
Expand Down Expand Up @@ -512,6 +528,9 @@ const accountTransactions = async (req, res) => {

const fetchAll = variables.offset ? false : parseToBooleanDefaultFalse(req.query.fetchAll);

// Add fields info to the query, to prevent fetching what's not needed
variables.hasAccountingCategoryField = fields.includes('accountingCategory');

try {
// Forward Api Key or Authorization header
const headers = {};
Expand Down