fix: make unique number of sales and purchases transactions is optional.

This commit is contained in:
Ahmed Bouhuolia
2020-10-26 14:32:35 +02:00
parent 3446dba0c5
commit 4ed96e5143
6 changed files with 42 additions and 20 deletions

View File

@@ -193,8 +193,9 @@ export default class PaymentReceiveService {
const paymentAmount = sumBy(paymentReceiveDTO.entries, 'paymentAmount');
// Validate payment receive number uniquiness.
await this.validatePaymentReceiveNoExistance(tenantId, paymentReceiveDTO.paymentReceiveNo);
if (paymentReceiveDTO.paymentReceiveNo) {
await this.validatePaymentReceiveNoExistance(tenantId, paymentReceiveDTO.paymentReceiveNo);
}
// Validate customer existance.
await this.customersService.getCustomerByIdOrThrowError(tenantId, paymentReceiveDTO.customerId);
@@ -255,8 +256,9 @@ export default class PaymentReceiveService {
const oldPaymentReceive = await this.getPaymentReceiveOrThrowError(tenantId, paymentReceiveId);
// Validate payment receive number uniquiness.
await this.validatePaymentReceiveNoExistance(tenantId, paymentReceiveDTO.paymentReceiveNo, paymentReceiveId);
if (paymentReceiveDTO.paymentReceiveNo) {
await this.validatePaymentReceiveNoExistance(tenantId, paymentReceiveDTO.paymentReceiveNo, paymentReceiveId);
}
// Validate the deposit account existance and type.
this.getDepositAccountOrThrowError(tenantId, paymentReceiveDTO.depositAccountId);

View File

@@ -99,8 +99,9 @@ export default class SaleEstimateService {
};
// Validate estimate number uniquiness on the storage.
await this.validateEstimateNumberExistance(tenantId, estimateDTO.estimateNumber);
if (estimateDTO.estimateNumber) {
await this.validateEstimateNumberExistance(tenantId, estimateDTO.estimateNumber);
}
// Retrieve the given customer or throw not found service error.
await this.customersService.getCustomer(tenantId, estimateDTO.customerId);
@@ -146,8 +147,9 @@ export default class SaleEstimateService {
};
// Validate estimate number uniquiness on the storage.
await this.validateEstimateNumberExistance(tenantId, estimateDTO.estimateNumber, estimateId);
if (estimateDTO.estimateNumber) {
await this.validateEstimateNumberExistance(tenantId, estimateDTO.estimateNumber, estimateId);
}
// Retrieve the given customer or throw not found service error.
await this.customersService.getCustomer(tenantId, estimateDTO.customerId);

View File

@@ -126,8 +126,9 @@ export default class SaleInvoicesService extends SalesInvoicesCost {
await this.customersService.getCustomerByIdOrThrowError(tenantId, saleInvoiceDTO.customerId);
// Validate sale invoice number uniquiness.
await this.validateInvoiceNumberUnique(tenantId, saleInvoiceDTO.invoiceNo);
if (saleInvoiceDTO.invoiceNo) {
await this.validateInvoiceNumberUnique(tenantId, saleInvoiceDTO.invoiceNo);
}
// Validate items ids existance.
await this.itemsEntriesService.validateItemsIdsExistance(tenantId, saleInvoiceDTO.entries);
await this.itemsEntriesService.validateNonSellableEntriesItems(tenantId, saleInvoiceDTO.entries);
@@ -174,8 +175,9 @@ export default class SaleInvoicesService extends SalesInvoicesCost {
await this.customersService.getCustomerByIdOrThrowError(tenantId, saleInvoiceDTO.customerId);
// Validate sale invoice number uniquiness.
await this.validateInvoiceNumberUnique(tenantId, saleInvoiceDTO.invoiceNo, saleInvoiceId);
if (saleInvoiceDTO.invoiceNo) {
await this.validateInvoiceNumberUnique(tenantId, saleInvoiceDTO.invoiceNo, saleInvoiceId);
}
// Validate items ids existance.
await this.itemsEntriesService.validateItemsIdsExistance(tenantId, saleInvoiceDTO.entries);

View File

@@ -127,8 +127,9 @@ export default class SalesReceiptService {
await this.itemsEntriesService.validateNonSellableEntriesItems(tenantId, saleReceiptDTO.entries);
// Validate sale receipt number uniuqiness.
await this.validateReceiptNumberUnique(tenantId, saleReceiptDTO.receiptNumber);
if (saleReceiptDTO.receiptNumber) {
await this.validateReceiptNumberUnique(tenantId, saleReceiptDTO.receiptNumber);
}
this.logger.info('[sale_receipt] trying to insert sale receipt graph.', { tenantId, saleReceiptDTO });
const saleReceipt = await SaleReceipt.query()
.insertGraphAndFetch({
@@ -173,7 +174,9 @@ export default class SalesReceiptService {
await this.itemsEntriesService.validateNonSellableEntriesItems(tenantId, saleReceiptDTO.entries);
// Validate sale receipt number uniuqiness.
await this.validateReceiptNumberUnique(tenantId, saleReceiptDTO.receiptNumber, saleReceiptId);
if (saleReceiptDTO.receiptNumber) {
await this.validateReceiptNumberUnique(tenantId, saleReceiptDTO.receiptNumber, saleReceiptId);
}
const saleReceipt = await SaleReceipt.query()
.upsertGraphAndFetch({