Merge branch 'dev' into 6392-balance-produccion-propia
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Javi Gallego 2024-02-12 08:45:53 +01:00
commit a18ddc8e9a
34 changed files with 547 additions and 263 deletions

View File

@ -1,4 +1,6 @@
node_modules node_modules
print/node_modules print/node_modules
front/node_modules front
services db
e2e
storage

31
Jenkinsfile vendored
View File

@ -5,9 +5,15 @@ def FROM_GIT
def RUN_TESTS def RUN_TESTS
def RUN_BUILD def RUN_BUILD
def BRANCH_ENV = [
test: 'test',
master: 'production'
]
node { node {
stage('Setup') { stage('Setup') {
env.NODE_ENV = 'dev' env.BACK_REPLICAS = 1
env.NODE_ENV = BRANCH_ENV[env.BRANCH_NAME] ?: 'dev'
PROTECTED_BRANCH = [ PROTECTED_BRANCH = [
'dev', 'dev',
@ -86,9 +92,6 @@ pipeline {
} }
} }
stage('Stack') { stage('Stack') {
environment {
TZ = 'Europe/Madrid'
}
parallel { parallel {
stage('Back') { stage('Back') {
stages { stages {
@ -104,14 +107,10 @@ pipeline {
} }
post { post {
always { always {
script { junit(
try { testResults: 'junitresults.xml',
junit 'junitresults.xml' allowEmptyResults: true
junit 'junit.xml' )
} catch (e) {
echo e.toString()
}
}
} }
} }
} }
@ -144,6 +143,14 @@ pipeline {
steps { steps {
sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=10' sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=10'
} }
post {
always {
junit(
testResults: 'junit.xml',
allowEmptyResults: true
)
}
}
} }
stage('Build') { stage('Build') {
when { when {

View File

@ -8,6 +8,26 @@ module.exports = Self => {
}); });
Self.validatesUniquenessOf('bic', { Self.validatesUniquenessOf('bic', {
message: 'This BIC already exist.' message: 'This BIC already exist'
}); });
Self.validatesPresenceOf('countryFk', {
message: 'CountryFK cannot be empty'
});
Self.validateAsync('bic', checkBic, {
message: 'Bank entity id must be specified'
});
async function checkBic(err, done) {
const filter = {
fields: ['code'],
where: {id: this.countryFk}
};
const country = await Self.app.models.Country.findOne(filter);
const code = country ? country.code.toLowerCase() : null;
if (code == 'es' && !this.id)
err();
done();
}
}; };

View File

@ -1,19 +1,36 @@
/* eslint-disable no-console */ /* eslint-disable no-console */
const path = require('path'); const path = require('path');
const getopts = require('getopts');
const Myt = require('@verdnatura/myt/myt'); const Myt = require('@verdnatura/myt/myt');
const Run = require('@verdnatura/myt/myt-run'); const Run = require('@verdnatura/myt/myt-run');
const helper = require('./tests-helper'); const helper = require('./tests-helper');
const opts = getopts(process.argv.slice(2), {
string: [
'network'
],
boolean: [
'ci',
'junit'
]
});
let server; let server;
const isCI = process.argv[2] === 'ci';
const PARALLEL = false; const PARALLEL = false;
const TIMEOUT = 900000; const TIMEOUT = 900000;
process.on('SIGINT', teardown);
process.on('exit', teardown); process.on('exit', teardown);
process.on('uncaughtException', onError); process.on('uncaughtException', onError);
process.on('unhandledRejection', onError); process.on('unhandledRejection', onError);
const exitSignals = [
'SIGINT',
'SIGUSR1',
'SIGUSR2'
];
for (const signal of exitSignals)
process.on(signal, () => process.exit());
async function setup() { async function setup() {
console.log('Building and running DB container.'); console.log('Building and running DB container.');
@ -21,9 +38,9 @@ async function setup() {
await myt.init({ await myt.init({
workspace: path.join(__dirname, '..'), workspace: path.join(__dirname, '..'),
random: true, random: true,
ci: isCI, ci: opts.ci,
tmpfs: process.platform == 'linux', tmpfs: process.platform == 'linux',
network: isCI ? 'jenkins' : null network: opts.network || null
}); });
server = await myt.run(Run); server = await myt.run(Run);
await myt.deinit(); await myt.deinit();
@ -38,18 +55,19 @@ async function setup() {
async function teardown() { async function teardown() {
if (!server) return; if (!server) return;
const oldServer = server;
server = null;
if (!PARALLEL) if (!PARALLEL)
await helper.deinit(); await helper.deinit();
console.log('Stopping and removing DB container.'); console.log('Stopping and removing DB container.');
await server.rm(); await oldServer.rm();
server = null;
} }
async function onError(err) { async function onError(err) {
await teardown();
console.error(err); console.error(err);
process.exit(1);
} }
async function test() { async function test() {
@ -79,8 +97,8 @@ async function test() {
const SpecReporter = require('jasmine-spec-reporter').SpecReporter; const SpecReporter = require('jasmine-spec-reporter').SpecReporter;
runner.addReporter(new SpecReporter({ runner.addReporter(new SpecReporter({
spec: { spec: {
displaySuccessful: isCI, displaySuccessful: opts.ci,
displayPending: isCI displayPending: opts.ci
}, },
summary: { summary: {
displayPending: false, displayPending: false,
@ -88,11 +106,12 @@ async function test() {
})); }));
} }
if (isCI) { if (opts.junit) {
const JunitReporter = require('jasmine-reporters'); const JunitReporter = require('jasmine-reporters');
runner.addReporter(new JunitReporter.JUnitXmlReporter()); runner.addReporter(new JunitReporter.JUnitXmlReporter());
runner.jasmine.DEFAULT_TIMEOUT_INTERVAL = TIMEOUT;
} }
if (opts.ci)
runner.jasmine.DEFAULT_TIMEOUT_INTERVAL = TIMEOUT;
// runner.loadConfigFile('back/jasmine.json'); // runner.loadConfigFile('back/jasmine.json');
runner.loadConfig(config); runner.loadConfig(config);

View File

@ -184,8 +184,8 @@ INSERT INTO `vn`.`warehouse`(`id`, `name`, `code`, `isComparative`, `isInventory
(13, 'Inventory', 'inv', 1, 1, 1, 0, 0, 0, 1, 0, 0, 0), (13, 'Inventory', 'inv', 1, 1, 1, 0, 0, 0, 1, 0, 0, 0),
(60, 'Algemesi', NULL, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0); (60, 'Algemesi', NULL, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0);
INSERT INTO `vn`.`sectorType` (id,description) INSERT INTO `vn`.`sectorType` (`id`, `code`)
VALUES (1,'First type'); VALUES (1,'normal');
INSERT INTO `vn`.`sector`(`id`, `description`, `warehouseFk`, `code`, `typeFk`) INSERT INTO `vn`.`sector`(`id`, `description`, `warehouseFk`, `code`, `typeFk`)
VALUES VALUES

View File

@ -0,0 +1,58 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`accountNumberToIban`(
vAccount VARCHAR(20)
)
RETURNS varchar(4) CHARSET utf8mb3 COLLATE utf8mb3_general_ci
DETERMINISTIC
BEGIN
/**
* Calcula y genera el código IBAN correspondiente
* a un número de cuenta bancaria español.
*
* @param vAccount Número de cuenta bancaria
* @return vIban Código IBAN de 4 caracteres.
*/
DECLARE vIban VARCHAR(4);
SELECT
CONCAT('ES',
RIGHT(
CONCAT(0,
98-MOD(
CONCAT(
MOD(
CONCAT(
MOD(
CONCAT(
MOD(
SUBSTRING(vAccount, 1, 8),
97
),
SUBSTRING(vAccount,9,8)
),
97
),
SUBSTRING(
CONCAT(vAccount, 142800),
17,
8
)
),
97
),
SUBSTRING(
CONCAT(vAccount, 142800),
25,
2
)
),
97
)
),
2
)
) INTO vIban;
RETURN vIban;
END$$
DELIMITER ;

View File

@ -70,9 +70,9 @@ BEGIN
ish.created, ish.created,
ish.visible, ish.visible,
IFNULL( IFNULL(
IF(st.description = 'previousByPacking', ish.packing, g.`grouping`), IF(st.code = 'previousByPacking', ish.packing, g.`grouping`),
1) `grouping`, 1) `grouping`,
st.description = 'previousPrepared' isPreviousPrepared, st.code = 'previousPrepared' isPreviousPrepared,
iss.id itemShelvingSaleFk, iss.id itemShelvingSaleFk,
ts.ticketFk, ts.ticketFk,
iss.id, iss.id,

View File

@ -15,11 +15,13 @@ BEGIN
p.code, p.code,
ish.id, ish.id,
s.priority, s.priority,
ish.isChecked ish.isChecked,
ic.url
FROM itemShelving ish FROM itemShelving ish
JOIN item i ON i.id = ish.itemFk JOIN item i ON i.id = ish.itemFk
JOIN shelving s ON vSelf = s.code COLLATE utf8_unicode_ci JOIN shelving s ON vSelf = s.code COLLATE utf8_unicode_ci
LEFT JOIN parking p ON s.parkingFk = p.id LEFT JOIN parking p ON s.parkingFk = p.id
JOIN hedera.imageConfig ic
WHERE ish.shelvingFk COLLATE utf8_unicode_ci = vSelf; WHERE ish.shelvingFk COLLATE utf8_unicode_ci = vSelf;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -207,7 +207,7 @@ proc: BEGIN
ENGINE = MEMORY ENGINE = MEMORY
SELECT ish.itemFk, SELECT ish.itemFk,
p.sectorFk, p.sectorFk,
st.description = 'previousPrepared' isPreviousPrepared, st.code = 'previousPrepared' isPreviousPrepared,
sc.itemPackingTypeFk sc.itemPackingTypeFk
FROM itemShelving ish FROM itemShelving ish
JOIN shelving sh ON sh.code = ish.shelvingFk JOIN shelving sh ON sh.code = ish.shelvingFk

View File

@ -85,7 +85,7 @@ BEGIN
JOIN client c ON c.id = t.clientFk JOIN client c ON c.id = t.clientFk
JOIN tmp.productionBuffer pb ON pb.ticketFk = t.id JOIN tmp.productionBuffer pb ON pb.ticketFk = t.id
JOIN packagingConfig pc JOIN packagingConfig pc
WHERE IF(st.description = 'previousByPacking', WHERE IF(st.code = 'previousByPacking',
i.`size` > pc.previousPreparationMinimumSize i.`size` > pc.previousPreparationMinimumSize
AND (MOD(TRUNCATE(isa.quantity,0), isa.packing)= 0 ), AND (MOD(TRUNCATE(isa.quantity,0), isa.packing)= 0 ),
TRUE) TRUE)

View File

@ -15,7 +15,7 @@ AS SELECT `ish`.`itemFk` AS `itemFk`,
`sh`.`parkingFk` AS `parkingFk`, `sh`.`parkingFk` AS `parkingFk`,
`ish`.`id` AS `itemShelvingFk`, `ish`.`id` AS `itemShelvingFk`,
`ish`.`created` AS `created`, `ish`.`created` AS `created`,
`st`.`description` = 'previousPrepared' AS `isPreviousPrepared` `st`.`code` = 'previousPrepared' AS `isPreviousPrepared`
FROM ( FROM (
( (
( (

View File

@ -1,49 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn2008`.`cc_to_iban`(cc VARCHAR(20))
RETURNS varchar(4) CHARSET utf8mb3 COLLATE utf8mb3_general_ci
DETERMINISTIC
BEGIN
DECLARE iban VARCHAR(4);
select
CONCAT('ES',
RIGHT(
concat(0,
98-
mod(
concat(
mod(
concat(
mod(
concat(
mod(
substring(cc,1,8),
97),
substring(cc,9,8)
),
97),
substring(
concat(
cc,
142800
),
17,
8
)
),
97),
substring(
concat(
cc,
142800
),
25,
2
)
),
97)
)
,2)
)into iban;
RETURN iban;
END$$
DELIMITER ;

View File

@ -1 +0,0 @@
REVOKE EXECUTE ON FUNCTION vn2008.red FROM hrBoss, salesPerson;

View File

@ -0,0 +1,3 @@
INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId)
VALUES ('Supplier', 'updateAllFiscalData', 'WRITE', 'ALLOW', 'ROLE', 'administrative'),
('Supplier', 'updateFiscalData', 'WRITE', 'ALLOW', 'ROLE', 'buyer');

View File

@ -0,0 +1,60 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`accountNumberToIban`(
vAccount VARCHAR(20)
)
RETURNS varchar(4) CHARSET utf8mb3 COLLATE utf8mb3_general_ci
DETERMINISTIC
BEGIN
/**
* Calcula y genera el código IBAN correspondiente
* a un número de cuenta bancaria español.
*
* @param vAccount Número de cuenta bancaria
* @return vIban Código IBAN de 4 caracteres.
*/
DECLARE vIban VARCHAR(4);
SELECT
CONCAT('ES',
RIGHT(
CONCAT(0,
98-MOD(
CONCAT(
MOD(
CONCAT(
MOD(
CONCAT(
MOD(
SUBSTRING(vAccount, 1, 8),
97
),
SUBSTRING(vAccount,9,8)
),
97
),
SUBSTRING(
CONCAT(vAccount, 142800),
17,
8
)
),
97
),
SUBSTRING(
CONCAT(vAccount, 142800),
25,
2
)
),
97
)
),
2
)
) INTO vIban;
RETURN vIban;
END$$
DELIMITER ;
GRANT EXECUTE ON FUNCTION util.accountNumberToIban TO hr, financial;

View File

@ -0,0 +1,38 @@
ALTER TABLE vn.sectorType CHANGE description code varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL;
-- Si no pongo lo de bajo da error en la view vn.itemShelvingAvailable
CREATE OR REPLACE DEFINER=`root`@`localhost`
SQL SECURITY DEFINER
VIEW `vn`.`itemShelvingStock`
AS SELECT `ish`.`itemFk` AS `itemFk`,
sum(`ish`.`visible`) AS `visible`,
min(`ish`.`packing`) AS `packing`,
min(`ish`.`grouping`) AS `grouping`,
`s`.`description` AS `sector`,
sum(`ish`.`visible`) AS `visibleOriginal`,
0 AS `removed`,
`p`.`sectorFk` AS `sectorFk`,
`s`.`warehouseFk` AS `warehouseFk`,
`ish`.`shelvingFk` AS `shelvingFk`,
`p`.`code` AS `parkingCode`,
`sh`.`parkingFk` AS `parkingFk`,
`ish`.`id` AS `itemShelvingFk`,
`ish`.`created` AS `created`,
`st`.`code` = 'previousPrepared' AS `isPreviousPrepared`
FROM (
(
(
(
`vn`.`itemShelving` `ish`
LEFT JOIN `vn`.`shelving` `sh` ON(`sh`.`code` = `ish`.`shelvingFk`)
)
LEFT JOIN `vn`.`parking` `p` ON(`p`.`id` = `sh`.`parkingFk`)
)
LEFT JOIN `vn`.`sector` `s` ON(`s`.`id` = `p`.`sectorFk`)
)
LEFT JOIN `vn`.`sectorType` `st` ON(`st`.`id` = `s`.`typeFk`)
)
WHERE `ish`.`visible` <> 0
AND `p`.`sectorFk` <> 0
GROUP BY `ish`.`itemFk`,
`p`.`sectorFk`;

View File

@ -0,0 +1,34 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`intrastat_estimateNet`(
vSelf INT,
vStems INT
)
RETURNS double
DETERMINISTIC
BEGIN
/**
* Calcula un valor neto estimado en función de
* datos históricos de facturas intrastat.
*
* @param vSelf Id de intrastat
* @param vStems Número de unidades
* @return vNet
*/
DECLARE vNet DOUBLE;
SELECT ROUND(vStems / (SUM(average) / COUNT(average)), 2) INTO vNet
FROM (
SELECT *, stems / net average
FROM invoiceInIntrastat
WHERE intrastatFk = vSelf
AND net
AND stems > 0
ORDER BY dated DESC
LIMIT 20
) sub;
RETURN vNet/2;
END$$
DELIMITER ;
GRANT EXECUTE ON FUNCTION vn.intrastat_estimateNet TO administrative;

View File

@ -3,8 +3,9 @@ services:
front: front:
image: registry.verdnatura.es/salix-front:${VERSION:?} image: registry.verdnatura.es/salix-front:${VERSION:?}
build: build:
context: . context: front
dockerfile: front/Dockerfile environment:
- TZ
ports: ports:
- 80 - 80
deploy: deploy:
@ -17,12 +18,15 @@ services:
memory: 1G memory: 1G
back: back:
image: registry.verdnatura.es/salix-back:${VERSION:?} image: registry.verdnatura.es/salix-back:${VERSION:?}
build: . build:
ports: context: .
- 3000 dockerfile: back/Dockerfile
environment: environment:
- TZ
- NODE_ENV - NODE_ENV
- DEBUG - DEBUG
ports:
- 3000
configs: configs:
- source: datasources - source: datasources
target: /etc/salix/datasources.json target: /etc/salix/datasources.json

View File

@ -1,7 +1,9 @@
/* eslint-disable no-console */
require('@babel/register')({presets: ['@babel/env']}); require('@babel/register')({presets: ['@babel/env']});
require('core-js/stable'); require('core-js/stable');
require('regenerator-runtime/runtime'); require('regenerator-runtime/runtime');
require('vn-loopback/server/boot/date')(); require('vn-loopback/server/boot/date')();
const getopts = require('getopts');
const path = require('path'); const path = require('path');
const Myt = require('@verdnatura/myt/myt'); const Myt = require('@verdnatura/myt/myt');
@ -18,12 +20,16 @@ process.on('warning', warning => {
}); });
async function test() { async function test() {
if (process.argv[2] === 'show') const opts = getopts(process.argv.slice(2), {
process.env.E2E_SHOW = true; boolean: ['show']
});
process.env.E2E_SHOW = opts.show;
console.log('Building and running DB container.');
const myt = new Myt(); const myt = new Myt();
await myt.init({workspace: path.join(__dirname, '../..')}); await myt.init({workspace: path.join(__dirname, '../..')});
await myt.run(Run); await myt.run(Run);
await myt.deinit();
const Jasmine = require('jasmine'); const Jasmine = require('jasmine');
const jasmine = new Jasmine(); const jasmine = new Jasmine();
@ -70,12 +76,10 @@ async function test() {
jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000; jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
await jasmine.execute(); await jasmine.execute();
await myt.deinit();
} }
async function backendStatus() { async function backendStatus() {
log('Awaiting backend connection...'); log('Awaiting backend connection.');
const milliseconds = 1000; const milliseconds = 1000;
const maxAttempts = 10; const maxAttempts = 10;

View File

@ -10,7 +10,7 @@ RUN apt-get update \
&& ln -sf /dev/stderr /var/log/nginx/error.log && ln -sf /dev/stderr /var/log/nginx/error.log
WORKDIR /etc/nginx WORKDIR /etc/nginx
COPY front/nginx.conf sites-available/salix COPY nginx.conf sites-available/salix
RUN rm sites-enabled/default && ln -s ../sites-available/salix sites-enabled/salix RUN rm sites-enabled/default && ln -s ../sites-available/salix sites-enabled/salix
COPY dist /salix/dist COPY dist /salix/dist

View File

@ -1,19 +1,19 @@
import 'angular'; import 'angular';
import 'angular-mocks'; import 'angular-mocks';
import core from './front/core/module.js'; import core from './core/module.js';
import './front/salix/components/app/app.js'; import './salix/components/app/app.js';
import './modules/zone/front/module.js'; import '../modules/zone/front/module.js';
import './modules/claim/front/module.js'; import '../modules/claim/front/module.js';
import './modules/client/front/module.js'; import '../modules/client/front/module.js';
import './modules/invoiceOut/front/module.js'; import '../modules/invoiceOut/front/module.js';
import './modules/invoiceIn/front/module.js'; import '../modules/invoiceIn/front/module.js';
import './modules/item/front/module.js'; import '../modules/item/front/module.js';
import './modules/order/front/module.js'; import '../modules/order/front/module.js';
import './modules/route/front/module.js'; import '../modules/route/front/module.js';
import './modules/ticket/front/module.js'; import '../modules/ticket/front/module.js';
import './modules/travel/front/module.js'; import '../modules/travel/front/module.js';
import './modules/worker/front/module.js'; import '../modules/worker/front/module.js';
import './modules/shelving/front/module.js'; import '../modules/shelving/front/module.js';
import 'vn-loopback/server/boot/date'; import 'vn-loopback/server/boot/date';
// Set NODE_ENV // Set NODE_ENV

View File

@ -1,7 +1,7 @@
/* eslint-disable no-console */
require('require-yaml'); require('require-yaml');
const gulp = require('gulp'); const gulp = require('gulp');
const PluginError = require('plugin-error'); const PluginError = require('plugin-error');
const argv = require('minimist')(process.argv.slice(2));
const log = require('fancy-log'); const log = require('fancy-log');
const Myt = require('@verdnatura/myt/myt'); const Myt = require('@verdnatura/myt/myt');
const Run = require('@verdnatura/myt/myt-run'); const Run = require('@verdnatura/myt/myt-run');
@ -11,13 +11,10 @@ const Start = require('@verdnatura/myt/myt-start');
let isWindows = /^win/.test(process.platform); let isWindows = /^win/.test(process.platform);
if (argv.NODE_ENV)
process.env.NODE_ENV = argv.NODE_ENV;
let langs = ['es', 'en']; let langs = ['es', 'en'];
let srcDir = './front'; let srcDir = './front';
let modulesDir = './modules'; let modulesDir = './modules';
let buildDir = 'dist'; let buildDir = 'front/dist';
let backSources = [ let backSources = [
'!node_modules', '!node_modules',
@ -67,19 +64,40 @@ back.description = `Starts backend and database service`;
const defaultTask = gulp.parallel(front, back); const defaultTask = gulp.parallel(front, back);
defaultTask.description = `Starts all application services`; defaultTask.description = `Starts all application services`;
function install() { async function install() {
const install = require('gulp-install'); const spawn = require('child_process').spawn;
const print = require('gulp-print');
let npmArgs = []; console.log('-> Installing global packages...');
if (argv.ci) npmArgs = ['--no-audit', '--prefer-offline']; await pnpmInstall();
let packageFiles = ['front/package.json', 'print/package.json']; const modules = ['front', 'print'];
return gulp.src(packageFiles) for (const module of modules) {
.pipe(print(filepath => { console.log(`-> Installing '${module}' packages...`);
return `Installing packages in ${filepath}`; await pnpmInstall(module);
})) }
.pipe(install({npm: npmArgs}));
async function pnpmInstall(prefix) {
let args = ['install', '--prefer-offline'];
if (prefix) args = args.concat(['--prefix', prefix]);
const options = {
stdio: [
process.stdin,
process.stdout,
process.stderr
]
};
await new Promise((resolve, reject) => {
const child = spawn('pnpm', args, options);
child.on('exit', code => {
if (code !== 0)
reject(new Error(`pnpm exit code ${code}`));
else
resolve(code);
});
});
}
} }
install.description = `Installs node dependencies in all directories`; install.description = `Installs node dependencies in all directories`;

View File

@ -10,7 +10,7 @@ module.exports = {
}, },
testEnvironment: 'jsdom', testEnvironment: 'jsdom',
setupFilesAfterEnv: [ setupFilesAfterEnv: [
'./jest-front.js' './front/jest-setup.js'
], ],
testMatch: [ testMatch: [
'**/front/**/*.spec.js', '**/front/**/*.spec.js',
@ -37,7 +37,7 @@ module.exports = {
], ],
moduleNameMapper: { moduleNameMapper: {
'\\.(css|scss)$': 'identity-obj-proxy', '\\.(css|scss)$': 'identity-obj-proxy',
'\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/fileMock.js', '\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/front/jest-mock.js',
}, },
testURL: 'http://localhost', testURL: 'http://localhost',
verbose: false, verbose: false,

View File

@ -198,6 +198,7 @@
"Booking completed": "Booking complete", "Booking completed": "Booking complete",
"The ticket is in preparation": "The ticket [{{ticketId}}]({{{ticketUrl}}}) of the sales person {{salesPersonId}} is in preparation", "The ticket is in preparation": "The ticket [{{ticketId}}]({{{ticketUrl}}}) of the sales person {{salesPersonId}} is in preparation",
"You can only add negative amounts in refund tickets": "You can only add negative amounts in refund tickets", "You can only add negative amounts in refund tickets": "You can only add negative amounts in refund tickets",
"Bank entity must be specified": "Bank entity must be specified",
"Try again": "Try again", "Try again": "Try again",
"keepPrice": "keepPrice", "keepPrice": "keepPrice",
"Cannot past travels with entries": "Cannot past travels with entries", "Cannot past travels with entries": "Cannot past travels with entries",
@ -205,6 +206,5 @@
"Incorrect pin": "Incorrect pin.", "Incorrect pin": "Incorrect pin.",
"The notification subscription of this worker cant be modified": "The notification subscription of this worker cant be modified", "The notification subscription of this worker cant be modified": "The notification subscription of this worker cant be modified",
"Name should be uppercase": "Name should be uppercase", "Name should be uppercase": "Name should be uppercase",
"Fecha fuera de rango": "Fecha fuera de rango", "You cannot update these fields": "You cannot update these fields"
"There is no zone for these parameters 34": "There is no zone for these parameters 34" }
}

View File

@ -338,5 +338,7 @@
"The alias cant be modified": "Este alias de correo no puede ser modificado", "The alias cant be modified": "Este alias de correo no puede ser modificado",
"No tickets to invoice": "No hay tickets para facturar", "No tickets to invoice": "No hay tickets para facturar",
"Name should be uppercase": "El nombre debe ir en mayúscula", "Name should be uppercase": "El nombre debe ir en mayúscula",
"An email is necessary": "Es necesario un email" "Bank entity must be specified": "La entidad bancaria es obligatoria",
} "An email is necessary": "Es necesario un email",
"You cannot update these fields": "No puedes actualizar estos campos"
}

View File

@ -66,6 +66,7 @@ module.exports = Self => {
cou.country, cou.country,
c.id clientId, c.id clientId,
c.socialName clientSocialName, c.socialName clientSocialName,
u.nickname workerSocialName,
SUM(s.quantity * s.price * ( 100 - s.discount ) / 100) amount, SUM(s.quantity * s.price * ( 100 - s.discount ) / 100) amount,
negativeBase.taxableBase, negativeBase.taxableBase,
negativeBase.ticketFk, negativeBase.ticketFk,
@ -80,6 +81,7 @@ module.exports = Self => {
JOIN vn.client c ON c.id = t.clientFk JOIN vn.client c ON c.id = t.clientFk
JOIN vn.country cou ON cou.id = c.countryFk JOIN vn.country cou ON cou.id = c.countryFk
LEFT JOIN vn.worker w ON w.id = c.salesPersonFk LEFT JOIN vn.worker w ON w.id = c.salesPersonFk
JOIN account.user u ON u.id = w.id
LEFT JOIN ( LEFT JOIN (
SELECT ticketFk, taxableBase SELECT ticketFk, taxableBase
FROM tmp.ticketAmount FROM tmp.ticketAmount

View File

@ -16,7 +16,7 @@ class Controller extends Section {
this.filter = { this.filter = {
where: { where: {
itemFk: this.$params.id, itemFk: this.$params.id,
shipped: { landed: {
between: [from, to] between: [from, to]
} }
} }
@ -36,7 +36,7 @@ class Controller extends Section {
const to = new Date(this._dateTo); const to = new Date(this._dateTo);
to.setHours(23, 59, 59, 59); to.setHours(23, 59, 59, 59);
this.filter.where.shipped = { this.filter.where.landed = {
between: [from, to] between: [from, to]
}; };
this.$.model.refresh(); this.$.model.refresh();
@ -53,7 +53,7 @@ class Controller extends Section {
const to = new Date(value); const to = new Date(value);
to.setHours(23, 59, 59, 59); to.setHours(23, 59, 59, 59);
this.filter.where.shipped = { this.filter.where.landed = {
between: [from, to] between: [from, to]
}; };
this.$.model.refresh(); this.$.model.refresh();

View File

@ -1,92 +1,142 @@
const app = require('vn-loopback/server/server'); const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context'); const LoopBackContext = require('loopback-context');
describe('Supplier updateFiscalData', () => { describe('Supplier updateFiscalData()', () => {
const supplierId = 1; const supplierId = 1;
const administrativeId = 5; const administrativeId = 5;
const employeeId = 1; const buyerId = 35;
const defaultData = {
name: 'PLANTS SL',
nif: '06089160W',
account: '4100000001',
sageTaxTypeFk: 4,
sageWithholdingFk: 1,
sageTransactionTypeFk: 1,
postCode: '15214',
city: 'PONTEVEDRA',
provinceFk: 1,
countryFk: 1,
};
it('should return an error if the user is not administrative', async() => { const name = 'NEW PLANTS';
const ctx = {req: {accessToken: {userId: employeeId}}}; const city = 'PONTEVEDRA';
ctx.args = {}; const nif = 'A68446004';
const account = '4000000005';
const sageTaxTypeFk = 5;
const sageWithholdingFk = 2;
const sageTransactionTypeFk = 2;
const postCode = '46460';
const phone = 456129367;
const street = ' Fake address 12 3 flat';
const provinceFk = 2;
const countryFk = 1;
const supplierActivityFk = 'animals';
const healthRegister = '400664487H';
let error; let ctx;
await app.models.Supplier.updateFiscalData(ctx, supplierId) let options;
.catch(e => { let tx;
error = e;
});
expect(error.message).toBeDefined(); beforeEach(async() => {
}); ctx = {
req: {
it('should check that the supplier fiscal data is untainted', async() => { accessToken: {userId: buyerId},
const supplier = await app.models.Supplier.findById(supplierId); headers: {origin: 'http://localhost'},
__: value => value
expect(supplier.name).toEqual(defaultData.name); },
expect(supplier.nif).toEqual(defaultData.nif); args: {}
expect(supplier.account).toEqual(defaultData.account);
expect(supplier.sageTaxTypeFk).toEqual(defaultData.sageTaxTypeFk);
expect(supplier.sageWithholdingFk).toEqual(defaultData.sageWithholdingFk);
expect(supplier.sageTransactionTypeFk).toEqual(defaultData.sageTransactionTypeFk);
expect(supplier.postCode).toEqual(defaultData.postCode);
expect(supplier.city).toEqual(defaultData.city);
expect(supplier.provinceFk).toEqual(defaultData.provinceFk);
expect(supplier.countryFk).toEqual(defaultData.countryFk);
});
it('should update the supplier fiscal data and return the count if changes made', async() => {
const activeCtx = {
accessToken: {userId: administrativeId},
}; };
const ctx = {req: activeCtx};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx active: ctx.req
}); });
ctx.args = { options = {transaction: tx};
name: 'WEAPON DEALER', tx = await models.Sale.beginTransaction({});
nif: 'A68446004', options.transaction = tx;
account: '4000000005', });
sageTaxTypeFk: 5,
sageWithholdingFk: 2,
sageTransactionTypeFk: 2,
postCode: '46460',
city: 'VALENCIA',
provinceFk: 2,
countryFk: 1,
supplierActivityFk: 'animals',
healthRegister: '400664487H'
};
const result = await app.models.Supplier.updateFiscalData(ctx, supplierId); afterEach(async() => {
await tx.rollback();
});
expect(result.name).toEqual('WEAPON DEALER'); it('should throw an error if it is a buyer and tries to update forbidden fiscal data', async() => {
expect(result.nif).toEqual('A68446004'); try {
expect(result.account).toEqual('4000000005'); await models.Supplier.updateFiscalData(ctx,
expect(result.sageTaxTypeFk).toEqual(5); supplierId,
expect(result.sageWithholdingFk).toEqual(2); name,
expect(result.sageTransactionTypeFk).toEqual(2); nif,
expect(result.postCode).toEqual('46460'); account,
expect(result.city).toEqual('VALENCIA'); undefined,
expect(result.provinceFk).toEqual(2); sageTaxTypeFk,
expect(result.countryFk).toEqual(1); undefined,
expect(result.supplierActivityFk).toEqual('animals'); sageTransactionTypeFk,
expect(result.healthRegister).toEqual('400664487H'); undefined,
undefined,
undefined,
provinceFk,
countryFk,
supplierActivityFk,
healthRegister,
undefined,
undefined,
options);
} catch (e) {
expect(e.message).toEqual('You cannot update these fields');
}
});
// Restores it('should update the granted fiscal data if it is a buyer', async() => {
ctx.args = defaultData; const supplier = await models.Supplier.updateFiscalData(ctx,
await app.models.Supplier.updateFiscalData(ctx, supplierId); supplierId,
undefined,
undefined,
account,
phone,
undefined,
undefined,
undefined,
postCode,
street,
city,
provinceFk,
undefined,
undefined,
undefined,
undefined,
undefined,
options);
expect(supplier.account).toEqual(account);
expect(supplier.phone).toEqual(phone);
expect(supplier.postCode).toEqual(postCode);
expect(supplier.account).toEqual(account);
expect(supplier.city).toEqual(city);
expect(supplier.provinceFk).toEqual(provinceFk);
});
it('should update all fiscalData if it is an administative', async() => {
const supplier = await models.Supplier.updateFiscalData(ctx,
supplierId,
name,
nif,
account,
phone,
sageTaxTypeFk,
sageWithholdingFk,
sageTransactionTypeFk,
postCode,
street,
city,
provinceFk,
countryFk,
supplierActivityFk,
healthRegister,
undefined,
undefined,
options);
expect(supplier.name).toEqual(name);
expect(supplier.nif).toEqual(nif);
expect(supplier.account).toEqual(account);
expect(supplier.phone).toEqual(phone);
expect(supplier.sageTaxTypeFk).toEqual(sageTaxTypeFk);
expect(supplier.sageWithholdingFk).toEqual(sageWithholdingFk);
expect(supplier.sageTransactionTypeFk).toEqual(sageTransactionTypeFk);
expect(supplier.postCode).toEqual(postCode);
expect(supplier.street).toEqual(street);
expect(supplier.city).toEqual(city);
expect(supplier.provinceFk).toEqual(provinceFk);
expect(supplier.countryFk).toEqual(countryFk);
expect(supplier.supplierActivityFk).toEqual(supplierActivityFk);
expect(supplier.healthRegister).toEqual(healthRegister);
}); });
}); });

View File

@ -1,75 +1,59 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => { module.exports = Self => {
Self.remoteMethod('updateFiscalData', { Self.remoteMethodCtx('updateFiscalData', {
description: 'Updates fiscal data of a supplier', description: 'Updates fiscal data of a supplier',
accessType: 'WRITE', accessType: 'WRITE',
accepts: [{ accepts: [{
arg: 'ctx',
type: 'Object',
http: {source: 'context'}
},
{
arg: 'id', arg: 'id',
type: 'Number', type: 'Number',
description: 'The supplier id', description: 'The supplier id',
http: {source: 'path'} http: {source: 'path'}
}, }, {
{
arg: 'name', arg: 'name',
type: 'string' type: 'string'
}, }, {
{
arg: 'nif', arg: 'nif',
type: 'string' type: 'string'
}, }, {
{
arg: 'account', arg: 'account',
type: 'any' type: 'any'
}, }, {
{ arg: 'phone',
type: 'string'
}, {
arg: 'sageTaxTypeFk', arg: 'sageTaxTypeFk',
type: 'any' type: 'any'
}, }, {
{
arg: 'sageWithholdingFk', arg: 'sageWithholdingFk',
type: 'any' type: 'any'
}, }, {
{
arg: 'sageTransactionTypeFk', arg: 'sageTransactionTypeFk',
type: 'any' type: 'any'
}, }, {
{
arg: 'postCode', arg: 'postCode',
type: 'any' type: 'any'
}, }, {
{
arg: 'street', arg: 'street',
type: 'any' type: 'any'
}, }, {
{
arg: 'city', arg: 'city',
type: 'string' type: 'string'
}, }, {
{
arg: 'provinceFk', arg: 'provinceFk',
type: 'any' type: 'any'
}, }, {
{
arg: 'countryFk', arg: 'countryFk',
type: 'any' type: 'any'
}, }, {
{
arg: 'supplierActivityFk', arg: 'supplierActivityFk',
type: 'string' type: 'string'
}, }, {
{
arg: 'healthRegister', arg: 'healthRegister',
type: 'string' type: 'string'
}, }, {
{
arg: 'isVies', arg: 'isVies',
type: 'boolean' type: 'boolean'
}, }, {
{
arg: 'isTrucker', arg: 'isTrucker',
type: 'boolean' type: 'boolean'
}], }],
@ -84,15 +68,42 @@ module.exports = Self => {
} }
}); });
Self.updateFiscalData = async(ctx, supplierId) => { Self.updateFiscalData = async(ctx, supplierId, name, nif, account, phone, sageTaxTypeFk, sageWithholdingFk, sageTransactionTypeFk, postCode, street, city, provinceFk, countryFk, supplierActivityFk, healthRegister, isVies, isTrucker, options) => {
const models = Self.app.models; const models = Self.app.models;
const args = ctx.args; const {args} = ctx;
const myOptions = {};
const supplier = await models.Supplier.findById(supplierId); const supplier = await models.Supplier.findById(supplierId);
// Remove unwanted properties if (typeof options == 'object') Object.assign(myOptions, options);
delete args.ctx; delete args.ctx;
delete args.id; delete args.id;
return supplier.updateAttributes(args); const updateAllFiscalData = await models.ACL.checkAccessAcl(ctx, 'Supplier', 'updateAllFiscalData', 'WRITE');
if (!updateAllFiscalData) {
for (const arg in args) {
if (args[arg] && !['street', 'postCode', 'city', 'provinceFk', 'phone'].includes(arg))
throw new UserError('You cannot update these fields');
}
}
return supplier.updateAttributes({
name,
nif,
account,
phone,
sageTaxTypeFk,
sageWithholdingFk,
sageTransactionTypeFk,
postCode,
street,
city,
provinceFk,
countryFk,
supplierActivityFk,
healthRegister,
isVies,
isTrucker
}, myOptions);
}; };
}; };

View File

@ -55,7 +55,7 @@
"@babel/plugin-syntax-dynamic-import": "^7.7.4", "@babel/plugin-syntax-dynamic-import": "^7.7.4",
"@babel/preset-env": "^7.11.0", "@babel/preset-env": "^7.11.0",
"@babel/register": "^7.7.7", "@babel/register": "^7.7.7",
"@verdnatura/myt": "^1.6.3", "@verdnatura/myt": "^1.6.6",
"angular-mocks": "^1.7.9", "angular-mocks": "^1.7.9",
"babel-jest": "^26.0.1", "babel-jest": "^26.0.1",
"babel-loader": "^8.2.4", "babel-loader": "^8.2.4",
@ -67,6 +67,7 @@
"eslint-plugin-jasmine": "^2.10.1", "eslint-plugin-jasmine": "^2.10.1",
"fancy-log": "^1.3.2", "fancy-log": "^1.3.2",
"file-loader": "^6.2.0", "file-loader": "^6.2.0",
"getopts": "^2.3.0",
"gulp": "^4.0.2", "gulp": "^4.0.2",
"gulp-concat": "^2.6.1", "gulp-concat": "^2.6.1",
"gulp-env": "^0.4.0", "gulp-env": "^0.4.0",
@ -89,7 +90,6 @@
"js-yaml": "^4.1.0", "js-yaml": "^4.1.0",
"json-loader": "^0.5.7", "json-loader": "^0.5.7",
"merge-stream": "^1.0.1", "merge-stream": "^1.0.1",
"minimist": "^1.2.5",
"node-sass": "^9.0.0", "node-sass": "^9.0.0",
"nodemon": "^2.0.16", "nodemon": "^2.0.16",
"plugin-error": "^1.0.1", "plugin-error": "^1.0.1",
@ -107,7 +107,7 @@
"scripts": { "scripts": {
"dbtest": "nodemon -q db/tests.js -w db/tests", "dbtest": "nodemon -q db/tests.js -w db/tests",
"test:back": "nodemon -q back/tests.js --config back/nodemonConfig.json", "test:back": "nodemon -q back/tests.js --config back/nodemonConfig.json",
"test:back:ci": "node back/tests.js ci", "test:back:ci": "node back/tests.js --ci --junit --network jenkins",
"test:e2e": "node e2e/helpers/tests.js", "test:e2e": "node e2e/helpers/tests.js",
"test:front": "jest --watch", "test:front": "jest --watch",
"back": "nodemon --inspect -w modules ./node_modules/gulp/bin/gulp.js back", "back": "nodemon --inspect -w modules ./node_modules/gulp/bin/gulp.js back",

View File

@ -128,8 +128,8 @@ devDependencies:
specifier: ^7.7.7 specifier: ^7.7.7
version: 7.23.7(@babel/core@7.23.9) version: 7.23.7(@babel/core@7.23.9)
'@verdnatura/myt': '@verdnatura/myt':
specifier: ^1.6.3 specifier: ^1.6.6
version: 1.6.3 version: 1.6.6
angular-mocks: angular-mocks:
specifier: ^1.7.9 specifier: ^1.7.9
version: 1.8.3 version: 1.8.3
@ -163,6 +163,9 @@ devDependencies:
file-loader: file-loader:
specifier: ^6.2.0 specifier: ^6.2.0
version: 6.2.0(webpack@5.90.1) version: 6.2.0(webpack@5.90.1)
getopts:
specifier: ^2.3.0
version: 2.3.0
gulp: gulp:
specifier: ^4.0.2 specifier: ^4.0.2
version: 4.0.2 version: 4.0.2
@ -229,9 +232,6 @@ devDependencies:
merge-stream: merge-stream:
specifier: ^1.0.1 specifier: ^1.0.1
version: 1.0.1 version: 1.0.1
minimist:
specifier: ^1.2.5
version: 1.2.8
node-sass: node-sass:
specifier: ^9.0.0 specifier: ^9.0.0
version: 9.0.0 version: 9.0.0
@ -2630,8 +2630,8 @@ packages:
dev: false dev: false
optional: true optional: true
/@verdnatura/myt@1.6.3: /@verdnatura/myt@1.6.6:
resolution: {integrity: sha512-VRoTB5sEPL8a7VaX9l2afpaPNT6pBa+If1tP9tpaJ4enFQbNITlApcC0GK6XYmWMkJQjl2lgdN4/u0UCiNb2MQ==} resolution: {integrity: sha512-5KHi9w1baEQ6Oe/pAR8pl0oD5yyJJuPirE+ZhygreUGGURfig4VekjhlGE3WEbWquDiIAMi89J1VQ+1Ba0+jQw==}
hasBin: true hasBin: true
dependencies: dependencies:
'@sqltools/formatter': 1.2.5 '@sqltools/formatter': 1.2.5

View File

@ -11,7 +11,7 @@ let baseConfig = {
entry: {salix: 'salix'}, entry: {salix: 'salix'},
mode, mode,
output: { output: {
path: path.join(__dirname, 'dist'), path: path.join(__dirname, 'front/dist'),
publicPath: '/' publicPath: '/'
}, },
module: { module: {
@ -139,7 +139,7 @@ let devConfig = {
host: '0.0.0.0', host: '0.0.0.0',
port: 5000, port: 5000,
publicPath: '/', publicPath: '/',
contentBase: 'dist', contentBase: 'front/dist',
quiet: false, quiet: false,
noInfo: false, noInfo: false,
hot: true, hot: true,