From 962436b8bbd51260b81cbfdcbf3ce718d8128bf3 Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 25 Jun 2020 17:12:53 +0200 Subject: [PATCH 1/6] 2344 ticket sale descuento usuario --- .../00-manaSpellersRequery.sql | 71 +++++++++++++++++++ db/changes/PASTE_COMMENT_REMINDER | 4 ++ modules/item/back/models/item.json | 3 + .../back/methods/ticket/updateDiscount.js | 19 ++--- 4 files changed, 82 insertions(+), 15 deletions(-) create mode 100644 db/changes/10200-Desescalada/00-manaSpellersRequery.sql create mode 100644 db/changes/PASTE_COMMENT_REMINDER diff --git a/db/changes/10200-Desescalada/00-manaSpellersRequery.sql b/db/changes/10200-Desescalada/00-manaSpellersRequery.sql new file mode 100644 index 000000000..fe9407ed3 --- /dev/null +++ b/db/changes/10200-Desescalada/00-manaSpellersRequery.sql @@ -0,0 +1,71 @@ +USE `vn`; +DROP procedure IF EXISTS `manaSpellersRequery`; + +DELIMITER $$ +USE `vn`$$ +CREATE DEFINER=`root`@`%` PROCEDURE `manaSpellersRequery`(vWorkerFk INTEGER) +BEGIN + DECLARE vWorkerHasMana BOOLEAN; + DECLARE vFromDated DATE; + DECLARE vToDated DATE DEFAULT TIMESTAMPADD(DAY,1,CURDATE()); + DECLARE vMana INT; + DECLARE vAutoMana INT; + DECLARE vManaBank INT; + DECLARE vManaGreugeType INT; + + SELECT id INTO vMana + FROM `component` WHERE code = 'mana'; + + SELECT id INTO vAutoMana + FROM `component` WHERE code = 'autoMana'; + + SELECT id INTO vManaBank + FROM `bank` WHERE code = 'mana'; + + SELECT id INTO vManaGreugeType + FROM `greugeType` WHERE code = 'mana'; + + SELECT COUNT(*) INTO vWorkerHasMana + FROM vn.workerMana wm + LEFT JOIN vn.workerManaExcluded wme ON wm.workerFk = wme.workerFk + WHERE wm.workerFk = vWorkerFk AND wme.workerFk IS NULL; + + IF vWorkerHasMana THEN + + SELECT max(dated) INTO vFromDated + FROM clientManaCache; + + REPLACE workerMana (workerFk, amount) + SELECT vWorkerFk, sum(mana) FROM + ( + SELECT s.quantity * sc.value as mana + FROM ticket t + JOIN address a ON a.id = t.addressFk + JOIN client c ON c.id = a.clientFk + JOIN sale s ON s.ticketFk = t.id + JOIN saleComponent sc ON sc.saleFk = s.id + WHERE c.salesPersonFk = vWorkerFk AND sc.componentFk IN (vMana, vAutoMana) + AND t.shipped > vFromDated AND t.shipped < vToDated + UNION ALL + SELECT - r.amountPaid + FROM receipt r + JOIN client c ON c.id = r.clientFk + WHERE c.salesPersonFk = vWorkerFk AND bankFk = vManaBank + AND payed > vFromDated + UNION ALL + SELECT g.amount + FROM greuge g + JOIN client c ON c.id = g.clientFk + WHERE c.salesPersonFk = vWorkerFk AND g.greugeTypeFk = vManaGreugeType + AND g.shipped > vFromDated and g.shipped < CURDATE() + UNION ALL + SELECT cc.mana + FROM clientManaCache cc + JOIN client c ON c.id = cc.clientFk + WHERE c.salesPersonFk = vWorkerFk AND cc.dated = vFromDated + ) sub; + END IF; +END$$ + +DELIMITER ; + diff --git a/db/changes/PASTE_COMMENT_REMINDER b/db/changes/PASTE_COMMENT_REMINDER new file mode 100644 index 000000000..07b707920 --- /dev/null +++ b/db/changes/PASTE_COMMENT_REMINDER @@ -0,0 +1,4 @@ +/* +Hay una versión en salix que machacará toda esta función/procedimiento +avisa a ___ de los cambios que quieres hacer +*/ \ No newline at end of file diff --git a/modules/item/back/models/item.json b/modules/item/back/models/item.json index 5d2e47d2a..6198fe702 100644 --- a/modules/item/back/models/item.json +++ b/modules/item/back/models/item.json @@ -122,6 +122,9 @@ "mysql": { "columnName": "expenceFk" } + }, + "compression": { + "type": "Number" } }, "relations": { diff --git a/modules/ticket/back/methods/ticket/updateDiscount.js b/modules/ticket/back/methods/ticket/updateDiscount.js index 3b69c6b68..d06ac8b27 100644 --- a/modules/ticket/back/methods/ticket/updateDiscount.js +++ b/modules/ticket/back/methods/ticket/updateDiscount.js @@ -35,7 +35,6 @@ module.exports = Self => { }); Self.updateDiscount = async(ctx, id, salesIds, newDiscount) => { - const userId = ctx.req.accessToken.userId; const models = Self.app.models; const tx = await Self.beginTransaction({}); @@ -69,6 +68,7 @@ module.exports = Self => { if (!allFromSameTicket) throw new UserError('All sales must belong to the same ticket'); + const userId = ctx.req.accessToken.userId; const isLocked = await models.Ticket.isLocked(id); const isSalesPerson = await models.Account.hasRole(userId, 'salesPerson'); const state = await Self.app.models.TicketState.findOne({ @@ -79,18 +79,9 @@ module.exports = Self => { if (isLocked || (!isSalesPerson && alertLevel > 0)) throw new UserError(`The sales of this ticket can't be modified`); - const ticket = await models.Ticket.findById(id, { - include: { - relation: 'client', - scope: { - fields: ['salesPersonFk'] - } - }, - }, options); - const salesPersonId = ticket.client().salesPersonFk; const usesMana = await models.WorkerMana.findOne({ where: { - workerFk: salesPersonId + workerFk: userId }, fields: 'amount'}, options); @@ -115,10 +106,8 @@ module.exports = Self => { await Promise.all(promises); - if (salesPersonId) { - const query = `call vn.manaSpellersRequery(?)`; - await Self.rawSql(query, [salesPersonId], options); - } + const query = `call vn.manaSpellersRequery(?)`; + await Self.rawSql(query, [userId], options); await tx.commit(); } catch (error) { From db06626675a93b2da808c92f36e4dcc9c0ae14ec Mon Sep 17 00:00:00 2001 From: jgallego Date: Mon, 29 Jun 2020 14:26:27 +0200 Subject: [PATCH 2/6] refactor --- db/Dockerfile | 4 ++-- db/docker.js | 5 ++--- modules/item/back/models/item.json | 3 --- .../methods/sale/specs/updatePrice.spec.js | 5 +++++ .../worker-mana/getCurrentWorkerMana.js | 18 +++++++++--------- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/db/Dockerfile b/db/Dockerfile index c376e6893..60e25319f 100644 --- a/db/Dockerfile +++ b/db/Dockerfile @@ -35,5 +35,5 @@ ENTRYPOINT ["docker-start.sh"] CMD ["mysqld"] -#HEALTHCHECK --interval=5s --timeout=10s --retries=200 \ -# CMD mysqladmin ping -h 127.0.0.1 -u root || exit 1 +HEALTHCHECK --interval=5s --timeout=10s --retries=200 \ + CMD mysqladmin ping -h 127.0.0.1 -u root || exit 1 diff --git a/db/docker.js b/db/docker.js index 0a221a0be..0cb912be6 100644 --- a/db/docker.js +++ b/db/docker.js @@ -39,8 +39,7 @@ module.exports = class Docker { let runChown = process.platform != 'linux'; - const healthCheck = `--health-cmd='mysqladmin ping --silent'`; - const container = await this.execP(`docker run ${healthCheck} --env RUN_CHOWN=${runChown} -d ${dockerArgs} salix-db`); + const container = await this.execP(`docker run --env RUN_CHOWN=${runChown} -d ${dockerArgs} salix-db`); this.id = container.stdout; try { @@ -54,7 +53,7 @@ module.exports = class Docker { this.dbConf.port = netSettings.Ports['3306/tcp'][0]['HostPort']; } - if (runChown) await this.wait(); + await this.waitForHealthy(); } catch (err) { if (this.isRandom) await this.rm(); diff --git a/modules/item/back/models/item.json b/modules/item/back/models/item.json index 6198fe702..5d2e47d2a 100644 --- a/modules/item/back/models/item.json +++ b/modules/item/back/models/item.json @@ -122,9 +122,6 @@ "mysql": { "columnName": "expenceFk" } - }, - "compression": { - "type": "Number" } }, "relations": { diff --git a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js index 2ca266769..c4a0127ac 100644 --- a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js +++ b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js @@ -66,6 +66,11 @@ describe('sale updatePrice()', () => { let saleUpdated = await app.models.Sale.findById(saleId); createdSaleComponent = await app.models.SaleComponent.findOne({where: {saleFk: saleId, componentFk: manaComponentId}}); + console.log(manaComponentId); + console.log(saleId); + console.log(saleUpdated); + console.log(createdSaleComponent); + expect(saleUpdated.price).toBe(price); expect(createdSaleComponent.value).toEqual(-2.04); }); diff --git a/modules/worker/back/methods/worker-mana/getCurrentWorkerMana.js b/modules/worker/back/methods/worker-mana/getCurrentWorkerMana.js index 7be2312e6..03973057d 100644 --- a/modules/worker/back/methods/worker-mana/getCurrentWorkerMana.js +++ b/modules/worker/back/methods/worker-mana/getCurrentWorkerMana.js @@ -14,16 +14,16 @@ module.exports = Self => { }); Self.getCurrentWorkerMana = async ctx => { - let currentClientId = ctx.req.accessToken.userId; - let currentWorker = await Self.app.models.Worker.findOne({ - where: {userFk: currentClientId}, - fields: 'id' - }); - let currentWorkerMana = await Self.app.models.WorkerMana.findOne({ - where: {workerFk: currentWorker.id}, + let userId = ctx.req.accessToken.userId; + + console.log(userId); + let workerMana = await Self.app.models.WorkerMana.findOne({ + where: {workerFk: userId}, fields: 'amount' }); - - return currentWorkerMana ? currentWorkerMana.amount : 0; + let workerMana1 = await Self.app.models.WorkerMana.find(); + console.log(workerMana); + console.log(workerMana1); + return workerMana ? workerMana.amount : 0; }; }; From d77297941fd11002a2baabebcbd18d7c923b541b Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Tue, 30 Jun 2020 09:08:08 +0200 Subject: [PATCH 3/6] fix date in a front test --- modules/zone/front/calendar/index.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/zone/front/calendar/index.spec.js b/modules/zone/front/calendar/index.spec.js index 6ea524020..0b5adc10d 100644 --- a/modules/zone/front/calendar/index.spec.js +++ b/modules/zone/front/calendar/index.spec.js @@ -33,6 +33,7 @@ describe('component vnZoneCalendar', () => { describe('step()', () => { it('should set the date month to 4 months backwards', () => { const now = new Date(); + now.setDate(15); now.setMonth(now.getMonth() - 4); controller.step(-1); From e7a866553c90c9f53a161a7e73d2140a8a74389f Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Tue, 30 Jun 2020 09:15:08 +0200 Subject: [PATCH 4/6] fix test --- modules/zone/front/calendar/index.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/zone/front/calendar/index.spec.js b/modules/zone/front/calendar/index.spec.js index 0b5adc10d..00645b317 100644 --- a/modules/zone/front/calendar/index.spec.js +++ b/modules/zone/front/calendar/index.spec.js @@ -46,6 +46,7 @@ describe('component vnZoneCalendar', () => { it('should set the date month to 4 months forwards', () => { const now = new Date(); + now.setDate(15); now.setMonth(now.getMonth() + 4); controller.step(1); From 039eec7d26de8478aceb557a314ce473a6356f1a Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 30 Jun 2020 10:16:22 +0200 Subject: [PATCH 5/6] test excepto fallo e2e --- db/changes/10170-NOFallas/00-aclWorkerDms.sql | 5 - .../10170-NOFallas/00-zone_getEvents.sql | 119 ------------------ .../10170-NOFallas/00-zone_getWarehouse.sql | 87 ------------- .../00-manaSpellersRequery.sql | 71 ----------- db/dump/fixtures.sql | 3 + e2e/paths/05-ticket/14_create_ticket.spec.js | 2 +- loopback/locale/en.json | 3 +- .../methods/sale/specs/updatePrice.spec.js | 5 - .../ticket/back/methods/sale/updatePrice.js | 3 +- .../ticket/specs/updateDiscount.spec.js | 25 +++- .../back/methods/ticket/updateDiscount.js | 1 - .../worker-mana/getCurrentWorkerMana.js | 5 +- 12 files changed, 32 insertions(+), 297 deletions(-) delete mode 100644 db/changes/10170-NOFallas/00-aclWorkerDms.sql delete mode 100644 db/changes/10170-NOFallas/00-zone_getEvents.sql delete mode 100644 db/changes/10170-NOFallas/00-zone_getWarehouse.sql delete mode 100644 db/changes/10200-Desescalada/00-manaSpellersRequery.sql diff --git a/db/changes/10170-NOFallas/00-aclWorkerDms.sql b/db/changes/10170-NOFallas/00-aclWorkerDms.sql deleted file mode 100644 index 46e56f77e..000000000 --- a/db/changes/10170-NOFallas/00-aclWorkerDms.sql +++ /dev/null @@ -1,5 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) -VALUES -('WorkerDms', 'filter', 'READ', 'ALLOW', 'ROLE', 'employee'), -('WorkerDms', 'downloadFile', 'READ', 'ALLOW', 'ROLE', 'employee'); -DELETE FROM `salix`.`ACL` WHERE (`id` = '205'); diff --git a/db/changes/10170-NOFallas/00-zone_getEvents.sql b/db/changes/10170-NOFallas/00-zone_getEvents.sql deleted file mode 100644 index 991150db7..000000000 --- a/db/changes/10170-NOFallas/00-zone_getEvents.sql +++ /dev/null @@ -1,119 +0,0 @@ -USE `vn`; -DROP procedure IF EXISTS `zone_getEvents`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `zone_getEvents`( - vGeoFk INT, - vAgencyModeFk INT) -BEGIN -/** - * Returns available events for the passed province/postcode and agency. - * - * @param vGeoFk The geo id - * @param vAgencyModeFk The agency mode id - */ - DECLARE vDeliveryMethodFk VARCHAR(255); - - DROP TEMPORARY TABLE IF EXISTS tZone; - CREATE TEMPORARY TABLE tZone - (id INT PRIMARY KEY) - ENGINE = MEMORY; - - SELECT dm.`code` INTO vDeliveryMethodFk - FROM agencyMode am - JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk - WHERE am.id = vAgencyModeFk; - - IF vDeliveryMethodFk = 'PICKUP' THEN - INSERT INTO tZone - SELECT id - FROM zone - WHERE agencyModeFk = vAgencyModeFk; - ELSE - CALL zone_getFromGeo(vGeoFk); - - IF vAgencyModeFk IS NOT NULL THEN - INSERT INTO tZone - SELECT t.id - FROM tmp.zone t - JOIN zone z ON z.id = t.id - WHERE z.agencyModeFk = vAgencyModeFk; - ELSE - INSERT INTO tZone - SELECT t.id - FROM tmp.zone t - JOIN zone z ON z.id = t.id - JOIN agencyMode am ON am.id = z.agencyModeFk - JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk - WHERE dm.`code` IN ('AGENCY', 'DELIVERY'); - END IF; - DROP TEMPORARY TABLE tmp.zone; - END IF; - - SELECT e.zoneFk, e.`type`, e.dated, e.`started`, e.`ended`, e.weekDays - FROM tZone t - JOIN zoneEvent e ON e.zoneFk = t.id; - - SELECT e.zoneFk, e.dated - FROM tZone t - JOIN zoneExclusion e ON e.zoneFk = t.id; - - DROP TEMPORARY TABLE tZone; -END$$ - -DELIMITER ; - -USE `vn`; -DROP procedure IF EXISTS `zone_getEvents__`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `zone_getEvents__`( - vProvinceFk INT, - vPostCode VARCHAR(255), - vAgencyModeFk INT) -BEGIN -/** - * Returns available events for the passed province/postcode and agency. - * - * @param vAgencyModeFk The agency mode id - * @param vProvinceFk The province id - * @param vPostCode The postcode or %NULL to use the province - */ - - DECLARE vGeoFk INT; - - IF vPostCode IS NOT NULL THEN - SELECT p.geoFk INTO vGeoFk - FROM postCode p - JOIN town t ON t.id = p.townFk - WHERE p.`code` = vPostCode - AND t.provinceFk = vProvinceFk; - ELSE - SELECT geoFk INTO vGeoFk - FROM province - WHERE id = vProvinceFk; - END IF; - - CALL zone_getFromGeo(vGeoFk); - - IF vAgencyModeFk IS NOT NULL THEN - DELETE t FROM tmp.zone t - JOIN zone z ON z.id = t.id - WHERE z.agencyModeFk != vAgencyModeFk; - END IF; - - SELECT e.zoneFk, e.`type`, e.dated, e.`started`, e.`ended`, e.weekDays - FROM tmp.zone t - JOIN zoneEvent e ON e.zoneFk = t.id; - - SELECT e.zoneFk, e.dated - FROM tmp.zone t - JOIN zoneExclusion e ON e.zoneFk = t.id; - - DROP TEMPORARY TABLE tmp.zone; -END$$ - -DELIMITER ; - diff --git a/db/changes/10170-NOFallas/00-zone_getWarehouse.sql b/db/changes/10170-NOFallas/00-zone_getWarehouse.sql deleted file mode 100644 index a65643ff5..000000000 --- a/db/changes/10170-NOFallas/00-zone_getWarehouse.sql +++ /dev/null @@ -1,87 +0,0 @@ -USE `vn`; -DROP procedure IF EXISTS `zone_getWarehouse`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `zone_getWarehouse`(vAddress INT, vLanded DATE, vWarehouse INT) -BEGIN -/** - * Devuelve el listado de agencias disponibles para la fecha, - * dirección y almacén pasados. - * - * @param vAddress - * @param vWarehouse warehouse - * @param vLanded Fecha de recogida - * @select Listado de agencias disponibles - */ - - CALL zone_getFromGeo(address_getGeo(vAddress)); - CALL zone_getOptionsForLanding(vLanded, FALSE); - - SELECT am.id agencyModeFk, - am.name agencyMode, - am.description, - am.deliveryMethodFk, - TIMESTAMPADD(DAY, -zo.travelingDays, vLanded) shipped, - zw.warehouseFk, - z.id zoneFk - FROM tmp.zoneOption zo - JOIN zone z ON z.id = zo.zoneFk - JOIN agencyMode am ON am.id = z.agencyModeFk - JOIN zoneWarehouse zw ON zw.zoneFk = zo.zoneFk - WHERE zw.warehouseFk = vWarehouse - GROUP BY z.agencyModeFk - ORDER BY agencyMode; - - DROP TEMPORARY TABLE - tmp.zone, - tmp.zoneOption; - -END$$ - -DELIMITER ; - -USE `vn`; -DROP procedure IF EXISTS `zone_getWarehouse__`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `zone_getWarehouse__`(vAddress INT, vLanded DATE, vWarehouse INT) -BEGIN -/** - * Devuelve el listado de agencias disponibles para la fecha, - * dirección y almacén pasados. - * - * @param vAddress - * @param vWarehouse warehouse - * @param vLanded Fecha de recogida - * @select Listado de agencias disponibles - */ - - CALL zone_getFromGeo(address_getGeo(vAddress)); - CALL zone_getOptionsForLanding(vLanded, FALSE); - - SELECT am.id agencyModeFk, - am.name agencyMode, - am.description, - am.deliveryMethodFk, - TIMESTAMPADD(DAY, -zo.travelingDays, vLanded) shipped, - zw.warehouseFk, - z.id zoneFk - FROM tmp.zoneOption zo - JOIN zone z ON z.id = zo.zoneFk - JOIN agencyMode am ON am.id = z.agencyModeFk - JOIN zoneWarehouse zw ON zw.zoneFk = zo.zoneFk - WHERE zw.warehouseFk - GROUP BY z.agencyModeFk - ORDER BY agencyMode; - - DROP TEMPORARY TABLE - tmp.zone, - tmp.zoneOption; - -END$$ - -DELIMITER ; - - diff --git a/db/changes/10200-Desescalada/00-manaSpellersRequery.sql b/db/changes/10200-Desescalada/00-manaSpellersRequery.sql deleted file mode 100644 index fe9407ed3..000000000 --- a/db/changes/10200-Desescalada/00-manaSpellersRequery.sql +++ /dev/null @@ -1,71 +0,0 @@ -USE `vn`; -DROP procedure IF EXISTS `manaSpellersRequery`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `manaSpellersRequery`(vWorkerFk INTEGER) -BEGIN - DECLARE vWorkerHasMana BOOLEAN; - DECLARE vFromDated DATE; - DECLARE vToDated DATE DEFAULT TIMESTAMPADD(DAY,1,CURDATE()); - DECLARE vMana INT; - DECLARE vAutoMana INT; - DECLARE vManaBank INT; - DECLARE vManaGreugeType INT; - - SELECT id INTO vMana - FROM `component` WHERE code = 'mana'; - - SELECT id INTO vAutoMana - FROM `component` WHERE code = 'autoMana'; - - SELECT id INTO vManaBank - FROM `bank` WHERE code = 'mana'; - - SELECT id INTO vManaGreugeType - FROM `greugeType` WHERE code = 'mana'; - - SELECT COUNT(*) INTO vWorkerHasMana - FROM vn.workerMana wm - LEFT JOIN vn.workerManaExcluded wme ON wm.workerFk = wme.workerFk - WHERE wm.workerFk = vWorkerFk AND wme.workerFk IS NULL; - - IF vWorkerHasMana THEN - - SELECT max(dated) INTO vFromDated - FROM clientManaCache; - - REPLACE workerMana (workerFk, amount) - SELECT vWorkerFk, sum(mana) FROM - ( - SELECT s.quantity * sc.value as mana - FROM ticket t - JOIN address a ON a.id = t.addressFk - JOIN client c ON c.id = a.clientFk - JOIN sale s ON s.ticketFk = t.id - JOIN saleComponent sc ON sc.saleFk = s.id - WHERE c.salesPersonFk = vWorkerFk AND sc.componentFk IN (vMana, vAutoMana) - AND t.shipped > vFromDated AND t.shipped < vToDated - UNION ALL - SELECT - r.amountPaid - FROM receipt r - JOIN client c ON c.id = r.clientFk - WHERE c.salesPersonFk = vWorkerFk AND bankFk = vManaBank - AND payed > vFromDated - UNION ALL - SELECT g.amount - FROM greuge g - JOIN client c ON c.id = g.clientFk - WHERE c.salesPersonFk = vWorkerFk AND g.greugeTypeFk = vManaGreugeType - AND g.shipped > vFromDated and g.shipped < CURDATE() - UNION ALL - SELECT cc.mana - FROM clientManaCache cc - JOIN client c ON c.id = cc.clientFk - WHERE c.salesPersonFk = vWorkerFk AND cc.dated = vFromDated - ) sub; - END IF; -END$$ - -DELIMITER ; - diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index e48a20ec6..95de30b06 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1455,6 +1455,9 @@ INSERT INTO `vn`.`clientContact`(`id`, `clientFk`, `name`, `phone`) (3, 101, 'contact 3', 222333444), (4, 102, 'contact 1', 876543219); +INSERT INTO `vn`.`workerManaExcluded`(`workerFk`) + VALUES + (9); /* el mana de los trabajadores lo podemos poner a mano en la tabla si lo calculamos antes, pero si hazemos alguna modificacion en alguna tabla que utiliza para calcularlo ya no seria correcto diff --git a/e2e/paths/05-ticket/14_create_ticket.spec.js b/e2e/paths/05-ticket/14_create_ticket.spec.js index 26c22ad3d..1d80f7f1f 100644 --- a/e2e/paths/05-ticket/14_create_ticket.spec.js +++ b/e2e/paths/05-ticket/14_create_ticket.spec.js @@ -1,7 +1,7 @@ import selectors from '../../helpers/selectors.js'; import getBrowser from '../../helpers/puppeteer'; -describe('Ticket create path', () => { +fdescribe('Ticket create path', () => { let browser; let page; let nextMonth = new Date(); diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 6f20b947b..114b07edf 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -67,5 +67,6 @@ "Customs agent is required for a non UEE member": "Customs agent is required for a non UEE member", "Incoterms is required for a non UEE member": "Incoterms is required for a non UEE member", "Client checked as validated despite of duplication": "Client checked as validated despite of duplication from client id {{clientId}}", - "Landing cannot be lesser than shipment": "Landing cannot be lesser than shipment" + "Landing cannot be lesser than shipment": "Landing cannot be lesser than shipment", + "NOT_ZONE_WITH_THIS_PARAMETERS": "NOT_ZONE_WITH_THIS_PARAMETERS" } \ No newline at end of file diff --git a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js index c4a0127ac..2ca266769 100644 --- a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js +++ b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js @@ -66,11 +66,6 @@ describe('sale updatePrice()', () => { let saleUpdated = await app.models.Sale.findById(saleId); createdSaleComponent = await app.models.SaleComponent.findOne({where: {saleFk: saleId, componentFk: manaComponentId}}); - console.log(manaComponentId); - console.log(saleId); - console.log(saleUpdated); - console.log(createdSaleComponent); - expect(saleUpdated.price).toBe(price); expect(createdSaleComponent.value).toEqual(-2.04); }); diff --git a/modules/ticket/back/methods/sale/updatePrice.js b/modules/ticket/back/methods/sale/updatePrice.js index dac388034..200eeb444 100644 --- a/modules/ticket/back/methods/sale/updatePrice.js +++ b/modules/ticket/back/methods/sale/updatePrice.js @@ -56,7 +56,9 @@ module.exports = Self => { throw new UserError(`The sales of this ticket can't be modified`); const userId = ctx.req.accessToken.userId; + let usesMana = await models.WorkerMana.findOne({where: {workerFk: userId}, fields: 'amount'}, options); + let componentCode = usesMana ? 'mana' : 'buyerDiscount'; let discount = await models.Component.findOne({where: {code: componentCode}}, options); @@ -80,7 +82,6 @@ module.exports = Self => { value: componentValue }, options); } - await sale.updateAttributes({price: newPrice}, options); query = `CALL vn.manaSpellersRequery(?)`; diff --git a/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js b/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js index 111897efe..42689c73e 100644 --- a/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js +++ b/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js @@ -8,7 +8,7 @@ describe('sale updateDiscount()', () => { beforeAll(async done => { originalSale = await app.models.Sale.findById(originalSaleId); - let manaDiscount = await app.models.Component.findOne({where: {code: 'mana'}}); + let manaDiscount = await app.models.Component.findOne({where: {code: 'buyerDiscount'}}); componentId = manaDiscount.id; let ticket = await app.models.Ticket.findById(originalSale.ticketFk); @@ -26,7 +26,6 @@ describe('sale updateDiscount()', () => { done(); }); - it('should throw an error if no sales were selected', async() => { let ctx = {req: {accessToken: {userId: 9}}}; let error; @@ -76,6 +75,28 @@ describe('sale updateDiscount()', () => { }); it('should update the discount if the salesPerson has mana', async() => { + let ctx = {req: {accessToken: {userId: 18}}}; + const ticketId = 11; + const sales = [originalSaleId]; + const newDiscount = 100; + let manaDiscount = await app.models.Component.findOne({where: {code: 'mana'}}); + componentId = manaDiscount.id; + + await app.models.Ticket.updateDiscount(ctx, ticketId, sales, newDiscount); + + let updatedSale = await app.models.Sale.findById(originalSaleId); + let createdSaleComponent = await app.models.SaleComponent.findOne({ + where: { + componentFk: componentId, + saleFk: originalSaleId + } + }); + + expect(createdSaleComponent.componentFk).toEqual(componentId); + expect(updatedSale.discount).toEqual(100); + }); + + it('should update the discount and add company discount component if the worker does not have mana', async() => { let ctx = {req: {accessToken: {userId: 9}}}; const ticketId = 11; const sales = [originalSaleId]; diff --git a/modules/ticket/back/methods/ticket/updateDiscount.js b/modules/ticket/back/methods/ticket/updateDiscount.js index d06ac8b27..7c9f9ae48 100644 --- a/modules/ticket/back/methods/ticket/updateDiscount.js +++ b/modules/ticket/back/methods/ticket/updateDiscount.js @@ -90,7 +90,6 @@ module.exports = Self => { where: {code: componentCode}}, options); const componentId = discountComponent.id; - let promises = []; for (let sale of sales) { const value = ((-sale.price * newDiscount) / 100); diff --git a/modules/worker/back/methods/worker-mana/getCurrentWorkerMana.js b/modules/worker/back/methods/worker-mana/getCurrentWorkerMana.js index 03973057d..fa34af475 100644 --- a/modules/worker/back/methods/worker-mana/getCurrentWorkerMana.js +++ b/modules/worker/back/methods/worker-mana/getCurrentWorkerMana.js @@ -16,14 +16,11 @@ module.exports = Self => { Self.getCurrentWorkerMana = async ctx => { let userId = ctx.req.accessToken.userId; - console.log(userId); let workerMana = await Self.app.models.WorkerMana.findOne({ where: {workerFk: userId}, fields: 'amount' }); - let workerMana1 = await Self.app.models.WorkerMana.find(); - console.log(workerMana); - console.log(workerMana1); + return workerMana ? workerMana.amount : 0; }; }; From 05b0d7e906fd71ddd5bffe651ef4af907ac7587d Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 30 Jun 2020 12:34:51 +0200 Subject: [PATCH 6/6] test ok --- e2e/paths/05-ticket/14_create_ticket.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/paths/05-ticket/14_create_ticket.spec.js b/e2e/paths/05-ticket/14_create_ticket.spec.js index 1d80f7f1f..26c22ad3d 100644 --- a/e2e/paths/05-ticket/14_create_ticket.spec.js +++ b/e2e/paths/05-ticket/14_create_ticket.spec.js @@ -1,7 +1,7 @@ import selectors from '../../helpers/selectors.js'; import getBrowser from '../../helpers/puppeteer'; -fdescribe('Ticket create path', () => { +describe('Ticket create path', () => { let browser; let page; let nextMonth = new Date();