feat: trigger compute items cost once the sale invoice and bill be edited or deleted.

This commit is contained in:
a.bouhuolia
2020-12-23 18:57:17 +02:00
parent 26452d9c05
commit b07bb2df53
9 changed files with 228 additions and 69 deletions

View File

@@ -392,7 +392,7 @@ export default class BillsService extends SalesInvoicesCost {
billId,
'IN',
billDate,
lotNumber,
lotNumber
);
// Records the inventory transactions.
await this.inventoryService.recordInventoryTransactions(
@@ -418,11 +418,25 @@ export default class BillsService extends SalesInvoicesCost {
* @return {Promise<void>}
*/
public async revertInventoryTransactions(tenantId: number, billId: number) {
const { inventoryTransactionRepository } = this.tenancy.repositories(
tenantId
);
// Retrieve the inventory transactions of the given sale invoice.
const oldInventoryTransactions = await inventoryTransactionRepository.find({
transactionId: billId,
transactionType: 'Bill',
});
await this.inventoryService.deleteInventoryTransactions(
tenantId,
billId,
'Bill'
);
// Triggers 'onInventoryTransactionsDeleted' event.
this.eventDispatcher.dispatch(
events.bill.onInventoryTransactionsDeleted,
{ tenantId, billId, oldInventoryTransactions }
);
}
/**