mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-23 16:19:49 +00:00
fix(server): shouldn't write GL entries when save transaction as draft.
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
||||
ISaleInvoiceCreatedPayload,
|
||||
ISaleInvoiceDeletedPayload,
|
||||
ISaleInvoiceEditedPayload,
|
||||
ISaleInvoiceEventDeliveredPayload,
|
||||
} from '@/interfaces';
|
||||
import { InvoiceInventoryTransactions } from '@/services/Sales/Invoices/InvoiceInventoryTransactions';
|
||||
|
||||
@@ -20,6 +21,10 @@ export default class WriteInventoryTransactions {
|
||||
events.saleInvoice.onCreated,
|
||||
this.handleWritingInventoryTransactions
|
||||
);
|
||||
bus.subscribe(
|
||||
events.saleInvoice.onDelivered,
|
||||
this.handleWritingInventoryTransactions
|
||||
);
|
||||
bus.subscribe(
|
||||
events.saleInvoice.onEdited,
|
||||
this.handleRewritingInventoryTransactions
|
||||
@@ -38,7 +43,10 @@ export default class WriteInventoryTransactions {
|
||||
tenantId,
|
||||
saleInvoice,
|
||||
trx,
|
||||
}: ISaleInvoiceCreatedPayload) => {
|
||||
}: ISaleInvoiceCreatedPayload | ISaleInvoiceEventDeliveredPayload) => {
|
||||
// Can't continue if the sale invoice is not delivered yet.
|
||||
if (!saleInvoice.deliveredAt) return null;
|
||||
|
||||
await this.saleInvoiceInventory.recordInventoryTranscactions(
|
||||
tenantId,
|
||||
saleInvoice,
|
||||
|
||||
@@ -15,11 +15,15 @@ export default class SaleInvoiceWriteGLEntriesSubscriber {
|
||||
/**
|
||||
* Constructor method.
|
||||
*/
|
||||
attach(bus) {
|
||||
public attach(bus) {
|
||||
bus.subscribe(
|
||||
events.saleInvoice.onCreated,
|
||||
this.handleWriteJournalEntriesOnInvoiceCreated
|
||||
);
|
||||
bus.subscribe(
|
||||
events.saleInvoice.onDelivered,
|
||||
this.handleWriteJournalEntriesOnInvoiceCreated
|
||||
);
|
||||
bus.subscribe(
|
||||
events.saleInvoice.onEdited,
|
||||
this.handleRewriteJournalEntriesOnceInvoiceEdit
|
||||
@@ -36,8 +40,12 @@ export default class SaleInvoiceWriteGLEntriesSubscriber {
|
||||
private handleWriteJournalEntriesOnInvoiceCreated = async ({
|
||||
tenantId,
|
||||
saleInvoiceId,
|
||||
saleInvoice,
|
||||
trx,
|
||||
}: ISaleInvoiceCreatedPayload) => {
|
||||
// Can't continue if the sale invoice is not delivered yet.
|
||||
if (!saleInvoice.deliveredAt) return null;
|
||||
|
||||
await this.saleInvoiceGLEntries.writeInvoiceGLEntries(
|
||||
tenantId,
|
||||
saleInvoiceId,
|
||||
@@ -53,6 +61,9 @@ export default class SaleInvoiceWriteGLEntriesSubscriber {
|
||||
saleInvoice,
|
||||
trx,
|
||||
}: ISaleInvoiceEditedPayload) => {
|
||||
// Can't continue if the sale invoice is not delivered yet.
|
||||
if (!saleInvoice.deliveredAt) return null;
|
||||
|
||||
await this.saleInvoiceGLEntries.rewritesInvoiceGLEntries(
|
||||
tenantId,
|
||||
saleInvoice.id,
|
||||
|
||||
Reference in New Issue
Block a user