diff --git a/back/methods/docuware/core.js b/back/methods/docuware/core.js index 3de33b786..74d922236 100644 --- a/back/methods/docuware/core.js +++ b/back/methods/docuware/core.js @@ -4,45 +4,21 @@ module.exports = Self => { /** * Returns basic headers * + * @param {string} cookie - The docuware cookie * @return {object} - The headers */ Self.getOptions = async() => { const docuwareConfig = await Self.app.models.DocuwareConfig.findOne(); - const now = Date.vnNow(); - let {url, username, password, token, expired} = docuwareConfig; - - if (process.env.NODE_ENV && (!expired || expired < now + 60)) { - const {data: {IdentityServiceUrl}} = await axios.get(`${url}/Home/IdentityServiceInfo`); - const {data: {token_endpoint}} = await axios.get(`${IdentityServiceUrl}/.well-known/openid-configuration`); - const {data} = await axios.post(token_endpoint, { - grant_type: 'password', - scope: 'docuware.platform', - client_id: 'docuware.platform.net.client', - username, - password - }, {headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/x-www-form-urlencoded' - }}); - - const newToken = data.access_token; - token = data.token_type + ' ' + newToken; - await docuwareConfig.updateAttributes({ - token, - expired: now + data.expires_in - }); - } - const headers = { headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', - 'Authorization': token + 'Cookie': docuwareConfig.cookie } }; return { - url, + url: docuwareConfig.url, headers }; }; diff --git a/back/methods/docuware/specs/core.spec.js b/back/methods/docuware/specs/core.spec.js index 47580483d..cdf8a3b62 100644 --- a/back/methods/docuware/specs/core.spec.js +++ b/back/methods/docuware/specs/core.spec.js @@ -2,54 +2,87 @@ const axios = require('axios'); const models = require('vn-loopback/server/server').models; describe('Docuware core', () => { - const fileCabinetCode = 'deliveryNote'; - beforeAll(async() => { + beforeAll(() => { process.env.NODE_ENV = 'testing'; + }); - const docuwareInfo = await models.Docuware.findOne({ - where: { - code: fileCabinetCode - } + afterAll(() => { + delete process.env.NODE_ENV; + }); + + describe('getOptions()', () => { + it('should return url and headers', async() => { + const result = await models.Docuware.getOptions(); + + expect(result.url).toBeDefined(); + expect(result.headers).toBeDefined(); }); + }); - spyOn(axios, 'get').and.callFake(url => { - if (url.includes('IdentityServiceInfo')) return {data: {IdentityServiceUrl: 'IdentityServiceUrl'}}; - if (url.includes('IdentityServiceUrl')) return {data: {token_endpoint: 'token_endpoint'}}; - if (url.includes('dialogs')) { - return { - data: { - Dialog: [ - { - DisplayName: 'find', - Id: 'getDialogTest' - } - ] - } - }; - } + describe('getDialog()', () => { + it('should return dialogId', async() => { + const dialogs = { + data: { + Dialog: [ + { + DisplayName: 'find', + Id: 'getDialogTest' + } + ] + } + }; + spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(dialogs))); + const result = await models.Docuware.getDialog('deliveryNote', 'find', 'randomFileCabinetId'); - if (url.includes('FileCabinets')) { - return {data: { + expect(result).toEqual('getDialogTest'); + }); + }); + + describe('getFileCabinet()', () => { + it('should return fileCabinetId', async() => { + const code = 'deliveryNote'; + const docuwareInfo = await models.Docuware.findOne({ + where: { + code + } + }); + const dialogs = { + data: { FileCabinet: [ { Name: docuwareInfo.fileCabinetName, Id: 'getFileCabinetTest' } ] - }}; - } + } + }; + spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(dialogs))); + const result = await models.Docuware.getFileCabinet(code); + + expect(result).toEqual('getFileCabinetTest'); + }); + }); + + describe('get()', () => { + it('should return data without parse', async() => { + spyOn(models.Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random())))); + spyOn(models.Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random())))); + const data = { + data: { + id: 1 + } + }; + spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data))); + const result = await models.Docuware.get('deliveryNote'); + + expect(result.id).toEqual(1); }); - spyOn(axios, 'post').and.callFake(url => { - if (url.includes('token_endpoint')) { - return {data: { - access_token: 'access_token', - token_type: 'bearer', - expires_in: 10000 - }}; - } - if (url.includes('DialogExpression')) { - return {data: { + it('should return data with parse', async() => { + spyOn(models.Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random())))); + spyOn(models.Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random())))); + const data = { + data: { Items: [{ Fields: [ { @@ -70,52 +103,12 @@ describe('Docuware core', () => { ] }] } - }; - } - }); - }); - - afterAll(() => { - delete process.env.NODE_ENV; - }); - - describe('getOptions()', () => { - it('should return url and headers', async() => { - const result = await models.Docuware.getOptions(); - - expect(result.url).toBeDefined(); - expect(result.headers).toBeDefined(); - }); - }); - - describe('Dialog()', () => { - it('should return dialogId', async() => { - const result = await models.Docuware.getDialog('deliveryNote', 'find', 'randomFileCabinetId'); - - expect(result).toEqual('getDialogTest'); - }); - }); - - describe('getFileCabinet()', () => { - it('should return fileCabinetId', async() => { - const result = await models.Docuware.getFileCabinet(fileCabinetCode); - - expect(result).toEqual('getFileCabinetTest'); - }); - }); - - describe('get()', () => { - it('should return data without parse', async() => { - const [result] = await models.Docuware.get('deliveryNote'); - - expect(result.firstRequiredField).toEqual(1); - }); - - it('should return data with parse', async() => { + }; const parse = { 'firstRequiredField': 'id', 'secondRequiredField': 'name', }; + spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data))); const [result] = await models.Docuware.get('deliveryNote', null, parse); expect(result.id).toEqual(1); @@ -126,14 +119,17 @@ describe('Docuware core', () => { describe('getById()', () => { it('should return data', async() => { - spyOn(models.Docuware, 'get'); - await models.Docuware.getById('deliveryNote', 1); + spyOn(models.Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random())))); + spyOn(models.Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random())))); + const data = { + data: { + id: 1 + } + }; + spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data))); + const result = await models.Docuware.getById('deliveryNote', 1); - expect(models.Docuware.get).toHaveBeenCalledWith( - 'deliveryNote', - {condition: [Object({DBName: 'N__ALBAR_N', Value: [1]})]}, - undefined - ); + expect(result.id).toEqual(1); }); }); }); diff --git a/back/methods/docuware/upload.js b/back/methods/docuware/upload.js index 5b35b7598..0102911e0 100644 --- a/back/methods/docuware/upload.js +++ b/back/methods/docuware/upload.js @@ -143,7 +143,7 @@ module.exports = Self => { headers: { 'Content-Type': 'multipart/form-data', 'X-File-ModifiedDate': Date.vnNew(), - 'Authorization': docuwareOptions.headers.headers.Authorization, + 'Cookie': docuwareOptions.headers.headers.Cookie, ...data.getHeaders() }, }; diff --git a/back/methods/mrw-config/createShipment.ejs b/back/methods/mrw-config/createShipment.ejs index 52ccc859c..5f15aa054 100644 --- a/back/methods/mrw-config/createShipment.ejs +++ b/back/methods/mrw-config/createShipment.ejs @@ -41,7 +41,7 @@ <%= mrw.defaultHeight %> <%= mrw.defaultLength %> <%= mrw.defaultWidth %> - <%= mrw.defaultWeight %> + <%= expeditionData.kg %> diff --git a/back/methods/mrw-config/createShipment.js b/back/methods/mrw-config/createShipment.js index 2ebb80774..1057d728a 100644 --- a/back/methods/mrw-config/createShipment.js +++ b/back/methods/mrw-config/createShipment.js @@ -53,7 +53,8 @@ module.exports = Self => { CONCAT( e.ticketFk, LPAD(e.counter, mc.counterWidth, '0')) reference, LPAD(IF(mw.serviceType IS NULL, ms.serviceType, mw.serviceType), mc.serviceTypeWidth, '0') serviceType, IF(mw.weekdays, 'S', 'N') weekDays, - ta.description deliveryObservation + ta.description deliveryObservation, + ms.kg FROM expedition e JOIN ticket t ON e.ticketFk = t.id JOIN agencyMode am ON am.id = t.agencyModeFk diff --git a/back/methods/vn-user/specs/renew-token.spec.js b/back/methods/vn-user/specs/renew-token.spec.js index 8941916ec..8f1bb54c1 100644 --- a/back/methods/vn-user/specs/renew-token.spec.js +++ b/back/methods/vn-user/specs/renew-token.spec.js @@ -72,9 +72,9 @@ describe('Renew Token', () => { } expect(error).toBeDefined(); + const query = 'SELECT * FROM util.debug'; - const query = 'SELECT * FROM util.debug WHERE variable = "renewToken"'; - const debugLog = await models.Application.rawSql(query); + const debugLog = await models.Application.rawSql(query, null); expect(debugLog.length).toEqual(1); }); diff --git a/back/models/docuware-config.json b/back/models/docuware-config.json index b15cb4c03..9d06c4874 100644 --- a/back/models/docuware-config.json +++ b/back/models/docuware-config.json @@ -16,17 +16,17 @@ "url": { "type": "string" }, - "token": { + "cookie": { "type": "string" - }, - "username": { - "type": "string" - }, - "password": { - "type": "string" - }, - "expired":{ - "type": "number" } - } + }, + "acls": [ + { + "property": "*", + "accessType": "*", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + } + ] } diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index a667b6d27..5076f9330 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -403,7 +403,7 @@ INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city (1112, 'Trash', NULL, 'GARBAGE MAN', 'Unknown name', 'NEW YORK CITY, UNDERGROUND', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 0, 1, 0, NULL, 1, 0, NULL, 0, 'others','loses'); INSERT INTO `vn`.`client`(`id`, `name`, `fi`, `socialName`, `contact`, `street`, `city`, `postcode`, `isRelevant`, `email`, `iban`,`dueDay`,`accountingAccount`, `isEqualizated`, `provinceFk`, `hasToInvoice`, `credit`, `countryFk`, `isActive`, `gestdocFk`, `quality`, `payMethodFk`,`created`, `isTaxDataChecked`) - SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), UPPER(CONCAT(name, 'Social')), CONCAT(name, 'Contact'), UPPER(CONCAT(name, 'Street')), 'GOTHAM', 46460, 1, CONCAT(name,'@mydomain.com'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5, util.VN_CURDATE(), 1 + SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), UPPER(CONCAT(name, 'Social')), CONCAT(name, 'Contact'), CONCAT(name, 'Street'), 'GOTHAM', 46460, 1, CONCAT(name,'@mydomain.com'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5, util.VN_CURDATE(), 1 FROM `account`.`role` `r` WHERE `r`.`hasLogin` = 1; diff --git a/db/routines/vn/events/itemCampaign_add.sql b/db/routines/vn/events/itemCampaign_add.sql deleted file mode 100644 index efb2aeb11..000000000 --- a/db/routines/vn/events/itemCampaign_add.sql +++ /dev/null @@ -1,8 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` EVENT `vn`.`itemCampaig_add` - ON SCHEDULE EVERY 1 DAY - STARTS '2024-10-18 03:00:00.000' - ON COMPLETION PRESERVE - ENABLE -DO CALL itemCampaign_add()$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/collection_addWithReservation.sql b/db/routines/vn/procedures/collection_addWithReservation.sql index bb6e94a63..cc0b7fd9b 100644 --- a/db/routines/vn/procedures/collection_addWithReservation.sql +++ b/db/routines/vn/procedures/collection_addWithReservation.sql @@ -37,23 +37,23 @@ BEGIN WHERE t.id = vTicketFk; CALL cache.available_refresh( - vCacheAvailableFk, + vCacheAvailableFk, FALSE, - vWarehouseFk, + vWarehouseFk, util.VN_CURDATE()); SELECT available INTO vAvailable FROM cache.available - WHERE calc_id = vCacheAvailableFk + WHERE calc_id = vCacheAvailableFk AND item_id = vItemFk; - + IF vAvailable < vQuantity THEN SET vHasThrow = TRUE; ELSE SELECT `name`, - CONCAT(getUser(), ' ', DATE_FORMAT(util.VN_NOW(), '%H:%i'), ' ', name) + CONCAT(getUser(), ' ', DATE_FORMAT(util.VN_NOW(), '%H:%i'), ' ', name) INTO vItemName, vConcept - FROM item + FROM item WHERE id = vItemFk; START TRANSACTION; @@ -69,7 +69,7 @@ BEGIN CALL sale_calculateComponent(vSaleFk, NULL); CALL itemShelvingSale_addBySale(vSaleFk, vSectorFk); - + IF NOT EXISTS (SELECT TRUE FROM itemShelvingSale WHERE saleFk = vSaleFk LIMIT 1) THEN SET vHasThrow = TRUE; END IF; @@ -78,13 +78,13 @@ BEGIN IF vHasThrow THEN CALL util.throw("There is no available for the selected item"); END IF; - + IF vSaleGroupFk THEN INSERT INTO saleGroupDetail SET saleFk = vSaleFk, saleGroupFk = vSaleGroupFk; END IF; - + COMMIT; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/itemCampaign_add.sql b/db/routines/vn/procedures/itemCampaign_add.sql deleted file mode 100644 index 8fb40df67..000000000 --- a/db/routines/vn/procedures/itemCampaign_add.sql +++ /dev/null @@ -1,54 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemCampaign_add`() -proc: BEGIN -/** - * Añade registros a tabla itemCampaign. - * - * @param vDateFrom Fecha desde - * @param vDateTo Fecha hasta - * @param vCampaign Código de la campaña - */ - DECLARE vYesterday DATE; - DECLARE vCampaign VARCHAR(100); - DECLARE vScopeDays INT; - DECLARE vPreviousDays INT; - DECLARE vDateSumFrom DATE; - DECLARE vDateSumTo DATE; - - SET vYesterday = util.yesterday(); - - SELECT dated, code, scopeDays, previousDays - INTO vDateSumTo, vCampaign, vScopeDays, vPreviousDays - FROM campaign - WHERE dated >= vYesterday - ORDER BY dated - LIMIT 1; - - IF vCampaign IS NULL THEN - CALL util.throw('Missing data in campaign table'); - END IF; - - IF NOT vYesterday BETWEEN vDateSumTo - INTERVAL vPreviousDays DAY - AND vDateSumTo THEN - LEAVE proc; - END IF; - - SET vDateSumFrom = vDateSumTo - INTERVAL vScopeDays DAY; - SET vDateSumTo = vDateSumTo - INTERVAL 1 DAY; - - INSERT INTO itemCampaign(dated, itemFk, quantity, total, campaign) - SELECT vYesterday, - s.itemFk, - SUM(s.quantity) quantity, - SUM((s.quantity * s.price) * (100 - s.discount) / 100) total, - vCampaign - FROM sale s - JOIN ticket t ON t.id = s.ticketFk - JOIN client c ON c.id = t.clientFk - WHERE t.shipped BETWEEN vDateSumFrom AND util.dayEnd(vDateSumTo) - AND c.typeFk = 'normal' - AND NOT t.isDeleted - GROUP BY s.itemFk - HAVING quantity; -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingSale_addBySale.sql b/db/routines/vn/procedures/itemShelvingSale_addBySale.sql index 06736732a..6625e89b8 100644 --- a/db/routines/vn/procedures/itemShelvingSale_addBySale.sql +++ b/db/routines/vn/procedures/itemShelvingSale_addBySale.sql @@ -18,9 +18,8 @@ proc: BEGIN DECLARE vReservedQuantity INT; DECLARE vOutStanding INT; DECLARE vUserFk INT; - DECLARE vTotalReservedQuantity INT; + DECLARE vTotalReservedQuantity INT; DECLARE vSaleQuantity INT; - DECLARE vIsRequiredTx BOOL DEFAULT NOT @@in_transaction; DECLARE vItemShelvingAvailable CURSOR FOR SELECT ish.id itemShelvingFk, @@ -30,7 +29,7 @@ proc: BEGIN JOIN shelving sh ON sh.code = ish.shelvingFk JOIN parking p ON p.id = sh.parkingFk JOIN sector sc ON sc.id = p.sectorFk - JOIN productionConfig pc + JOIN productionConfig pc WHERE s.id = vSaleFk AND NOT sc.isHideForPickers AND (sc.id = vSectorFk OR vSectorFk IS NULL) @@ -45,15 +44,15 @@ proc: BEGIN DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN - CALL util.tx_rollback(vIsRequiredTx); + ROLLBACK; RESIGNAL; END; - - CALL util.tx_start(vIsRequiredTx); - + + START TRANSACTION; + SELECT id INTO vSaleFk FROM sale - WHERE id = vSaleFk + WHERE id = vSaleFk FOR UPDATE; SELECT MAX(p.pickingOrder), s.quantity - SUM(IFNULL(iss.quantity, 0)), s.quantity @@ -66,7 +65,7 @@ proc: BEGIN WHERE s.id = vSaleFk; IF vOutStanding <= 0 THEN - CALL util.tx_commit(vIsRequiredTx); + COMMIT; LEAVE proc; END IF; @@ -86,7 +85,7 @@ proc: BEGIN IF vTotalReservedQuantity <> vSaleQuantity THEN CALL util.debugAdd('itemShelvingSale_addBySale', CONCAT(vSaleFk, ' - ', vSaleQuantity,' - ', vTotalReservedQuantity,'-', vOutStanding,'-', account.myUser_getId())); - + UPDATE sale SET quantity = vTotalReservedQuantity WHERE id = vSaleFk; @@ -94,7 +93,7 @@ proc: BEGIN LEAVE l; END IF; - SELECT id INTO vItemShelvingFk + SELECT id INTO vItemShelvingFk FROM itemShelving WHERE id = vItemShelvingFk FOR UPDATE; @@ -103,19 +102,19 @@ proc: BEGIN SET vOutStanding = vOutStanding - vReservedQuantity; IF vReservedQuantity > 0 THEN - CALL util.debugAdd('itemShelvingSale_addBySale_reservedQuantity', - CONCAT(vSaleFk, ' - ', vReservedQuantity, ' - ', vOutStanding, account.myUser_getId())); - INSERT INTO itemShelvingSale( - itemShelvingFk, - saleFk, - quantity, - userFk, - isPicked) - SELECT vItemShelvingFk, - vSaleFk, - vReservedQuantity, - vUserFk, - FALSE; + CALL util.debugAdd('itemShelvingSale_addBySale_reservedQuantity', + CONCAT(vSaleFk, ' - ', vReservedQuantity, ' - ', vOutStanding, account.myUser_getId())); + INSERT INTO itemShelvingSale( + itemShelvingFk, + saleFk, + quantity, + userFk, + isPicked) + SELECT vItemShelvingFk, + vSaleFk, + vReservedQuantity, + vUserFk, + FALSE; UPDATE itemShelving SET available = available - vReservedQuantity @@ -124,6 +123,6 @@ proc: BEGIN END IF; END LOOP; CLOSE vItemShelvingAvailable; - CALL util.tx_commit(vIsRequiredTx); + COMMIT; END$$ DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/item_getSimilar.sql b/db/routines/vn/procedures/item_getSimilar.sql index 336f3521e..537f53848 100644 --- a/db/routines/vn/procedures/item_getSimilar.sql +++ b/db/routines/vn/procedures/item_getSimilar.sql @@ -24,7 +24,6 @@ BEGIN CALL cache.available_refresh(vAvailableCalcFk, FALSE, vWarehouseFk, vDated); CALL cache.visible_refresh(vVisibleCalcFk, FALSE, vWarehouseFk); - CALL buy_getUltimate(NULL, vWarehouseFk, vDated); WITH itemTags AS ( SELECT i.id, @@ -75,13 +74,14 @@ BEGIN AND a.calc_id = vAvailableCalcFk LEFT JOIN cache.visible v ON v.item_id = i.id AND v.calc_id = vVisibleCalcFk - LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = i.id + LEFT JOIN cache.last_buy lb ON lb.item_id = i.id + AND lb.warehouse_id = vWarehouseFk LEFT JOIN vn.itemProposal ip ON ip.mateFk = i.id AND ip.itemFk = vSelf LEFT JOIN vn.itemTag it ON it.itemFk = i.id AND it.priority = vPriority LEFT JOIN vn.tag t ON t.id = it.tagFk - LEFT JOIN vn.buy b ON b.id = bu.buyFk + LEFT JOIN vn.buy b ON b.id = lb.buy_id JOIN itemTags its WHERE a.available > 0 AND (i.typeFk = its.typeFk OR NOT vShowType) @@ -98,7 +98,5 @@ BEGIN (i.tag8 = its.tag8) DESC, match8 DESC LIMIT 100; - - DROP TEMPORARY TABLE tmp.buyUltimate; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/saleTracking_sectorCollectionAddPrevOK.sql b/db/routines/vn/procedures/saleTracking_sectorCollectionAddPrevOK.sql deleted file mode 100644 index 003168ec8..000000000 --- a/db/routines/vn/procedures/saleTracking_sectorCollectionAddPrevOK.sql +++ /dev/null @@ -1,20 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`saleTracking_sectorCollectionAddPrevOK`( - vSectorCollectionFk INT -) -BEGIN -/** - * Inserta los registros de sectorCollection con el estado PREVIA OK si la reserva está picked - * - * @param vSectorCollectionFk Identificador de vn.sectorCollection - */ - REPLACE saleTracking(saleFk, isChecked, workerFk, stateFk) - SELECT sgd.saleFk, TRUE, sc.userFk, s.id - FROM sectorCollection sc - JOIN sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id - JOIN saleGroupDetail sgd ON sgd.saleGroupFk = scsg.saleGroupFk - JOIN state s ON s.code = 'OK PREVIOUS' - JOIN itemShelvingSale iss ON iss.saleFk = sgd.saleFk - WHERE sc.id = vSectorCollectionFk AND iss.isPicked; -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_canAdvance.sql b/db/routines/vn/procedures/ticket_canAdvance.sql index e8fc70bba..57c3f4235 100644 --- a/db/routines/vn/procedures/ticket_canAdvance.sql +++ b/db/routines/vn/procedures/ticket_canAdvance.sql @@ -51,8 +51,7 @@ BEGIN origin.companyFk futureCompanyFk, IFNULL(dest.nickname, origin.nickname) nickname, dest.landed, - dest.preparation, - origin.departmentFk + dest.preparation FROM ( SELECT s.ticketFk, c.salesPersonFk workerFk, @@ -72,11 +71,9 @@ BEGIN t.addressFk, t.warehouseFk, t.companyFk, - t.agencyModeFk, - wd.departmentFk + t.agencyModeFk FROM ticket t JOIN client c ON c.id = t.clientFk - JOIN workerDepartment wd ON wd.workerFk = c.salesPersonFk JOIN sale s ON s.ticketFk = t.id JOIN saleVolume sv ON sv.saleFk = s.id JOIN item i ON i.id = s.itemFk diff --git a/db/versions/11291-purpleChico/00-firstScript.sql b/db/versions/11291-purpleChico/00-firstScript.sql deleted file mode 100644 index e60b90376..000000000 --- a/db/versions/11291-purpleChico/00-firstScript.sql +++ /dev/null @@ -1,4 +0,0 @@ -ALTER TABLE vn.docuwareConfig ADD IF NOT EXISTS username varchar(100) NULL; -ALTER TABLE vn.docuwareConfig ADD IF NOT EXISTS password varchar(100) NULL; -ALTER TABLE vn.docuwareConfig ADD IF NOT EXISTS token text NULL; -ALTER TABLE vn.docuwareConfig ADD IF NOT EXISTS expired int(11) NULL; diff --git a/db/versions/11300-limeMedeola/00-firstScript.sql b/db/versions/11300-limeMedeola/00-firstScript.sql deleted file mode 100644 index 28b033b4a..000000000 --- a/db/versions/11300-limeMedeola/00-firstScript.sql +++ /dev/null @@ -1,137 +0,0 @@ -CREATE TABLE IF NOT EXISTS `vn`.`itemFarmingTag` ( - `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, - `name` varchar(50) DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `name_UNIQUE` (`name`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT - CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; - -INSERT IGNORE INTO `vn`.`itemFarmingTag` (`name`) VALUES ('Enraizado'); - -UPDATE vn.tag - SET isFree=0, - sourceTable='itemFarmingTag' - WHERE name= 'cultivo'; - -CREATE TABLE IF NOT EXISTS `vn`.`itemWrappingTag` ( - `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, - `name` varchar(50) DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `name_UNIQUE` (`name`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT - CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; - -INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Bolsa'); -INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Caja cartón'); -INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Caja decorativa'); -INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Celofán'); -INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Papel kraft'); -INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Plástico'); -INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Variable'); - -UPDATE vn.tag - SET isFree=0, - sourceTable='itemWrappingTag' - WHERE name= 'Envoltorio'; - -CREATE TABLE IF NOT EXISTS `vn`.`itemLanguageTag` ( - `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, - `name` varchar(50) DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `name_UNIQUE` (`name`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT - CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; - -INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Castellano'); -INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Catalán'); -INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Euskera'); -INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Francés'); -INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Gallego'); -INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Inglés'); -INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Portugués'); - -UPDATE vn.tag - SET isFree=0, - sourceTable='itemLanguageTag' - WHERE name= 'Idioma'; - -CREATE TABLE IF NOT EXISTS `vn`.`itemStemTag` ( - `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, - `name` varchar(50) DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `name_UNIQUE` (`name`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT - CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; - -INSERT IGNORE INTO `vn`.`itemStemTag` (`name`) VALUES ('Natural'); -INSERT IGNORE INTO `vn`.`itemStemTag` (`name`) VALUES ('Seminatural'); -INSERT IGNORE INTO `vn`.`itemStemTag` (`name`) VALUES ('Sintético'); - -UPDATE vn.tag - SET isFree=0, - sourceTable='itemStemTag' - WHERE name= 'Tronco'; - - -CREATE TABLE IF NOT EXISTS `vn`.`itemBreederTag` ( - `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, - `name` varchar(50) DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `name_UNIQUE` (`name`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT - CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; - -INSERT IGNORE INTO `vn`.`itemBreederTag` (`name`) VALUES ('David Austin'); - -UPDATE vn.tag - SET isFree=0, - sourceTable='itemBreederTag' - WHERE name= 'Obtentor'; - -CREATE TABLE IF NOT EXISTS `vn`.`itemBaseTag` ( - `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, - `name` varchar(50) DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `name_UNIQUE` (`name`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT - CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; - -INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Biodegradable'); -INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Caballete'); -INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Cerámica'); -INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Cristal'); -INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Plástico por inyección'); -INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Madera'); -INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Plástico'); -INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Rígido'); -INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Ruedas'); -INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Sin soporte rígido'); - -UPDATE vn.tag - SET isFree=0, - sourceTable='itemBaseTag' - WHERE name= 'Soporte'; - -CREATE TABLE IF NOT EXISTS `vn`.`itemVatRateTag` ( - `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, - `name` varchar(50) DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `name_UNIQUE` (`name`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT - CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; - -INSERT IGNORE INTO `vn`.`itemVatRateTag` (`name`) VALUES ('General'); -INSERT IGNORE INTO `vn`.`itemVatRateTag` (`name`) VALUES ('Reducido'); - -UPDATE vn.tag - SET isFree=0, - sourceTable='itemVatRateTag' - WHERE name= 'Tipo de IVA'; - -GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemFarmingTag TO logisticAssist; -GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemWrappingTag TO logisticAssist; -GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemLanguageTag TO logisticAssist; -GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemStemTag TO logisticAssist; -GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemWrappingTag TO logisticAssist; -GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemBaseTag TO logisticAssist; -GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemBreederTag TO logisticAssist; \ No newline at end of file diff --git a/db/versions/11308-redCymbidium/00-firstScript.sql b/db/versions/11308-redCymbidium/00-firstScript.sql deleted file mode 100644 index fe76cb600..000000000 --- a/db/versions/11308-redCymbidium/00-firstScript.sql +++ /dev/null @@ -1,25 +0,0 @@ -CREATE TABLE IF NOT EXISTS `vn`.`itemCampaign` ( - `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, - dated date NOT NULL, - itemFk int(11) NOT NULL, - quantity decimal(10,2) NOT NULL, - total decimal(10,2) NOT NULL, - campaign varchar(100) NOT NULL, - UNIQUE KEY `itemCampaign_UNIQUE` (`dated`,`itemFk`), - CONSTRAINT itemCampaign_item_FK FOREIGN KEY (itemFk) REFERENCES vn.item(id) ON DELETE RESTRICT ON UPDATE CASCADE -) -ENGINE=InnoDB -DEFAULT CHARSET=utf8mb3 -COLLATE=utf8mb3_unicode_ci -COMMENT='Tallos confirmados por día en los días de más producción de una campaña. La tabla está pensada para que sea una foto.'; - -ALTER TABLE vn.campaign - ADD previousDays int(10) unsigned DEFAULT 30 NOT NULL COMMENT 'Días previos para calcular e insertar en la tabla itemCampaign'; - -UPDATE vn.campaign - SET previousDays = 90 - WHERE code = 'allSaints'; - -UPDATE vn.campaign - SET previousDays = 60 - WHERE code IN ('valentinesDay', 'mothersDay'); diff --git a/modules/ticket/back/methods/expedition-state/filter.js b/modules/ticket/back/methods/expedition-state/filter.js index 3a4e7a87c..1483780f7 100644 --- a/modules/ticket/back/methods/expedition-state/filter.js +++ b/modules/ticket/back/methods/expedition-state/filter.js @@ -29,7 +29,7 @@ module.exports = Self => { Object.assign(myOptions, options); const stmt = new ParameterizedSQL( - `SELECT es.created, u.name, u.id workerFk, est.description state, es.isScanned + `SELECT es.created, u.name, u.id workerFk, est.description state FROM vn.expeditionState es JOIN vn.expeditionStateType est ON est.id = es.typeFk JOIN account.user u ON u.id = es.userFk diff --git a/modules/ticket/back/methods/sale/recalculatePrice.js b/modules/ticket/back/methods/sale/recalculatePrice.js index ea71032d0..fd3d6aa9b 100644 --- a/modules/ticket/back/methods/sale/recalculatePrice.js +++ b/modules/ticket/back/methods/sale/recalculatePrice.js @@ -48,7 +48,7 @@ module.exports = Self => { CALL vn.sale_recalcComponent(null); DROP TEMPORARY TABLE tmp.recalculateSales;`; - const recalculation = await Self.rawSql(query, [salesIds], myOptions); + const recalculation = await Self.rawSql(query, salesIds, myOptions); if (tx) await tx.commit(); diff --git a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js index 100f74bf0..9d1403df0 100644 --- a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js +++ b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js @@ -85,25 +85,6 @@ describe('sale updatePrice()', () => { } }); - it('should check if priceFixed has changed', async() => { - const tx = await models.Sale.beginTransaction({}); - - try { - const options = {transaction: tx}; - - const price = 3; - const beforeUpdate = await models.Sale.findById(saleId, null, options); - await models.Sale.updatePrice(ctx, saleId, price, options); - const afterUpdate = await models.Sale.findById(saleId, null, options); - - expect(beforeUpdate.priceFixed).not.toEqual(afterUpdate.priceFixed); - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); - it('should set price as a decimal number and check the sale has the mana component changing the salesPersonMana', async() => { const tx = await models.Sale.beginTransaction({}); diff --git a/modules/ticket/back/methods/sale/updatePrice.js b/modules/ticket/back/methods/sale/updatePrice.js index d4f128082..191fd09e3 100644 --- a/modules/ticket/back/methods/sale/updatePrice.js +++ b/modules/ticket/back/methods/sale/updatePrice.js @@ -91,21 +91,7 @@ module.exports = Self => { value: componentValue }, myOptions); } - - const [priceFixed] = await Self.rawSql(` - SELECT SUM(value) value - FROM sale s - JOIN saleComponent sc ON sc.saleFk = s.id - JOIN component c ON c.id = sc.componentFk - JOIN componentType ct ON ct.id = c.typeFk - WHERE ct.isBase - AND s.id = ? - `, [id], myOptions); - - await sale.updateAttributes({ - price: newPrice, - priceFixed: priceFixed.value - }, myOptions); + await sale.updateAttributes({price: newPrice}, myOptions); await Self.rawSql('CALL vn.manaSpellersRequery(?)', [userId], myOptions); await Self.rawSql('CALL vn.ticket_recalc(?, NULL)', [sale.ticketFk], myOptions); diff --git a/modules/ticket/back/methods/ticket/getTicketsAdvance.js b/modules/ticket/back/methods/ticket/getTicketsAdvance.js index 41f3ee79a..1bd5f83de 100644 --- a/modules/ticket/back/methods/ticket/getTicketsAdvance.js +++ b/modules/ticket/back/methods/ticket/getTicketsAdvance.js @@ -50,11 +50,6 @@ module.exports = Self => { type: 'boolean', description: 'True when lines and stock of origin are equal' }, - { - arg: 'departmentFk', - type: 'number', - description: 'Department identifier' - }, { arg: 'filter', type: 'object', @@ -101,8 +96,6 @@ module.exports = Self => { }; case 'isFullMovable': return {'f.isFullMovable': value}; - case 'departmentFk': - return {'f.departmentFk': value}; } }); diff --git a/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js b/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js index a941013cd..488cd1fc2 100644 --- a/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js +++ b/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js @@ -6,9 +6,6 @@ describe('TicketFuture getTicketsAdvance()', () => { today.setHours(0, 0, 0, 0); let tomorrow = Date.vnNew(); tomorrow.setDate(today.getDate() + 1); - const salesDeptId = 43; - const spain1DeptId = 95; - beforeAll.mockLoopBackContext(); it('should return the tickets passing the required data', async() => { const tx = await models.Ticket.beginTransaction({}); @@ -132,39 +129,4 @@ describe('TicketFuture getTicketsAdvance()', () => { throw e; } }); - - it('should return the tickets matching the right department', async() => { - const tx = await models.Ticket.beginTransaction({}); - - try { - const options = {transaction: tx}; - ctx.args = { - dateFuture: tomorrow, - dateToAdvance: today, - warehouseFk: 1, - }; - - await models.Ticket.updateAll({id: {inq: [12, 31]}}, {clientFk: 1}, options); - const client = await models.Client.findById(1, null, options); - await client.updateAttribute('salesPersonFk', 1, options); - const business = await models.Business.findById(1, null, options); - await business.updateAttributes({departmentFk: spain1DeptId}, options); - - const saleTickets = await models.Ticket.getTicketsAdvance(ctx, options); - const filteredSaleTickets = await models.Ticket.getTicketsAdvance( - {args: {...ctx.args, departmentFk: spain1DeptId}}, - options); - - expect(saleTickets.length).toBeGreaterThan(filteredSaleTickets.length); - expect(saleTickets.some(ticket => ticket.departmentFk === salesDeptId)).toBeTrue(); - expect(saleTickets.some(ticket => ticket.departmentFk === spain1DeptId)).toBeTrue(); - - expect(filteredSaleTickets.some(ticket => ticket.departmentFk === salesDeptId)).toBeFalse(); - expect(filteredSaleTickets.some(ticket => ticket.departmentFk === spain1DeptId)).toBeTrue(); - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); }); diff --git a/modules/ticket/back/models/expedition.json b/modules/ticket/back/models/expedition.json index f3f912ec3..2dcca1e87 100644 --- a/modules/ticket/back/models/expedition.json +++ b/modules/ticket/back/models/expedition.json @@ -1,66 +1,63 @@ { - "name": "Expedition", - "base": "VnModel", - "mixins": { - "Loggable": true - }, - "options": { - "mysql": { - "table": "expedition" - } - }, - "properties": { - "id": { - "id": true, - "type": "number", - "description": "Identifier" + "name": "Expedition", + "base": "VnModel", + "mixins": { + "Loggable": true }, - "freightItemFk": { - "type": "number" + "options": { + "mysql": { + "table": "expedition" + } }, - "created": { - "type": "date" + "properties": { + "id": { + "id": true, + "type": "number", + "description": "Identifier" + }, + "freightItemFk": { + "type": "number" + }, + "created": { + "type": "date" + }, + "counter": { + "type": "number" + }, + "externalId": { + "type": "string" + } }, - "counter": { - "type": "number" - }, - "externalId": { - "type": "string" - }, - "stateTypeFk": { - "type": "number" - } - }, - "relations": { - "ticket": { - "type": "belongsTo", - "model": "Ticket", - "foreignKey": "ticketFk" - }, - "agencyMode": { - "type": "belongsTo", - "model": "AgencyMode", - "foreignKey": "agencyModeFk" - }, - "worker": { - "type": "belongsTo", - "model": "Worker", - "foreignKey": "workerFk" - }, - "packages": { - "type": "hasMany", - "model": "TicketPackaging", - "foreignKey": "ticketFk" - }, - "freightItem": { - "type": "belongsTo", - "model": "Item", - "foreignKey": "freightItemFk" - }, - "packaging": { - "type": "belongsTo", - "model": "Package", - "foreignKey": "packagingFk" + "relations": { + "ticket": { + "type": "belongsTo", + "model": "Ticket", + "foreignKey": "ticketFk" + }, + "agencyMode": { + "type": "belongsTo", + "model": "AgencyMode", + "foreignKey": "agencyModeFk" + }, + "worker": { + "type": "belongsTo", + "model": "Worker", + "foreignKey": "workerFk" + }, + "packages": { + "type": "hasMany", + "model": "TicketPackaging", + "foreignKey": "ticketFk" + }, + "freightItem": { + "type": "belongsTo", + "model": "Item", + "foreignKey": "freightItemFk" + }, + "packaging": { + "type": "belongsTo", + "model": "Package", + "foreignKey": "packagingFk" + } } } -} \ No newline at end of file diff --git a/modules/ticket/back/models/sale.json b/modules/ticket/back/models/sale.json index 947115f5c..96a36bbc9 100644 --- a/modules/ticket/back/models/sale.json +++ b/modules/ticket/back/models/sale.json @@ -28,9 +28,6 @@ "discount": { "type": "number" }, - "priceFixed": { - "type": "number" - }, "reserved": { "type": "boolean" },