diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index e5d5f53dc..838d976c7 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -1520,17 +1520,18 @@ INSERT INTO `vn`.`travel`(`id`,`shipped`, `landed`, `warehouseInFk`, `warehouseO INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `isConfirmed`, `companyFk`, `invoiceNumber`, `reference`, `isExcludedFromAvailable`, `evaNotes`, `typeFk`) VALUES - (1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 1, 442, 'IN2001', 'Movement 1', 0, '', 'packaging'), - (2, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 0, 442, 'IN2002', 'Movement 2', 0, 'observation two', 'product'), + (1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 1, 442, 'IN2001', 'Movement 1', 0, '', 'packaging'), + (2, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 0, 442, 'IN2002', 'Movement 2', 0, 'observation two' , 'product'), (3, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 3, 0, 442, 'IN2003', 'Movement 3', 0, 'observation three', 'product'), - (4, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 0, 69, 'IN2004', 'Movement 4', 0, 'observation four', 'product'), - (5, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 0, 442, 'IN2005', 'Movement 5', 0, 'observation five', 'product'), - (6, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 6, 0, 442, 'IN2006', 'Movement 6', 0, 'observation six', 'product'), + (4, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 0, 69, 'IN2004', 'Movement 4', 0, 'observation four' , 'product'), + (5, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 0, 442, 'IN2005', 'Movement 5', 0, 'observation five' , 'product'), + (6, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 6, 0, 442, 'IN2006', 'Movement 6', 0, 'observation six' , 'product'), (7, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'IN2007', 'Movement 7', 0, 'observation seven', 'product'), - (8, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'IN2008', 'Movement 8', 1, '', 'product'), - (9, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY), 10, 0, 442, 'IN2009', 'Movement 9', 1, '', 'product'), - (10, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY), 10, 0, 442, 'IN2009', 'Movement 10', 1, '', 'product'), - (99, 69, util.VN_CURDATE() - INTERVAL 1 MONTH, 11, 0, 442, 'IN2009', 'Movement 99', 0, '', 'product'); + (8, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'IN2008', 'Movement 8', 1, '', 'product'), + (9, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY), 10, 0, 442, 'IN2009', 'Movement 9', 1, '', 'product'), + (10, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY), 10, 0, 442, 'IN2009', 'Movement 10',1, '', 'product'), + (11, 4, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 1, 442, 'IN2001', 'Movement 11',0, '', 'product'), + (99, 69, util.VN_CURDATE() - INTERVAL 1 MONTH, 11, 0, 442, 'IN2009', 'Movement 99',0, '', 'product'); INSERT INTO `vn`.`entryConfig` (`defaultEntry`, `inventorySupplierFk`, `defaultSupplierFk`) VALUES (2, 4, 1); @@ -1570,7 +1571,8 @@ INSERT INTO `bs`.`waste`(`buyerFk`, `year`, `week`, `itemFk`, `itemTypeFk`, `sal (13, 7, 1, 50, 0, 3, 1, 2.000, 2.000, 0.000, 1, 1, 'packing', NULL, 0.00, 99.6, 99.4, 0, 1, 0, 4, util.VN_CURDATE()), (14, 7, 2, 5, 0, 3, 1, 2.000, 2.000, 0.000, 10, 10, 'grouping', NULL, 0.00, 7.30, 7.00, 0, 1, 0, 4, util.VN_CURDATE()), (15, 7, 4, 1.25, 0, 3, 1, 2.000, 2.000, 0.000, 10, 10, 'grouping', NULL, 0.00, 1.75, 1.67, 0, 1, 0, 4, util.VN_CURDATE()), - (16, 99,1,50.0000, 5000, 4, 1, 1.500, 1.500, 0.000, 1, 1, 'packing', NULL, 0.00, 99.60, 99.40, 0, 1, 0, 1.00, '2024-07-30 08:13:51.000'); + (16, 99,1,50.0000, 5000, 4, 1, 1.500, 1.500, 0.000, 1, 1, 'packing', NULL, 0.00, 99.60, 99.40, 0, 1, 0, 1.00, '2024-07-30 08:13:51.000'), + (17, 11, 1, 50, 5000, 4, 1, 1.500, 1.500, 0.000, 1, 1, 'packing', NULL, 0.00, 99.6, 99.4, 0, 1, 0, 1, util.VN_CURDATE() - INTERVAL 2 MONTH); INSERT INTO `hedera`.`order`(`id`, `date_send`, `customer_id`, `delivery_method_id`, `agency_id`, `address_id`, `company_id`, `note`, `source_app`, `confirmed`,`total`, `date_make`, `first_row_stamp`, `confirm_date`) VALUES @@ -4033,3 +4035,8 @@ INSERT IGNORE INTO vn.saySimpleConfig (url, defaultChannel) INSERT INTO vn.workerIrpf (workerFk,spouseNif, geographicMobilityDate) VALUES (1106,'26493101E','2019-09-20'); + + +INSERT IGNORE INTO vn.inventoryConfig + SET id = 1, + supplierFk = 4; \ No newline at end of file diff --git a/db/versions/11352-blackErica/00-firstScript.sql b/db/versions/11352-blackErica/00-firstScript.sql new file mode 100644 index 000000000..4e17c94c5 --- /dev/null +++ b/db/versions/11352-blackErica/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId, editorFk) + VALUES('InventoryConfig', '*', 'READ', 'ALLOW', 'ROLE', 'buyer', 100); \ No newline at end of file diff --git a/modules/entry/back/methods/entry/specs/filter.spec.js b/modules/entry/back/methods/entry/specs/filter.spec.js index 4bf5127b0..b139b00b6 100644 --- a/modules/entry/back/methods/entry/specs/filter.spec.js +++ b/modules/entry/back/methods/entry/specs/filter.spec.js @@ -38,8 +38,9 @@ describe('Entry filter()', () => { }; const result = await models.Entry.filter(ctx, options); + const resultWithCurrency = result.filter(entry => entry.currencyFk === 1); - expect(result.length).toEqual(12); + expect(result.length).toEqual(resultWithCurrency.length); await tx.rollback(); } catch (e) { @@ -141,18 +142,21 @@ describe('Entry filter()', () => { it('should return the entry matching the company', async() => { const tx = await models.Entry.beginTransaction({}); const options = {transaction: tx}; + const companyFk = 442; try { const ctx = { args: { - companyFk: 442 + companyFk }, req: {accessToken: {userId: 9}} }; const result = await models.Entry.filter(ctx, options); - expect(result.length).toEqual(11); + const resultWithCurrency = result.filter(entry => entry.companyFk === companyFk); + + expect(result.length).toEqual(resultWithCurrency.length); await tx.rollback(); } catch (e) { diff --git a/modules/entry/back/model-config.json b/modules/entry/back/model-config.json index 5c45b6e07..49c2df2db 100644 --- a/modules/entry/back/model-config.json +++ b/modules/entry/back/model-config.json @@ -28,5 +28,8 @@ }, "StockBought": { "dataSource": "vn" + }, + "InventoryConfig": { + "dataSource": "vn" } } diff --git a/modules/entry/back/models/inventory-config.json b/modules/entry/back/models/inventory-config.json new file mode 100644 index 000000000..caa39db88 --- /dev/null +++ b/modules/entry/back/models/inventory-config.json @@ -0,0 +1,18 @@ +{ + "name": "InventoryConfig", + "base": "VnModel", + "options": { + "mysql": { + "table": "inventoryConfig" + } + }, + "properties": { + "id": { + "type": "number", + "id": true + }, + "supplierFk": { + "type": "number" + } + } +} diff --git a/modules/item/back/methods/item/lastEntriesFilter.js b/modules/item/back/methods/item/lastEntriesFilter.js index 5aafbb4f6..06c60162f 100644 --- a/modules/item/back/methods/item/lastEntriesFilter.js +++ b/modules/item/back/methods/item/lastEntriesFilter.js @@ -54,7 +54,8 @@ module.exports = Self => { b.packageValue, b.packagingFk , s.id AS supplierFk, - s.name AS supplier + s.name AS supplier, + b.printedStickers FROM itemType it RIGHT JOIN (entry e LEFT JOIN supplier s ON s.id = e.supplierFk diff --git a/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js b/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js index 2fd30c2ca..d4429e158 100644 --- a/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js +++ b/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js @@ -34,10 +34,31 @@ describe('item lastEntriesFilter()', () => { const options = {transaction: tx}; try { - const filter = {where: {itemFk: 1, landed: {between: [minDate, maxDate]}}}; + const itemFk = 1; + const filter = {where: {itemFk, landed: {between: [minDate, maxDate]}}}; const result = await models.Item.lastEntriesFilter(filter, options); + const minDateUtc = new Date(minDate).getTime(); + const maxDateUtc = new Date(maxDate).getTime(); - expect(result.length).toEqual(6); + const resultMatch = ( + await Promise.all( + result.map(async item => { + const itemRecord = await models.Buy.findOne({ + fields: ['id'], + where: {id: item.id}, + options, + }); + + const isItemFkValid = itemRecord?.id === itemFk; + const landedDate = new Date(item.landed).getTime(); + const isLandedValid = landedDate >= minDateUtc && landedDate <= maxDateUtc; + + return isItemFkValid && isLandedValid; + }) + ) + ).filter(Boolean).length; + + expect(result.length).toEqual(resultMatch); await tx.rollback(); } catch (e) { diff --git a/modules/travel/back/methods/travel/specs/getEntries.spec.js b/modules/travel/back/methods/travel/specs/getEntries.spec.js index fcaa80d02..9286a9d55 100644 --- a/modules/travel/back/methods/travel/specs/getEntries.spec.js +++ b/modules/travel/back/methods/travel/specs/getEntries.spec.js @@ -3,9 +3,10 @@ const models = require('vn-loopback/server/server').models; describe('travel getEntries()', () => { const travelId = 1; it('should check the response contains the id', async() => { - const entries = await models.Travel.getEntries(travelId); + const result = await models.Travel.getEntries(travelId); + const entries = await models.Entry.find({where: {travelFk: travelId}}); - expect(entries.length).toEqual(1); + expect(entries.length).toEqual(result.length); expect(entries[0].id).toEqual(1); });