7658-devToTest_2428 #2663

Merged
alexm merged 251 commits from 7658-devToTest_2428 into test 2024-07-02 07:20:13 +00:00
24 changed files with 333 additions and 247 deletions
Showing only changes of commit 9b0913e439 - Show all commits

View File

@ -28,7 +28,7 @@ Pull from repository.
Run this commands on project root directory to install Node dependencies.
```
$ npm install
$ pnpm install
$ gulp install
```

View File

@ -12,6 +12,12 @@
"required": true,
"id": true
},
"sectorFromCode": {
"type": "string"
},
"sectorToCode": {
"type": "string"
},
"backupPrinterNotificationDelay": {
"type": "string"
}

View File

@ -22,6 +22,7 @@ BEGIN
DECLARE vSerialDua VARCHAR(1) DEFAULT 'D';
DECLARE vInvoiceTypeInformativeCode VARCHAR(1);
DECLARE vCountryCanariasCode, vCountryCeutaMelillaCode VARCHAR(2);
DECLARE vCompanyCode INT;
SELECT SiglaNacion INTO vCountryCanariasCode
FROM Naciones
@ -31,9 +32,6 @@ BEGIN
FROM Naciones
WHERE Nacion ='CEUTA Y MELILLA';
SELECT pendingServiceTransactionTypeFk INTO vDuaTransactionFk
FROM config;
SELECT id INTO vTaxImportFk
FROM taxType
WHERE code = 'import21';
@ -46,10 +44,14 @@ BEGIN
FROM taxType
WHERE code = 'import4';
SELECT definitiveExportTransactionTypeFk INTO vTransactionExportFk
FROM config;
SELECT shipmentTransactionTypeFk INTO vTransactionExportTaxFreeFk
SELECT shipmentTransactionTypeFk,
definitiveExportTransactionTypeFk,
pendingServiceTransactionTypeFk,
company_getCode(vCompanyFk)
INTO vTransactionExportTaxFreeFk,
vTransactionExportFk,
vDuaTransactionFk,
vCompanyCode
FROM config;
SELECT codeSage INTO vInvoiceTypeInformativeCode
@ -64,8 +66,6 @@ BEGIN
WHERE enlazadoSage = FALSE
AND Asiento <> 1 ;
CALL clientSupplier_add(vCompanyFk);
CALL pgc_add(vCompanyFk);
CALL invoiceOut_manager(vYear, vCompanyFk);
CALL invoiceIn_manager(vYear, vCompanyFk);
@ -158,7 +158,7 @@ BEGIN
)
SELECT 'EN' TipoEntrada,
YEAR(x.FECHA) Ejercicio,
company_getCode(vCompanyFk) AS CodigoEmpresa,
vCompanyCode CodigoEmpresa,
x.ASIEN Asiento,
IF(EURODEBE <> 0 OR (EURODEBE = 0 AND EUROHABER IS NULL),
'D', 'H') CargoAbono,
@ -291,20 +291,6 @@ BEGIN
WHERE m.CargoAbono = 'D'
AND m.enlazadoSage = FALSE;
-- Elimina cuentas de cliente/proveedor que no se utilizarán en la importación
DELETE cp
FROM clientesProveedores cp
LEFT JOIN movConta mc ON mc.codigoCuenta = cp.codigoCuenta
AND mc.enlazadoSage = FALSE
WHERE mc.codigoCuenta IS NULL;
-- Elimina cuentas contables que no se utilizarán en la importación
DELETE pc
FROM planCuentasPGC pc
LEFT JOIN movConta mc ON mc.codigoCuenta = pc.codigoCuenta
AND mc.enlazadoSage = FALSE
WHERE mc.codigoCuenta IS NULL;
-- DUAS
UPDATE movConta mci
JOIN vn.XDiario x ON x.ASIEN = mci.Asiento
@ -411,5 +397,44 @@ BEGIN
AND importeDivisa > 0
AND ImporteAsiento < 0;
CREATE OR REPLACE TEMPORARY TABLE tmp.clientSupplier
(INDEX(idClientSupplier, `type`))
ENGINE = MEMORY
WITH client AS(
SELECT DISTINCT c.id
FROM sage.movConta mc
JOIN vn.client c ON c.accountingAccount = mc.CodigoCuenta
WHERE NOT enlazadoSage
),supplier AS(
SELECT DISTINCT s.id
FROM sage.movConta mc
JOIN vn.supplier s ON s.account = mc.CodigoCuenta
WHERE NOT enlazadoSage
)SELECT idClientSupplier, `type`
FROM sage.clientSupplier cs
WHERE NOT isSync
UNION
SELECT id, 'C'
FROM client
UNION
SELECT id, 'P'
FROM supplier;
CALL clientSupplier_add(vCompanyFk);
INSERT IGNORE INTO sage.clientSupplier (companyFk, `type`, idClientSupplier, isSync)
SELECT vCompanyCode, `type`, idClientSupplier, FALSE
FROM tmp.clientSupplier;
DROP TEMPORARY TABLE tmp.clientSupplier;
CALL pgc_add(vCompanyFk);
-- Elimina cuentas contables que no se utilizarán en la importación
DELETE pc
FROM planCuentasPGC pc
LEFT JOIN movConta mc ON mc.codigoCuenta = pc.codigoCuenta
AND mc.enlazadoSage = FALSE
WHERE mc.codigoCuenta IS NULL;
END$$
DELIMITER ;

View File

@ -1,11 +1,16 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `sage`.`clientSupplier_add`(vCompanyFk INT)
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `sage`.`clientSupplier_add`(
vCompanyFk INT
)
BEGIN
/**
* Prepara los datos de clientes y proveedores para exportarlos a Sage
* @vCompanyFk Empresa dela que se quiere trasladar datos
* Inserta en la tabla sage.clientesProveedores los datos de clientes y proveedores
* que se actualizaran o se daran de alta en Sage
* @vCompanyFk Id de empresa
* @table tmp.clientSupplier(idClientSupplier, `type`)
*/
DECLARE vCountryCeutaMelillaFk INT;
DECLARE vCompanyCode INT DEFAULT company_getCode(vCompanyFk);
DECLARE vCountryCanariasCode, vCountryCeutaMelillaCode VARCHAR(2);
SELECT SiglaNacion INTO vCountryCanariasCode
@ -45,7 +50,7 @@ BEGIN
Email1,
iban)
SELECT
company_getCode(vCompanyFk),
vCompanyCode,
'C',
c.id,
c.socialName,
@ -75,15 +80,14 @@ BEGIN
IFNULL(SUBSTR(c.email, 1, LOCATE(',', CONCAT(c.email, ','))-1), ''),
IFNULL(c.iban, '')
FROM vn.`client` c
JOIN clientLastTwoMonths clm ON clm.clientFk = c.id
JOIN tmp.clientSupplier cs ON cs.idClientSupplier = c.id
LEFT JOIN vn.country cu ON cu.id = c.countryFk
LEFT JOIN Naciones n ON n.countryFk = cu.id
LEFT JOIN vn.province p ON p.id = c.provinceFk
LEFT JOIN Provincias pr ON pr.provinceFk = p.id
WHERE c.isRelevant
AND clm.companyFk = vCompanyFk
WHERE cs.type = 'C'
UNION ALL
SELECT company_getCode(vCompanyFk),
SELECT vCompanyCode,
'P',
s.id,
s.name,
@ -107,18 +111,16 @@ BEGIN
IFNULL(s.transactionTypeSageFk, 0),
IFNULL(s.withholdingSageFk, '0'),
IFNULL(SUBSTR(sc.email, 1, (COALESCE(NULLIF(LOCATE(',', sc.email), 0), 99) - 1)), ''),
IFNULL(iban, '')
IFNULL(sa.iban, '')
FROM vn.supplier s
JOIN supplierLastThreeMonths pl ON pl.supplierFk = s.id
JOIN tmp.clientSupplier cs ON cs.idClientSupplier = s.id
LEFT JOIN vn.country co ON co.id = s.countryFk
LEFT JOIN Naciones n ON n.countryFk = co.id
LEFT JOIN vn.province p ON p.id = s.provinceFk
LEFT JOIN Provincias pr ON pr.provinceFk = p.id
LEFT JOIN vn.supplierContact sc ON sc.supplierFk = s.id
LEFT JOIN vn.supplierAccount sa ON sa.supplierFk = s.id
WHERE pl.companyFk = vCompanyFk AND
s.isActive AND
s.nif <> ''
GROUP BY pl.supplierFk, pl.companyFk;
WHERE cs.type = 'P'
GROUP BY s.id;
END$$
DELIMITER ;

View File

@ -3,12 +3,35 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`client_afterUpdate`
AFTER UPDATE ON `client`
FOR EACH ROW
BEGIN
IF !(NEW.defaultAddressFk <=> OLD.defaultAddressFk) THEN
IF NOT (NEW.defaultAddressFk <=> OLD.defaultAddressFk) THEN
UPDATE `address` SET isDefaultAddress = FALSE
WHERE clientFk = NEW.id;
UPDATE `address` SET isDefaultAddress = TRUE
WHERE id = NEW.defaultAddressFk;
END IF;
IF NEW.id <> OLD.id
OR NOT (NEW.provinceFk <=> OLD.provinceFk)
OR NOT (NEW.socialName <=> OLD.socialName)
OR NOT (NEW.street <=> OLD.street)
OR NOT (NEW.accountingAccount <=> OLD.accountingAccount)
OR NOT (NEW.isVies <=> OLD.isVies)
OR NOT (NEW.fi <=> OLD.fi)
OR NOT (NEW.postcode <=> OLD.postcode)
OR NOT (NEW.city <=> OLD.city)
OR NOT (NEW.countryFk <=> OLD.countryFk)
OR NOT (NEW.taxTypeSageFk <=> OLD.taxTypeSageFk)
OR NOT (NEW.transactionTypeSageFk <=> OLD.transactionTypeSageFk)
OR NOT (NEW.email <=> OLD.email)
OR NOT (NEW.iban <=> OLD.iban)
OR NOT (NEW.phone <=> OLD.phone)
OR NOT (NEW.mobile <=> OLD.mobile) THEN
UPDATE sage.clientSupplier
SET isSync = FALSE
WHERE idClientSupplier IN (NEW.id, OLD.id)
AND `type` = 'C';
END IF;
END$$
DELIMITER ;

View File

@ -65,11 +65,11 @@ BEGIN
END IF;
END IF;
IF !(NEW.salesPersonFk <=> OLD.salesPersonFk) THEN
IF NOT (NEW.salesPersonFk <=> OLD.salesPersonFk) THEN
SET NEW.lastSalesPersonFk = IFNULL(NEW.salesPersonFk, OLD.salesPersonFk);
END IF;
IF !(NEW.businessTypeFk <=> OLD.businessTypeFk) AND (NEW.businessTypeFk = 'individual' OR OLD.businessTypeFk = 'individual') THEN
IF NOT (NEW.businessTypeFk <=> OLD.businessTypeFk) AND (NEW.businessTypeFk = 'individual' OR OLD.businessTypeFk = 'individual') THEN
SET NEW.isTaxDataChecked = 0;
END IF;
END$$

View File

@ -0,0 +1,26 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`supplier_afterUpdate`
BEFORE UPDATE ON `supplier`
FOR EACH ROW
BEGIN
IF NEW.id <> OLD.id
OR NOT (NEW.name <=> OLD.name)
OR NOT (NEW.street <=> OLD.street)
OR NOT (NEW.account <=> OLD.account)
OR NOT (NEW.nif <=> OLD.nif)
OR NOT (NEW.isVies <=> OLD.isVies)
OR NOT (NEW.provinceFk <=> OLD.provinceFk)
OR NOT (NEW.countryFk <=> OLD.countryFk)
OR NOT (NEW.postCode <=> OLD.postCode)
OR NOT (NEW.city <=> OLD.city)
OR NOT (NEW.taxTypeSageFk <=> OLD.taxTypeSageFk)
OR NOT (NEW.transactionTypeSageFk <=> OLD.transactionTypeSageFk)
OR NOT (NEW.withholdingSageFk <=> OLD.withholdingSageFk) THEN
UPDATE sage.clientSupplier
SET isSync = FALSE
WHERE idClientSupplier IN (NEW.id, OLD.id)
AND `type` = 'P';
END IF;
END$$
DELIMITER ;

View File

@ -0,0 +1,5 @@
-- Place your SQL code here
USE vn;
ALTER TABLE vn.productionConfig ADD itemOlderReviewHours int(11) DEFAULT 0 NOT NULL COMMENT 'Horas que se tienen en cuenta para comprobar si un ítem es más viejo.';

View File

@ -0,0 +1,9 @@
CREATE OR REPLACE TABLE sage.clientSupplier (
`companyFk` smallint(6) NOT NULL,
`type` ENUM('C','P') NOT NULL,
`idClientSupplier` INT NOT NULL,
`isSync` TINYINT(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`companyFk`,`idClientSupplier`,`type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci
COMMENT='Clients and suppliers present in Sage and their synchronization status';

View File

@ -0,0 +1,9 @@
-- Place your SQL code here
USE vn;
ALTER TABLE vn.productionConfig ADD sectorFromCode varchar(15) NULL COMMENT 'Sector origen que se revisa ítems más nuevos al parkinear';
ALTER TABLE vn.productionConfig ADD sectorToCode varchar(15) NULL COMMENT 'Sector destino que se revisa ítems más nuevos al parkinear';
ALTER TABLE vn.productionConfig ADD CONSTRAINT productionConfig_sector_FK FOREIGN KEY (sectorFromCode) REFERENCES vn.sector(code) ON DELETE RESTRICT ON UPDATE CASCADE;
ALTER TABLE vn.productionConfig ADD CONSTRAINT productionConfig_sector_FK_1 FOREIGN KEY (sectorToCode) REFERENCES vn.sector(code) ON DELETE RESTRICT ON UPDATE CASCADE;

View File

@ -0,0 +1,14 @@
-- Place your SQL code here
USE vn;
ALTER TABLE vn.itemShelving DROP FOREIGN KEY itemShelvingBuy_FK;
ALTER TABLE vn.itemShelving DROP FOREIGN KEY itemShelving_fk2;
ALTER TABLE vn.itemShelving DROP INDEX itemShelving_UN;
ALTER TABLE vn.itemShelving ADD CONSTRAINT itemShelving_fk2 FOREIGN KEY (shelvingFk) REFERENCES vn.shelving(code) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE vn.itemShelving ADD CONSTRAINT itemShelvingBuy_FK FOREIGN KEY (buyFk) REFERENCES vn.buy(id) ON DELETE RESTRICT ON UPDATE RESTRICT;

View File

@ -351,7 +351,7 @@
"You are not allowed to modify the alias": "No estás autorizado a modificar el alias",
"The address of the customer must have information about Incoterms and Customs Agent": "El consignatario del cliente debe tener informado Incoterms y Agente de aduanas",
"The line could not be marked": "La linea no puede ser marcada",
"This password can only be changed by the user themselves": "Esta contraseña solo puede ser modificada por el propio usuario",
"Through this procedure, it is not possible to modify the password of users with verified email": "Mediante este procedimiento, no es posible modificar la contraseña de usuarios con correo verificado",
"They're not your subordinate": "No es tu subordinado/a.",
"No results found": "No se han encontrado resultados",
"InvoiceIn is already booked": "La factura recibida está contabilizada",

View File

@ -13,7 +13,11 @@ module.exports = Self => {
Self.setUnverifiedPassword = async(id, pass, options) => {
const {emailVerified} = await models.VnUser.findById(id, {fields: ['emailVerified']}, options);
if (emailVerified) throw new ForbiddenError('This password can only be changed by the user themselves');
if (emailVerified) {
throw new ForbiddenError(
'Through this procedure, it is not possible to modify the password of users with verified email'
);
}
await models.VnUser.setPassword(id, pass, options);
};

View File

@ -0,0 +1,70 @@
module.exports = Self => {
Self.remoteMethod('getListItemNewer', {
description:
'Get boolean if any or specific item of the shelving has older created in another shelving or parking',
accessType: 'READ',
accepts: [{
arg: 'shelvingFk',
type: 'string',
required: true,
description: 'Shelving code'
},
{
arg: 'parking',
type: 'string',
required: true,
description: 'Parking code'
},
],
returns: {
type: 'Array',
root: true
},
http: {
path: `/getListItemNewer`,
verb: 'GET'
}
});
Self.getListItemNewer = async(shelvingFk, parking, options) => {
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const [isParkingToReview] = await Self.rawSql(`
SELECT COUNT(p.id) parkingToReview
FROM vn.parking p
JOIN vn.sector s ON s.id = p.sectorFk
JOIN vn.productionConfig pc
WHERE p.code = ? AND s.code = pc.sectorToCode;`,
[parking], myOptions);
if (isParkingToReview['parkingToReview'] < 1) return [];
const result = await Self.rawSql(`
WITH tItemShelving AS(
SELECT is2.itemFk, is2.created, p.sectorFK, is2.id
FROM vn.itemShelving is2
JOIN vn.shelving sh ON sh.code = is2.shelvingFk
JOIN vn.parking p ON p.id = sh.parkingFk
JOIN vn.sector s ON s.id = p.sectorFk
JOIN vn.productionConfig pc
WHERE is2.shelvingFk = ? AND s.code = pc.sectorFromCode
), tItemInSector AS (
SELECT is2.itemFk, is2.created, is2.shelvingFk
FROM vn.itemShelving is2
JOIN vn.shelving sh ON sh.code = is2.shelvingFk
JOIN vn.parking p ON p.id = sh.parkingFk
JOIN vn.sector s ON s.id = p.sectorFk
JOIN vn.productionConfig pc
WHERE is2.shelvingFk <> ?
AND s.code = pc.sectorFromCode)
SELECT ti.itemFK, tis.shelvingFk
FROM tItemShelving ti
JOIN tItemInSector tis ON tis.itemFk = ti.itemFk
JOIN vn.productionConfig pc
WHERE ti.created > tis.created + INTERVAL pc.itemOlderReviewHours HOUR;`,
[shelvingFk, shelvingFk], myOptions);
return result;
};
};

View File

@ -1,63 +0,0 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethod('hasItemOlder', {
description:
'Get boolean if any or specific item of the shelving has older created in another shelving or parking',
accessType: 'READ',
accepts: [{
arg: 'shelvingFkIn',
type: 'string',
required: true,
description: 'Shelving code'
},
{
arg: 'parking',
type: 'string',
description: 'Parking code'
},
{
arg: 'shelvingFkOut',
type: 'string',
description: 'Shelving code'
},
{
arg: 'itemFk',
type: 'integer',
description: 'Item id'
}],
returns: {
type: 'boolean',
root: true
},
http: {
path: `/hasItemOlder`,
verb: 'GET'
}
});
Self.hasItemOlder = async(shelvingFkIn, parking, shelvingFkOut, itemFk, options) => {
if (!parking && !shelvingFkOut) throw new UserError('Missing data: parking or shelving');
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const result = await Self.rawSql(`
SELECT COUNT(ish.id) countItemOlder
FROM vn.itemShelving ish
JOIN (
SELECT ish.itemFk, created,shelvingFk
FROM vn.itemShelving ish
JOIN vn.shelving s ON ish.shelvingFk = s.code
WHERE ish.shelvingFk = ?
)sub ON sub.itemFK = ish.itemFk
JOIN vn.shelving s ON s.code = ish.shelvingFk
JOIN vn.parking p ON p.id = s.parkingFk
WHERE sub.created > ish.created
AND (p.code <> ? OR ? IS NULL)
AND (ish.shelvingFk <> ? OR ? IS NULL)
AND (ish.itemFk <> ? OR ? IS NULL)`,
[shelvingFkIn, parking, parking, shelvingFkOut, shelvingFkOut, itemFk, itemFk], myOptions);
return result[0]['countItemOlder'] > 0;
};
};

View File

@ -0,0 +1,45 @@
const {models} = require('vn-loopback/server/server');
describe('itemShelving getListItemNewer()', () => {
it('should return true because there is an older item', async() => {
const shelving = 'NCC';
const parking = 'A-47-1';
const sectorCamHighCode = 'CAMARA SECTOR D';
const sectorCamCode = 'NAVE ALGEMESI';
const sectorCamCodeHighId = 1;
const sectorCamCodeId = 9991;
const tx = await models.Sector.beginTransaction({});
const myOptions = {transaction: tx};
try {
const sectorHighCam = await models.Sector.findById(sectorCamCodeHighId, null, myOptions);
await sectorHighCam.updateAttributes({
code: sectorCamHighCode
});
const sectorCam = await models.Sector.findById(sectorCamCodeId, null, myOptions);
await sectorCam.updateAttributes({
code: sectorCamCode
});
const config = await models.ProductionConfig.findOne();
await config.updateAttributes({
sectorToCode: sectorCamHighCode,
sectorFromCode: sectorCamCode
});
const result = await models.ItemShelving.getListItemNewer(shelving, parking, myOptions);
expect(result.length).toEqual(2);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});

View File

@ -1,45 +0,0 @@
const {models} = require('vn-loopback/server/server');
describe('itemShelving hasOlder()', () => {
it('should return false because there are not older items', async() => {
const shelvingFkIn = 'GVC';
const shelvingFkOut = 'HEJ';
const result = await models.ItemShelving.hasItemOlder(shelvingFkIn, null, shelvingFkOut);
expect(result).toBe(false);
});
it('should return false because there are not older items in parking', async() => {
const shelvingFkIn = 'HEJ';
const parking = '700-01';
const result = await models.ItemShelving.hasItemOlder(shelvingFkIn, parking);
expect(result).toBe(false);
});
it('should return true because there is an older item', async() => {
const shelvingFkIn = 'UXN';
const shelvingFkOut = 'PCC';
const parking = 'A-01-1';
const itemFk = 1;
const tx = await models.ItemShelving.beginTransaction({});
const myOptions = {transaction: tx};
const filter = {where: {shelvingFk: shelvingFkOut}
};
try {
const itemShelvingBefore = await models.ItemShelving.findOne(filter, myOptions);
await itemShelvingBefore.updateAttributes({
itemFk: itemFk
}, myOptions);
const result = await models.ItemShelving.hasItemOlder(shelvingFkIn, parking, null, null, myOptions);
expect(result).toBe(true);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});

View File

@ -4,5 +4,5 @@ module.exports = Self => {
require('../methods/item-shelving/getInventory')(Self);
require('../methods/item-shelving/getAlternative')(Self);
require('../methods/item-shelving/updateFromSale')(Self);
require('../methods/item-shelving/hasItemOlder')(Self);
require('../methods/item-shelving/getListItemNewer')(Self);
};

View File

@ -20,21 +20,4 @@ module.exports = Self => {
require('../methods/route/cmrEmail')(Self);
require('../methods/route/getExpeditionSummary')(Self);
require('../methods/route/getByWorker')(Self);
Self.validate('kmStart', validateDistance, {
message: 'Distance must be lesser than 4000'
});
Self.validate('kmEnd', validateDistance, {
message: 'Distance must be lesser than 4000'
});
function validateDistance(err) {
if (this.kmEnd) {
const routeTotalKm = this.kmEnd - this.kmStart;
const routeMaxKm = 4000;
if (routeTotalKm > routeMaxKm || this.kmStart > this.kmEnd)
err();
}
}
};

View File

@ -145,15 +145,10 @@ module.exports = Self => {
const newTicket = await models.Ticket.new(ctx, myOptions);
const ticketRefund = await models.TicketRefund.findOne({
where: {refundTicketFk: ticketId}
}, myOptions);
if (negative && (withWarehouse || !ticketRefund?.id)) {
await models.TicketRefund.create({
originalTicketFk: ticketId,
refundTicketFk: newTicket.id
}, myOptions);
}
return newTicket;
}

View File

@ -1,7 +1,7 @@
const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
describe('ticket state()', () => {
xdescribe('ticket state()', () => {
const salesPersonId = 18;
const employeeId = 1;
const productionId = 49;
@ -113,6 +113,7 @@ describe('ticket state()', () => {
try {
const options = {transaction: tx};
spyOn(models.Chat, 'sendCheckingPresence').and.callThrough();
const ticket = await models.Ticket.create(sampleTicket, options);
activeCtx.accessToken.userId = salesPersonId;
const assignedState = await models.State.findOne({where: {code: 'PICKER_DESIGNED'}}, options);
@ -124,6 +125,7 @@ describe('ticket state()', () => {
expect(resAssigned.userFk).toBe(paramsAssigned.userFk);
expect(resAssigned.userFk).toBe(1);
expect(resAssigned.id).toBeDefined();
expect(models.Chat.sendCheckingPresence).not.toHaveBeenCalled();
activeCtx.accessToken.userId = productionId;
const packedState = await models.State.findOne({where: {code: 'PACKED'}}, options);
@ -183,5 +185,37 @@ describe('ticket state()', () => {
throw e;
}
});
it('should not call sendCheckingPresence if sales.length is 0 because quantities are equal', async() => {
const tx = await models.TicketTracking.beginTransaction({});
spyOn(models.Chat, 'sendCheckingPresence').and.callThrough();
try {
const options = {transaction: tx};
const ticket = await models.Ticket.create(sampleTicket, options);
activeCtx.accessToken.userId = productionId;
const sampleSale = {
ticketFk: ticket.id,
itemFk: 1,
concept: 'Test',
quantity: 10,
originalQuantity: 10
};
await models.Sale.create(sampleSale, options);
const packedState = await models.State.findOne({where: {code: 'PACKED'}}, options);
const params = {ticketFk: ticket.id, stateFk: packedState.id};
await models.Ticket.state(ctx, params, options);
expect(models.Chat.sendCheckingPresence).not.toHaveBeenCalled();
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});

View File

@ -26,7 +26,6 @@ module.exports = Self => {
const models = Self.app.models;
const myOptions = {};
let tx;
let newStateOrder;
if (typeof options == 'object')
Object.assign(myOptions, options);
@ -41,16 +40,11 @@ module.exports = Self => {
throw new UserError('State cannot be blank');
if (params.stateFk) {
const {code, order} = await models.State.findById(
params.stateFk,
{fields: ['code', 'order']},
myOptions);
const {code} = await models.State.findById(params.stateFk, {fields: ['code']}, myOptions);
params.code = code;
newStateOrder = order;
} else {
const {id, order} = await models.State.findOne({where: {code: params.code}}, myOptions);
const {id} = await models.State.findOne({where: {code: params.code}}, myOptions);
params.stateFk = id;
newStateOrder = order;
}
if (!params.userFk) {
@ -70,59 +64,7 @@ module.exports = Self => {
if ((ticketState && !oldStateAllowed) || !newStateAllowed)
throw new UserError(`You don't have enough privileges`, 'ACCESS_DENIED');
const ticket = await models.Ticket.findById(params.ticketFk, {
include: [{
relation: 'client',
scope: {
fields: ['salesPersonFk']
}
}],
fields: ['id', 'clientFk']
}, myOptions);
const salesPersonFk = ticket.client().salesPersonFk;
const stateChecked = await models.State.findOne({fields: ['order'], where: {code: 'CHECKED'}});
if (salesPersonFk && newStateOrder >= stateChecked.order) {
const sales = await Self.rawSql(`
SELECT DISTINCT s.id,
s.itemFk,
s.concept,
s.originalQuantity AS oldQuantity,
s.quantity AS newQuantity
FROM vn.sale s
WHERE s.ticketFk = ?
AND s.originalQuantity IS NOT NULL
AND s.originalQuantity <> s.quantity
`, [params.ticketFk], myOptions);
if (sales.length) {
let changes = '';
const url = await models.Url.getUrl();
const $t = ctx.req.__;
for (let sale of sales) {
changes += `\r\n-` + $t('Changes in sales', {
itemId: sale.itemFk,
concept: sale.concept,
oldQuantity: sale.oldQuantity,
newQuantity: sale.newQuantity,
itemUrl: `${url}item/${sale.itemFk}/summary`
});
const currentSale = await models.Sale.findById(sale.id, null, myOptions);
await currentSale.updateAttributes({
originalQuantity: currentSale.quantity
}, myOptions);
}
const message = $t('Changed sale quantity', {
ticketId: ticket.id,
changes: changes,
ticketUrl: `${url}ticket/${ticket.id}/sale`
});
await models.Chat.sendCheckingPresence(ctx, salesPersonFk, message, myOptions);
}
}
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticket.id, params.code], myOptions);
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [params.ticketFk, params.code], myOptions);
const ticketTracking = await models.TicketTracking.findOne({
where: {ticketFk: params.ticketFk},

View File

@ -42,7 +42,9 @@ describe('worker setPassword()', () => {
await tx.rollback();
} catch (e) {
expect(e.message).toEqual(`This password can only be changed by the user themselves`);
expect(e.message).toEqual(
'Through this procedure, it is not possible to modify the password of users with verified email'
);
await tx.rollback();
}
});

View File

@ -11,7 +11,7 @@
? 'Click to allow the user to be disabled'
: 'Click to exclude the user from getting disabled'}}
</vn-item>
<vn-item ng-if="!$ctrl.worker.user.emailVerified && $ctrl.vnConfig.storage.currentUserWorkerId !=$ctrl.worker.id" ng-click="setPassword.show()" translate>
<vn-item ng-click="setPassword.show()" translate>
Change password
</vn-item>
</slot-menu>