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

@@ -10,7 +10,7 @@ import VendorCreditInventoryTransactions from './VendorCreditInventoryTransactio
@Service()
export default class VendorCreditInventoryTransactionsSubscriber {
@Inject()
inventoryTransactions: VendorCreditInventoryTransactions;
private inventoryTransactions: VendorCreditInventoryTransactions;
/**
* Attaches events with handlers.
@@ -21,6 +21,10 @@ export default class VendorCreditInventoryTransactionsSubscriber {
events.vendorCredit.onCreated,
this.writeInventoryTransactionsOnceCreated
);
bus.subscribe(
events.vendorCredit.onOpened,
this.writeInventoryTransactionsOnceCreated
);
bus.subscribe(
events.vendorCredit.onEdited,
this.rewriteInventroyTransactionsOnceEdited
@@ -40,6 +44,9 @@ export default class VendorCreditInventoryTransactionsSubscriber {
vendorCredit,
trx,
}: IVendorCreditCreatedPayload) => {
// Can't continue if vendor credit is not opened.
if (!vendorCredit.openedAt) return null;
await this.inventoryTransactions.createInventoryTransactions(
tenantId,
vendorCredit,
@@ -57,6 +64,9 @@ export default class VendorCreditInventoryTransactionsSubscriber {
vendorCredit,
trx,
}: IVendorCreditEditedPayload) => {
// Can't continue if vendor credit is not opened.
if (!vendorCredit.openedAt) return null;
await this.inventoryTransactions.editInventoryTransactions(
tenantId,
vendorCreditId,