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

@@ -181,9 +181,13 @@ export default class BillsService extends SalesInvoicesCost {
this.logger.info('[bill] trying to create a new bill', { tenantId, billDTO });
const billObj = await this.billDTOToModel(tenantId, billDTO);
// Retrieve vendor or throw not found service error.
await this.getVendorOrThrowError(tenantId, billDTO.vendorId);
await this.validateBillNumberExists(tenantId, billDTO.billNumber);
// Validate the bill number uniqiness on the storage.
if (billDTO.billNumber) {
await this.validateBillNumberExists(tenantId, billDTO.billNumber);
}
// Validate items IDs existance.
await this.itemsEntriesService.validateItemsIdsExistance(tenantId, billDTO.entries);
@@ -237,9 +241,13 @@ export default class BillsService extends SalesInvoicesCost {
const oldBill = await this.getBillOrThrowError(tenantId, billId);
const billObj = await this.billDTOToModel(tenantId, billDTO, oldBill);
// Retrieve vendor details or throw not found service error.
await this.getVendorOrThrowError(tenantId, billDTO.vendorId);
await this.validateBillNumberExists(tenantId, billDTO.billNumber, billId);
// Validate bill number uniqiness on the storage.
if (billDTO.billNumber) {
await this.validateBillNumberExists(tenantId, billDTO.billNumber, billId);
}
await this.itemsEntriesService.validateEntriesIdsExistance(tenantId, billId, 'Bill', billDTO.entries);
await this.itemsEntriesService.validateItemsIdsExistance(tenantId, billDTO.entries);
await this.itemsEntriesService.validateNonPurchasableEntriesItems(tenantId, billDTO.entries);