mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
feat: wip categorized transactions
This commit is contained in:
@@ -196,6 +196,7 @@ export default class Account extends mixin(TenantModel, [
|
||||
const Expense = require('models/Expense');
|
||||
const ExpenseEntry = require('models/ExpenseCategory');
|
||||
const ItemEntry = require('models/ItemEntry');
|
||||
const UncategorizedTransaction = require('models/UncategorizedCashflowTransaction');
|
||||
|
||||
return {
|
||||
/**
|
||||
@@ -305,6 +306,21 @@ export default class Account extends mixin(TenantModel, [
|
||||
to: 'items_entries.sellAccountId',
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Associated uncategorized transactions.
|
||||
*/
|
||||
uncategorizedTransactions: {
|
||||
relation: Model.HasManyRelation,
|
||||
modelClass: UncategorizedTransaction.default,
|
||||
join: {
|
||||
from: 'accounts.id',
|
||||
to: 'uncategorized_cashflow_transactions.accountId',
|
||||
},
|
||||
filter: (query) => {
|
||||
query.filter('categorized', false);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/* eslint-disable global-require */
|
||||
import TenantModel from 'models/TenantModel';
|
||||
import { Model } from 'objection';
|
||||
import Account from './Account';
|
||||
|
||||
export default class UncategorizedCashflowTransaction extends TenantModel {
|
||||
amount: number;
|
||||
@@ -80,4 +81,29 @@ export default class UncategorizedCashflowTransaction extends TenantModel {
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param queryContext
|
||||
*/
|
||||
public async $afterInsert(queryContext) {
|
||||
await super.$afterInsert(queryContext);
|
||||
|
||||
// Increments the uncategorized transactions count of the associated account.
|
||||
await Account.query(queryContext.transaction)
|
||||
.findById(this.accountId)
|
||||
.increment('uncategorized_transactions', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param queryContext
|
||||
*/
|
||||
public async $afterDelete(queryContext) {
|
||||
await super.$afterDelete(queryContext);
|
||||
|
||||
await Account.query()
|
||||
.findById(this.accountId)
|
||||
.decrement('uncategorized_transactions', 1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user