mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
feat: compute items cost of inventory adjustments transcations.
This commit is contained in:
@@ -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);
|
||||
49
server/src/subscribers/Inventory/InventoryAdjustment.ts
Normal file
49
server/src/subscribers/Inventory/InventoryAdjustment.ts
Normal 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,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user