Merge branch 'dev' into 8077-sumDefaulterRedirectionLilium
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Robert Ferrús 2025-01-29 12:44:42 +00:00
commit f87fa37a79
9 changed files with 149 additions and 155 deletions

View File

@ -752,13 +752,15 @@ INSERT INTO `vn`.`zoneConfig` (`id`, `scope`) VALUES (1, '1');
INSERT INTO `vn`.`route`(`id`, `time`, `workerFk`, `created`, `vehicleFk`, `agencyModeFk`, `description`, `m3`, `cost`, `started`, `finished`, `zoneFk`, `dated`)
VALUES
(1, '1899-12-30 12:15:00', 56, util.VN_CURDATE(), 1, 1, 'first route', 1.8, 10, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1, util.VN_CURDATE()),
(1, '1899-12-30 12:15:00', 133, util.VN_CURDATE(), 1, 1, 'first route', 1.8, 10, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1, util.VN_CURDATE()),
(2, '1899-12-30 13:20:00', 56, util.VN_CURDATE(), 1, 2, 'second route', 0.2, 20, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 9, util.VN_CURDATE()),
(3, '1899-12-30 14:30:00', 56, util.VN_CURDATE(), 2, 3, 'third route', 0.5, 30, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 10, util.VN_CURDATE()),
(4, '1899-12-30 15:45:00', 56, util.VN_CURDATE(), 3, 4, 'fourth route', 0, 40, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 12, util.VN_CURDATE()),
(5, '1899-12-30 16:00:00', 56, util.VN_CURDATE(), 4, 5, 'fifth route', 0.1, 50, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 13, util.VN_CURDATE()),
(6, NULL, 57, util.VN_CURDATE(), 5, 7, 'sixth route', 1.7, 60, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 3, util.VN_CURDATE()),
(7, NULL, 57, util.VN_CURDATE(), 6, 8, 'seventh route', 0, 70, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 5, util.VN_CURDATE());
(7, NULL, 57, util.VN_CURDATE(), 6, 8, 'seventh route', 0, 70, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 5, util.VN_CURDATE()),
(8, NULL, 133, util.VN_CURDATE(), 1, 1, 'eighth route', 1.8, 10.0, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1, util.VN_CURDATE()),
(9, NULL, 133, util.VN_CURDATE(), 1, 2, 'ninth route', 0.2, 20.0, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 9, util.VN_CURDATE());
INSERT INTO `vn`.`ticket`(`id`, `priority`, `agencyModeFk`,`warehouseFk`,`routeFk`, `shipped`, `landed`, `clientFk`,`nickname`, `addressFk`, `refFk`, `isDeleted`, `zoneFk`, `zonePrice`, `zoneBonus`, `created`, `weight`, `cmrFk`, `problem`, `risk`)
VALUES
@ -4061,3 +4063,8 @@ INSERT IGNORE INTO vn.osrmConfig (id,url,tolerance)
INSERT IGNORE INTO vn.inventoryConfig
SET id = 1,
supplierFk = 4;
UPDATE vn.worker
SET isFreelance=1
WHERE firstName='deliveryFreelancer';

View File

@ -1,11 +1,11 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `sage`.`accountingMovements_add`(
vYear INT,
vYear INT,
vCompanyFk INT
)
BEGIN
/**
* Traslada la info de contabilidad generada en base a vn.XDiario a la tabla sage.movConta
* Traslada la info de contabilidad generada en base a vn.XDiario a la tabla sage.movConta
* para poder ejecutar posteriormente el proceso de importación de datos de SQL Server
* Solo traladará los asientos marcados con el campo vn.XDiario.enlazadoSage = FALSE
* @vYear Año contable del que se quiere trasladar la información
@ -23,6 +23,7 @@ BEGIN
DECLARE vInvoiceTypeInformativeCode VARCHAR(1);
DECLARE vCountryCanariasCode, vCountryCeutaMelillaCode VARCHAR(2);
DECLARE vCompanyCode INT;
DECLARE vHasErrorTax BOOL DEFAULT FALSE;
SELECT SiglaNacion INTO vCountryCanariasCode
FROM Naciones
@ -44,12 +45,12 @@ BEGIN
FROM taxType
WHERE code = 'import4';
SELECT shipmentTransactionTypeFk,
definitiveExportTransactionTypeFk,
SELECT shipmentTransactionTypeFk,
definitiveExportTransactionTypeFk,
pendingServiceTransactionTypeFk,
company_getCode(vCompanyFk)
INTO vTransactionExportTaxFreeFk,
vTransactionExportFk,
vTransactionExportFk,
vDuaTransactionFk,
vCompanyCode
FROM config;
@ -66,6 +67,24 @@ BEGIN
WHERE enlazadoSage = FALSE
AND Asiento <> 1 ;
SELECT EXISTS (
SELECT TRUE
FROM vn.XDiario x
JOIN vn.invoiceIn ii ON ii.id = x.CLAVE
JOIN vn.invoiceInTax it ON it.invoiceInFk = ii.id
LEFT JOIN TiposIva ti ON ti.CodigoIva = it.taxTypeSageFk
LEFT JOIN taxType tt ON tt.id = it.taxTypeSageFk
WHERE x.FECHA BETWEEN vDatedFrom AND vDatedTo
AND NOT x.enlazadoSage
AND x.empresa_id = vCompanyFk
AND it.taxTypeSageFk
AND (ti.CodigoIva IS NULL OR tt.id IS NULL)
) INTO vHasErrorTax;
IF vHasErrorTax tHEN
CALL util.throw ('Error in tables for received invoices tax');
END IF;
CALL invoiceOut_manager(vYear, vCompanyFk);
CALL invoiceIn_manager(vYear, vCompanyFk);
@ -306,8 +325,8 @@ BEGIN
mci.FechaFacturaOriginal = x.FECHA_EX,
mci.SuFacturaNo = x.FACTURAEX,
mci.FechaOperacion = x.FECHA_OP,
mci.ImporteFactura = mci.ImporteFactura +
x.BASEEURO +
mci.ImporteFactura = mci.ImporteFactura +
x.BASEEURO +
CAST((x.IVA / 100) * x.BASEEURO AS DECIMAL(10, 2))
WHERE pm.description = 'HP Iva pendiente'
AND mci.enlazadoSage = FALSE
@ -326,7 +345,7 @@ BEGIN
mci.CodigoIva2 = vTaxImportFk,
mci.IvaDeducible2 = TRUE,
mci.ImporteFactura = mci.ImporteFactura +
x.BASEEURO +
x.BASEEURO +
CAST((x.IVA / 100) * x.BASEEURO AS DECIMAL(10, 2))
WHERE pm.description = 'HP Iva pendiente'
AND mci.enlazadoSage = FALSE
@ -344,8 +363,8 @@ BEGIN
mci.CodigoTransaccion3 = vDuaTransactionFk ,
mci.CodigoIva3 = vTaxImportSuperReducedFk,
mci.IvaDeducible3 = TRUE,
mci.ImporteFactura = mci.ImporteFactura +
x.BASEEURO +
mci.ImporteFactura = mci.ImporteFactura +
x.BASEEURO +
CAST((x.IVA / 100) * x.BASEEURO AS DECIMAL(10, 2))
WHERE pm.description = 'HP Iva pendiente'
AND mci.enlazadoSage = FALSE
@ -379,14 +398,14 @@ BEGIN
OR CodigoTransaccion2 = vTransactionExportFk
OR CodigoTransaccion3 = vTransactionExportFk
OR CodigoTransaccion4 = vTransactionExportFk)
AND SiglaNacion IN (vCountryCanariasCode COLLATE utf8mb3_unicode_ci,
AND SiglaNacion IN (vCountryCanariasCode COLLATE utf8mb3_unicode_ci,
vCountryCeutaMelillaCode COLLATE utf8mb3_unicode_ci);
UPDATE movConta mc
SET CodigoDivisa = 'USD',
FactorCambio = TRUE,
ImporteCambio = ABS( CAST( IF( ImporteDivisa <> 0 AND ImporteCambio = 0,
ImporteAsiento / ImporteDivisa,
ImporteCambio = ABS( CAST( IF( ImporteDivisa <> 0 AND ImporteCambio = 0,
ImporteAsiento / ImporteDivisa,
ImporteCambio) AS DECIMAL( 10, 2)))
WHERE enlazadoSage = FALSE
AND (ImporteCambio <> 0 OR ImporteDivisa <> 0 OR FactorCambio);
@ -403,20 +422,20 @@ BEGIN
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(
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
JOIN vn.supplier s ON s.account = mc.CodigoCuenta
WHERE NOT enlazadoSage
),clientSupplierSync AS(
SELECT idClientSupplier, `type`
FROM sage.clientSupplier cs
WHERE isSync
FROM sage.clientSupplier cs
WHERE isSync
)
SELECT idClientSupplier, `type`
FROM sage.clientSupplier cs
FROM sage.clientSupplier cs
WHERE NOT isSync
UNION
SELECT id, 'C'
@ -424,7 +443,7 @@ BEGIN
LEFT JOIN clientSupplierSync cs ON cs.idClientSupplier = c.id
AND cs.Type ='C'
WHERE cs.idClientSupplier IS NULL
UNION
UNION
SELECT id, 'P'
FROM supplier s
LEFT JOIN clientSupplierSync cs ON cs.idClientSupplier = s.id
@ -436,7 +455,7 @@ BEGIN
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);

View File

@ -0,0 +1,19 @@
INSERT INTO account.`role` (name,description,hasLogin)
VALUES ('deliveryFreelancer','Repartidor autónomo',1);
INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId)
VALUES
('Route', 'getTickets', 'READ', 'ALLOW', 'ROLE', 'deliveryFreelancer'),
('AgencyTerm', 'filter', 'READ', 'ALLOW', 'ROLE', 'deliveryFreelancer'),
('Route', 'summary', 'READ', 'ALLOW', 'ROLE', 'deliveryFreelancer'),
('Route', 'getRouteByAgency', 'WRITE', 'ALLOW', 'ROLE', 'deliveryFreelancer'),
('Route','filter','READ','ALLOW','ROLE','deliveryFreelancer'),
('UserConfig','getUserConfig','*','ALLOW','ROLE','deliveryFreelancer'),
('Route', 'getTickets', 'READ', 'ALLOW', 'ROLE', 'deliveryFreelancer'),
('Route','guessPriority','WRITE','ALLOW','ROLE','deliveryFreelancer'),
('Route','getDeliveryPoint','READ','ALLOW','ROLE','deliveryFreelancer'),
('Route', 'findById', 'READ', 'ALLOW', 'ROLE', 'deliveryFreelancer'),
('Route','sendSms','WRITE','ALLOW','ROLE','deliveryFreelancer'),
('Ticket','updateAttributes','WRITE','ALLOW','ROLE','deliveryFreelancer'),
('Client','findById','READ','ALLOW','ROLE','deliveryFreelancer');
;

View File

@ -18,7 +18,7 @@ describe('AgencyTerm filter()', () => {
const firstAgencyTerm = agencyTerms[0];
expect(firstAgencyTerm.routeFk).toEqual(1);
expect(agencyTerms.length).toEqual(5);
expect(agencyTerms.length).toEqual(7);
await tx.rollback();
} catch (e) {
@ -49,7 +49,7 @@ describe('AgencyTerm filter()', () => {
let result = await app.models.AgencyTerm.filter(ctx);
expect(result.length).toEqual(2);
expect(result.length).toEqual(4);
});
it('should return results matching "from" and "to"', async() => {
@ -72,7 +72,7 @@ describe('AgencyTerm filter()', () => {
const results = await models.AgencyTerm.filter(ctx, options);
expect(results.length).toBe(5);
expect(results.length).toBe(7);
await tx.rollback();
} catch (e) {
@ -90,7 +90,7 @@ describe('AgencyTerm filter()', () => {
let result = await app.models.AgencyTerm.filter(ctx);
expect(result.length).toEqual(1);
expect(result.length).toEqual(2);
expect(result[0].routeFk).toEqual(1);
});
@ -103,7 +103,7 @@ describe('AgencyTerm filter()', () => {
let result = await app.models.AgencyTerm.filter(ctx);
expect(result.length).toEqual(1);
expect(result.length).toEqual(2);
expect(result[0].routeFk).toEqual(2);
});
});

View File

@ -1,109 +0,0 @@
const app = require('vn-loopback/server/server');
const models = require('vn-loopback/server/server').models;
describe('AgencyTerm filter()', () => {
const authUserId = 9;
const today = Date.vnNew();
today.setHours(2, 0, 0, 0);
it('should return all results matching the filter', async() => {
const tx = await models.AgencyTerm.beginTransaction({});
try {
const options = {transaction: tx};
const filter = {};
const ctx = {req: {accessToken: {userId: authUserId}}};
const agencyTerms = await models.AgencyTerm.filter(ctx, filter, options);
const firstAgencyTerm = agencyTerms[0];
expect(firstAgencyTerm.routeFk).toEqual(1);
expect(agencyTerms.length).toEqual(5);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('should return results matching "search" searching by integer', async() => {
let ctx = {
args: {
search: 1,
}
};
let result = await app.models.AgencyTerm.filter(ctx);
expect(result.length).toEqual(1);
expect(result[0].routeFk).toEqual(1);
});
it('should return results matching "search" searching by string', async() => {
let ctx = {
args: {
search: 'Plants SL',
}
};
let result = await app.models.AgencyTerm.filter(ctx);
expect(result.length).toEqual(2);
});
it('should return results matching "from" and "to"', async() => {
const tx = await models.Buy.beginTransaction({});
const options = {transaction: tx};
try {
const from = Date.vnNew();
from.setHours(0, 0, 0, 0);
const to = Date.vnNew();
to.setHours(23, 59, 59, 999);
const ctx = {
args: {
from: from,
to: to
}
};
const results = await models.AgencyTerm.filter(ctx, options);
expect(results.length).toBe(5);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('should return results matching "agencyModeFk"', async() => {
let ctx = {
args: {
agencyModeFk: 1,
}
};
let result = await app.models.AgencyTerm.filter(ctx);
expect(result.length).toEqual(1);
expect(result[0].routeFk).toEqual(1);
});
it('should return results matching "agencyFk"', async() => {
let ctx = {
args: {
agencyFk: 2,
}
};
let result = await app.models.AgencyTerm.filter(ctx);
expect(result.length).toEqual(1);
expect(result[0].routeFk).toEqual(2);
});
});

View File

@ -87,6 +87,8 @@ module.exports = Self => {
Self.filter = async(ctx, filter) => {
let conn = Self.dataSource.connector;
const userId = ctx.req.accessToken.userId;
const models = Self.app.models;
let where = buildFilter(ctx.args, (param, value) => {
switch (param) {
@ -110,6 +112,13 @@ module.exports = Self => {
filter = mergeFilters(filter, {where});
const worker = await models.Worker.findById(userId, {fields: ['isFreelance']});
const getMyRoute = await models.ACL.checkAccessAcl(ctx, 'Route', 'getRouteByAgency', 'WRITE');
if (userId && getMyRoute && worker.isFreelance) {
if (!filter.where) filter.where = {};
filter.where[`workerFk`] = userId;
}
let stmts = [];
let stmt;

View File

@ -8,14 +8,32 @@ describe('Route filter()', () => {
it('should return the routes matching "search"', async() => {
const ctx = {
args: {
search: 1,
search: 5,
},
req: {
accessToken: {
userId: 9
}
}
};
const result = await app.models.Route.filter(ctx);
expect(result.length).toEqual(1);
expect(result[0].id).toEqual(5);
});
it('should return all results matching the filter', async() => {
const ctx = {
req: {
accessToken: {
userId: 133
}
}
};
const result = await app.models.Route.filter(ctx);
expect(result.length).toEqual(1);
expect(result[0].id).toEqual(1);
expect(result.length).toEqual(3);
});
it('should return results matching "from" and "to"', async() => {
@ -32,12 +50,16 @@ describe('Route filter()', () => {
args: {
from: from,
to: to
},
req: {
accessToken: {
userId: 9
}
}
};
const results = await models.Route.filter(ctx, options);
expect(results.length).toBe(7);
expect(results.length).toBe(9);
await tx.rollback();
} catch (e) {
@ -50,6 +72,11 @@ describe('Route filter()', () => {
const ctx = {
args: {
m3: 0.1,
},
req: {
accessToken: {
userId: 9
}
}
};
@ -62,6 +89,11 @@ describe('Route filter()', () => {
const ctx = {
args: {
description: 'third route',
},
req: {
accessToken: {
userId: 9
}
}
};
@ -74,24 +106,33 @@ describe('Route filter()', () => {
const ctx = {
args: {
workerFk: 56,
},
req: {
accessToken: {
userId: 9
}
}
};
const result = await app.models.Route.filter(ctx);
expect(result.length).toEqual(5);
expect(result.length).toEqual(4);
});
it('should return the routes matching "warehouseFk"', async() => {
const ctx = {
args: {
warehouseFk: 1,
},
req: {
accessToken: {
userId: 9
}
}
};
let result = await app.models.Route.filter(ctx);
expect(result.length).toEqual(7);
expect(result.length).toEqual(9);
ctx.args.warehouseFk = 2;
@ -104,9 +145,13 @@ describe('Route filter()', () => {
const ctx = {
args: {
vehicleFk: 2,
},
req: {
accessToken: {
userId: 9
}
}
};
const result = await app.models.Route.filter(ctx);
expect(result.length).toEqual(1);
@ -116,6 +161,11 @@ describe('Route filter()', () => {
const ctx = {
args: {
agencyModeFk: 7,
},
req: {
accessToken: {
userId: 9
}
}
};

View File

@ -22,7 +22,7 @@ describe('route summary()', () => {
});
it(`should return a summary object containing it's worker`, async() => {
const result = await app.models.Route.summary(1);
const result = await app.models.Route.summary(2);
const worker = result.route.worker().user();
expect(worker.name).toEqual('delivery');

View File

@ -166,12 +166,11 @@ module.exports = Self => {
LEFT JOIN account.emailUser eu ON eu.userFk = u.id`
);
stmt.merge(conn.makeWhere(filter.where));
stmts.push(stmt);
stmt.merge(conn.makeSuffix(filter));
let itemsIndex = stmts.push(stmt) - 1;
const itemsIndex = stmts.push(stmt) - 1;
const sql = ParameterizedSQL.join(stmts, ';');
const result = await conn.executeStmt(sql, myOptions);
return result[itemsIndex];
let sql = ParameterizedSQL.join(stmts, ';');
let result = await conn.executeStmt(sql);
return itemsIndex === 0 ? result : result[itemsIndex];
};
};