feat: compute items cost of inventory adjustments transcations.

This commit is contained in:
a.bouhuolia
2021-01-10 17:41:32 +02:00
parent 097b9fdb3a
commit 8491d44118
20 changed files with 433 additions and 180 deletions

View File

@@ -43,19 +43,13 @@ export class InventorySubscriber {
@On(events.inventory.onInventoryTransactionsCreated)
async handleScheduleItemsCostOnInventoryTransactionsCreated({
tenantId,
inventoryEntries,
transactionId,
transactionType,
transactionDate,
transactionDirection,
override
inventoryTransactions
}) {
const inventoryItemsIds = map(inventoryEntries, 'itemId');
const inventoryItemsIds = map(inventoryTransactions, 'itemId');
await this.saleInvoicesCost.scheduleComputeCostByItemsIds(
await this.saleInvoicesCost.computeItemsCostByInventoryTransactions(
tenantId,
inventoryItemsIds,
transactionDate,
inventoryTransactions
);
}
@@ -69,6 +63,12 @@ export class InventorySubscriber {
transactionId,
oldInventoryTransactions
}) {
// Ignore compute item cost with theses transaction types.
const ignoreWithTransactionTypes = ['OpeningItem'];
if (ignoreWithTransactionTypes.indexOf(transactionType) !== -1) {
return;
}
const inventoryItemsIds = map(oldInventoryTransactions, 'itemId');
const startingDates = map(oldInventoryTransactions, 'date');
const startingDate = head(startingDates);

View File

@@ -0,0 +1,49 @@
import { Container } from 'typedi';
import { On, EventSubscriber } from 'event-dispatch';
import events from 'subscribers/events';
import TenancyService from 'services/Tenancy/TenancyService';
import InventoryAdjustmentService from 'services/Inventory/InventoryAdjustmentService';
@EventSubscriber()
export default class InventoryAdjustmentsSubscriber {
logger: any;
tenancy: TenancyService;
inventoryAdjustment: InventoryAdjustmentService;
/**
* Constructor method.
*/
constructor() {
this.logger = Container.get('logger');
this.tenancy = Container.get(TenancyService);
this.inventoryAdjustment = Container.get(InventoryAdjustmentService);
}
/**
* Handles writing inventory transactions once the quick adjustment created.
*/
@On(events.inventoryAdjustment.onQuickCreated)
async handleWriteInventoryTransactionsOnceQuickCreated({
tenantId,
inventoryAdjustment,
}) {
await this.inventoryAdjustment.writeInventoryTransactions(
tenantId,
inventoryAdjustment
)
}
/**
* Handles reverting invetory transactions once the inventory adjustment deleted.
*/
@On(events.inventoryAdjustment.onDeleted)
async handleRevertInventoryTransactionsOnceDeleted({
tenantId,
inventoryAdjustmentId
}) {
await this.inventoryAdjustment.revertInventoryTransactions(
tenantId,
inventoryAdjustmentId,
);
}
}