feat: Re-compute the given items cost job.

feat: Optimize the architecture.
This commit is contained in:
Ahmed Bouhuolia
2020-08-18 02:28:08 +02:00
parent 4e68a7db71
commit d423365a19
44 changed files with 1605 additions and 798 deletions

View File

@@ -0,0 +1,36 @@
import { Model } from 'objection';
import TenantModel from '@/models/TenantModel';
export default class InventoryCostLotTracker extends TenantModel {
/**
* Table name
*/
static get tableName() {
return 'inventory_cost_lot_tracker';
}
/**
* Model timestamps.
*/
static get timestamps() {
return [];
}
/**
* Relationship mapping.
*/
static get relationMappings() {
const Item = require('@/models/Item');
return {
item: {
relation: Model.BelongsToOneRelation,
modelClass: this.relationBindKnex(Item.default),
join: {
from: 'inventory_cost_lot_tracker.itemId',
to: 'items.id',
},
},
};
}
}

View File

@@ -1,18 +0,0 @@
import { Model } from 'objection';
import TenantModel from '@/models/TenantModel';
export default class InventoryLotCostTracker extends TenantModel {
/**
* Table name
*/
static get tableName() {
return 'inventory_cost_lot_tracker';
}
/**
* Model timestamps.
*/
static get timestamps() {
return [];
}
}

View File

@@ -15,4 +15,22 @@ export default class InventoryTransaction extends TenantModel {
static get timestamps() {
return ['createdAt', 'updatedAt'];
}
/**
* Relationship mapping.
*/
static get relationMappings() {
const Item = require('@/models/Item');
return {
item: {
relation: Model.BelongsToOneRelation,
modelClass: this.relationBindKnex(Item.default),
join: {
from: 'inventory_transactions.itemId',
to: 'items.id',
},
},
};
}
}

View File

@@ -37,6 +37,8 @@ export default class View extends mixin(TenantModel, [CachableModel]) {
specificOrFavourite(query, viewId) {
if (viewId) {
query.where('id', viewId)
} else {
query.where('favourite', true);
}
return query;
}

View File

@@ -19,6 +19,7 @@ import View from './View';
import ItemEntry from './ItemEntry';
import InventoryTransaction from './InventoryTransaction';
import AccountType from './AccountType';
import InventoryLotCostTracker from './InventoryCostLotTracker';
export {
Customer,
@@ -41,5 +42,6 @@ export {
View,
ItemEntry,
InventoryTransaction,
InventoryLotCostTracker,
AccountType,
};