mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
Merge pull request #649 from bigcapitalhq/import-multi-branches-expenses
fix: Integrate multiple branches with expense resource
This commit is contained in:
@@ -17,6 +17,7 @@ export interface IExpensesFilter {
|
||||
columnSortBy: string;
|
||||
sortOrder: string;
|
||||
viewSlug?: string;
|
||||
filterQuery?: (query: any) => void;
|
||||
}
|
||||
|
||||
export interface IExpense {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { Features } from '@/interfaces';
|
||||
|
||||
/**
|
||||
* Expense - Settings.
|
||||
*/
|
||||
@@ -119,6 +121,12 @@ export default {
|
||||
type: 'boolean',
|
||||
printable: false,
|
||||
},
|
||||
branch: {
|
||||
name: 'Branch',
|
||||
type: 'text',
|
||||
accessor: 'branch.name',
|
||||
features: [Features.BRANCHES],
|
||||
},
|
||||
},
|
||||
fields2: {
|
||||
paymentAccountId: {
|
||||
@@ -178,6 +186,14 @@ export default {
|
||||
name: 'expense.field.publish',
|
||||
fieldType: 'boolean',
|
||||
},
|
||||
branchId: {
|
||||
name: 'Branch',
|
||||
fieldType: 'relation',
|
||||
relationModel: 'Branch',
|
||||
relationImportMatch: ['name', 'code'],
|
||||
features: [Features.BRANCHES],
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ export class GetExpenses {
|
||||
builder.withGraphFetched('categories.expenseAccount');
|
||||
|
||||
dynamicList.buildQuery()(builder);
|
||||
filterDTO?.filterQuery && filterDTO?.filterQuery(builder);
|
||||
})
|
||||
.pagination(filter.page - 1, filter.pageSize);
|
||||
|
||||
|
||||
@@ -15,12 +15,16 @@ export class ExpensesExportable extends Exportable {
|
||||
* @returns
|
||||
*/
|
||||
public exportable(tenantId: number, query: IExpensesFilter) {
|
||||
const filterQuery = (query) => {
|
||||
query.withGraphFetched('branch');
|
||||
};
|
||||
const parsedQuery = {
|
||||
sortOrder: 'desc',
|
||||
columnSortBy: 'created_at',
|
||||
...query,
|
||||
page: 1,
|
||||
pageSize: EXPORT_SIZE_LIMIT,
|
||||
filterQuery,
|
||||
} as IExpensesFilter;
|
||||
|
||||
return this.expensesApplication
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
import { Service, Inject } from 'typedi';
|
||||
import { camelCase, upperFirst, pickBy } from 'lodash';
|
||||
import { camelCase, upperFirst, pickBy, isEmpty } from 'lodash';
|
||||
import * as qim from 'qim';
|
||||
import pluralize from 'pluralize';
|
||||
import { IModelMeta, IModelMetaField, IModelMetaField2 } from '@/interfaces';
|
||||
import {
|
||||
Features,
|
||||
IModelMeta,
|
||||
IModelMetaField,
|
||||
IModelMetaField2,
|
||||
} from '@/interfaces';
|
||||
import TenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { ServiceError } from '@/exceptions';
|
||||
import I18nService from '@/services/I18n/I18nService';
|
||||
import { WarehousesSettings } from '../Warehouses/WarehousesSettings';
|
||||
import { BranchesSettings } from '../Branches/BranchesSettings';
|
||||
|
||||
const ERRORS = {
|
||||
RESOURCE_MODEL_NOT_FOUND: 'RESOURCE_MODEL_NOT_FOUND',
|
||||
@@ -19,6 +26,12 @@ export default class ResourceService {
|
||||
@Inject()
|
||||
i18nService: I18nService;
|
||||
|
||||
@Inject()
|
||||
private branchesSettings: BranchesSettings;
|
||||
|
||||
@Inject()
|
||||
private warehousesSettings: WarehousesSettings;
|
||||
|
||||
/**
|
||||
* Transform resource to model name.
|
||||
* @param {string} resourceName
|
||||
@@ -74,13 +87,45 @@ export default class ResourceService {
|
||||
return meta.fields;
|
||||
}
|
||||
|
||||
public filterSupportFeatures = (
|
||||
tenantId,
|
||||
fields: { [key: string]: IModelMetaField2 }
|
||||
) => {
|
||||
const isMultiFeaturesEnabled =
|
||||
this.branchesSettings.isMultiBranchesActive(tenantId);
|
||||
const isMultiWarehousesEnabled =
|
||||
this.warehousesSettings.isMultiWarehousesActive(tenantId);
|
||||
|
||||
return pickBy(fields, (field) => {
|
||||
if (
|
||||
!isMultiWarehousesEnabled &&
|
||||
field.features?.includes(Features.WAREHOUSES)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
!isMultiFeaturesEnabled &&
|
||||
field.features?.includes(Features.BRANCHES)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
};
|
||||
|
||||
public getResourceFields2(
|
||||
tenantId: number,
|
||||
modelName: string
|
||||
): { [key: string]: IModelMetaField2 } {
|
||||
const meta = this.getResourceMeta(tenantId, modelName);
|
||||
|
||||
return meta.fields2;
|
||||
return this.filterSupportFeatures(tenantId, meta.fields2);
|
||||
}
|
||||
|
||||
public getResourceColumns(tenantId: number, modelName: string) {
|
||||
const meta = this.getResourceMeta(tenantId, modelName);
|
||||
|
||||
return this.filterSupportFeatures(tenantId, meta.columns);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user