Files
bigcapital/server/src/models/ItemCategory.js
a.bouhuolia ce875ccf4e feat(contacts): auto-complete contacts.
feat(items): auto-complete items.
feat(resources): resource columns feat.
feat(contacts): retrieve specific contact details.
2021-03-03 11:35:42 +02:00

111 lines
2.3 KiB
JavaScript

import path from 'path';
import { Model } from 'objection';
import TenantModel from 'models/TenantModel';
export default class ItemCategory extends TenantModel {
/**
* Table name.
*/
static get tableName() {
return 'items_categories';
}
static get resourceable() {
return true;
}
/**
* Timestamps columns.
*/
get timestamps() {
return ['createdAt', 'updatedAt'];
}
/**
* Relationship mapping.
*/
static get relationMappings() {
const Item = require('models/Item');
return {
/**
* Item category may has many items.
*/
items: {
relation: Model.HasManyRelation,
modelClass: Item.default,
join: {
from: 'items_categories.id',
to: 'items.categoryId',
},
},
};
}
/**
* Item category fields.
*/
static get fields() {
return {
name: {
label: 'Name',
column: 'name',
columnType: 'string'
},
description: {
label: 'Description',
column: 'description',
columnType: 'string'
},
user: {
label: 'User',
column: 'user_id',
relation: 'users.id',
relationColumn: 'users.id',
},
cost_account: {
label: 'Cost account',
column: 'cost_account_id',
relation: 'accounts.id',
optionsResource: 'account'
},
sell_account: {
label: 'Sell account',
column: 'sell_account_id',
relation: 'accounts.id',
optionsResource: 'account'
},
inventory_account: {
label: 'Inventory account',
column: 'inventory_account_id',
relation: 'accounts.id',
optionsResource: 'account'
},
cost_method: {
label: 'Cost method',
column: 'cost_method',
options: [{
key: 'FIFO', label: 'First-in first-out (FIFO)',
key: 'LIFO', label: 'Last-in first-out (LIFO)',
key: 'average', label: 'Average rate',
}],
columnType: 'string',
},
count: {
label: 'Count',
column: 'count',
sortQuery: this.sortCountQuery
},
created_at: {
label: 'Created at',
column: 'created_at',
columnType: 'date',
},
};
}
static sortCountQuery(query, role) {
query.orderBy('count', role.order);
}
}