fix(server): wirte GL entries only when publish transaction

This commit is contained in:
Ahmed Bouhuolia
2023-08-17 21:49:07 +02:00
parent 5b2be2ac19
commit 0fcee0eaa7
13 changed files with 65 additions and 43 deletions

View File

@@ -4,6 +4,7 @@ import {
IBillCreatedPayload,
IBillEditedPayload,
IBIllEventDeletedPayload,
IBillOpenedPayload,
} from '@/interfaces';
import { BillInventoryTransactions } from '@/services/Purchases/Bills/BillInventoryTransactions';
@@ -20,6 +21,10 @@ export default class BillWriteInventoryTransactionsSubscriber {
events.bill.onCreated,
this.handleWritingInventoryTransactions
);
bus.subscribe(
events.bill.onOpened,
this.handleWritingInventoryTransactions
);
bus.subscribe(
events.bill.onEdited,
this.handleOverwritingInventoryTransactions
@@ -32,19 +37,19 @@ export default class BillWriteInventoryTransactionsSubscriber {
/**
* Handles writing the inventory transactions once bill created.
* @param {IBillCreatedPayload | IBillOpenedPayload} payload -
*/
private handleWritingInventoryTransactions = async ({
tenantId,
billId,
bill,
trx,
}: IBillCreatedPayload) => {
}: IBillCreatedPayload | IBillOpenedPayload) => {
// Can't continue if the bill is not opened yet.
if (!bill.openedAt) return null;
await this.billsInventory.recordInventoryTransactions(
tenantId,
billId,
bill.id,
false,
trx
);
@@ -52,6 +57,7 @@ export default class BillWriteInventoryTransactionsSubscriber {
/**
* Handles the overwriting the inventory transactions once bill edited.
* @param {IBillEditedPayload} payload -
*/
private handleOverwritingInventoryTransactions = async ({
tenantId,
@@ -72,6 +78,7 @@ export default class BillWriteInventoryTransactionsSubscriber {
/**
* Handles the reverting the inventory transactions once the bill deleted.
* @param {IBIllEventDeletedPayload} payload -
*/
private handleRevertInventoryTransactions = async ({
tenantId,

View File

@@ -19,7 +19,7 @@ export default class BillWriteGLEntriesSubscriber {
/**
* Attachs events with handles.
*/
attach(bus) {
public attach(bus) {
bus.subscribe(
events.bill.onCreated,
this.handlerWriteJournalEntriesOnCreate