Compare commits

...

29 Commits

Author SHA1 Message Date
David Domenech 31b07b31a9 Merge branch '6372-Delete-views-from-vn2008' of https://gitea.verdnatura.es/verdnatura/salix into 6372-Delete-views-from-vn2008
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-02-12 07:34:36 +01:00
David Domenech 6044c160f8 Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 6372-Delete-views-from-vn2008 2024-02-12 07:21:40 +01:00
Ivan Mas a0599403c8 Merge pull request 'fix: refs #6443 #6444 #6445 ChangeRevokeToGrant' (!2019) from 6443-6444-6445-fix-permissions into dev
gitea/salix/pipeline/head This commit looks good Details
Reviewed-on: #2019
Reviewed-by: Guillermo Bonet <guillermo@verdnatura.es>
2024-02-09 13:02:38 +00:00
Ivan Mas 222335809e Merge branch 'dev' into 6443-6444-6445-fix-permissions
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-02-09 13:00:47 +00:00
Jorge Penadés e96b14ad04 Merge pull request '#6806 fix lastEntriesFilter' (!2013) from 6806-fixEntryFilter into dev
gitea/salix/pipeline/head This commit looks good Details
Reviewed-on: #2013
Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
2024-02-09 12:47:17 +00:00
Jorge Penadés c3b0a8260a Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 6806-fixEntryFilter
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-02-09 13:38:59 +01:00
Ivan Mas 362d825202 fix: refs #6443 #6444 #6445 ChangeRevokeToGrant
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-02-09 13:38:09 +01:00
Carlos Satorres 3ee63e489e Merge pull request 'refs #6791 remake negativeBases' (!2017) from 6791-negativeNickname into dev
gitea/salix/pipeline/head This commit looks good Details
Reviewed-on: #2017
Reviewed-by: Alex Moreno <alexm@verdnatura.es>
2024-02-09 11:49:37 +00:00
Carlos Satorres e03e871529 Merge branch 'dev' into 6791-negativeNickname
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-02-09 11:47:36 +00:00
Carlos Satorres 1597f17230 refs #6791 remove intro
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-02-09 12:47:17 +01:00
Carlos Satorres 3e57bf2b34 refs #6791 remake negativeBases
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-02-09 11:49:29 +01:00
Jorge Penadés 3f08cdd51c Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 6806-fixEntryFilter
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-02-09 09:45:10 +01:00
Jorge Penadés e5f2be9f9c Merge pull request '#6272 updateFiscalData' (!2001) from 6272-updateFiscalData into dev
gitea/salix/pipeline/head This commit looks good Details
Reviewed-on: #2001
Reviewed-by: Alex Moreno <alexm@verdnatura.es>
2024-02-09 08:41:41 +00:00
Jorge Penadés 8cef56f4f8 Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 6272-updateFiscalData
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-02-09 09:35:28 +01:00
Juan Ferrer 26d4dbbe34 fix: refs#6706 docker-compose.yml fixes
gitea/salix/pipeline/head This commit looks good Details
2024-02-09 09:26:46 +01:00
Juan Ferrer f18191d6e9 refactor: refs#6706 root dir clean, minimist dep removed
gitea/salix/pipeline/head There was a failure building this commit Details
2024-02-09 09:23:00 +01:00
Jorge Penadés 4f9c1b8c95 Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 6272-updateFiscalData
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-02-09 07:49:32 +01:00
Jorge Penadés 30069ded15 fix: refs #6806 fix date filter
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-02-08 16:01:34 +01:00
Guillermo Bonet 8e8ee39302 Merge pull request 'refactor: refs #6609 sectorType description to code' (!2008) from 6609-sectorType into dev
gitea/salix/pipeline/head This commit looks good Details
gitea/salix/pipeline/pr-dev This commit looks good Details
Reviewed-on: #2008
Reviewed-by: Robert Ferrús <robert@verdnatura.es>
2024-02-08 11:19:38 +00:00
Guillermo Bonet 6a94a48a9d refactor: refs #6609 sectorType description to code
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-02-08 12:18:37 +01:00
Guillermo Bonet a2bb3c476c Merge branch '6609-sectorType' of https://gitea.verdnatura.es/verdnatura/salix into 6609-sectorType
gitea/salix/pipeline/pr-dev There was a failure building this commit Details
2024-02-08 12:08:20 +01:00
Guillermo Bonet 3f400f92e5 refactor: refs #6609 sectorType description to code 2024-02-08 12:08:19 +01:00
Guillermo Bonet 2676cb840c Merge branch 'dev' into 6609-sectorType
gitea/salix/pipeline/pr-dev There was a failure building this commit Details
2024-02-08 11:05:05 +00:00
Guillermo Bonet 2e009b6f25 refactor: refs #6609 sectorType description to code
gitea/salix/pipeline/pr-dev There was a failure building this commit Details
2024-02-08 12:04:34 +01:00
Ivan Mas 2b987d2461 Merge pull request 'refs #6443 migrate vn2008.cc_to_iban to util.accountNumberToIban' (!2006) from 6443-MigrateVn2008.cc_to_ibanToUtil into dev
gitea/salix/pipeline/head This commit looks good Details
Reviewed-on: #2006
Reviewed-by: Guillermo Bonet <guillermo@verdnatura.es>
2024-02-08 10:48:42 +00:00
Ivan Mas 3dfc85db42 Merge branch 'dev' into 6443-MigrateVn2008.cc_to_ibanToUtil
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-02-08 10:46:37 +00:00
Ivan Mas dee7019824 refs #6443 migrate vn2008.cc_to_iban to util.accountNumberToIban
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-02-08 10:50:56 +01:00
Jorge Penadés 06757640a3 Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 6272-updateFiscalData
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-02-08 08:15:39 +01:00
Jorge Penadés aff8ee28ea fix: refs #6272 back & create test
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-02-07 10:16:47 +01:00
27 changed files with 417 additions and 213 deletions

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),
(60, 'Algemesi', NULL, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0);
INSERT INTO `vn`.`sectorType` (id,description)
VALUES (1,'First type');
INSERT INTO `vn`.`sectorType` (`id`, `code`)
VALUES (1,'normal');
INSERT INTO `vn`.`sector`(`id`, `description`, `warehouseFk`, `code`, `typeFk`)
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.visible,
IFNULL(
IF(st.description = 'previousByPacking', ish.packing, g.`grouping`),
IF(st.code = 'previousByPacking', ish.packing, g.`grouping`),
1) `grouping`,
st.description = 'previousPrepared' isPreviousPrepared,
st.code = 'previousPrepared' isPreviousPrepared,
iss.id itemShelvingSaleFk,
ts.ticketFk,
iss.id,

View File

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

View File

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

View File

@ -15,7 +15,7 @@ AS SELECT `ish`.`itemFk` AS `itemFk`,
`sh`.`parkingFk` AS `parkingFk`,
`ish`.`id` AS `itemShelvingFk`,
`ish`.`created` AS `created`,
`st`.`description` = 'previousPrepared' AS `isPreviousPrepared`
`st`.`code` = 'previousPrepared' AS `isPreviousPrepared`
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

@ -18,11 +18,13 @@ services:
memory: 1G
back:
image: registry.verdnatura.es/salix-back:${VERSION:?}
build: .
build:
context: .
dockerfile: back/Dockerfile
environment:
- TZ
- NODE_ENV
- DEBUG
- TZ
ports:
- 3000
configs:

View File

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

View File

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

View File

@ -2,7 +2,6 @@
require('require-yaml');
const gulp = require('gulp');
const PluginError = require('plugin-error');
const argv = require('minimist')(process.argv.slice(2));
const log = require('fancy-log');
const Myt = require('@verdnatura/myt/myt');
const Run = require('@verdnatura/myt/myt-run');
@ -12,9 +11,6 @@ const Start = require('@verdnatura/myt/myt-start');
let isWindows = /^win/.test(process.platform);
if (argv.NODE_ENV)
process.env.NODE_ENV = argv.NODE_ENV;
let langs = ['es', 'en'];
let srcDir = './front';
let modulesDir = './modules';

View File

@ -10,7 +10,7 @@ module.exports = {
},
testEnvironment: 'jsdom',
setupFilesAfterEnv: [
'./jest-front.js'
'./front/jest-setup.js'
],
testMatch: [
'**/front/**/*.spec.js',
@ -37,7 +37,7 @@ module.exports = {
],
moduleNameMapper: {
'\\.(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',
verbose: false,

View File

@ -206,6 +206,5 @@
"Incorrect pin": "Incorrect pin.",
"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",
"Fecha fuera de rango": "Fecha fuera de rango",
"There is no zone for these parameters 34": "There is no zone for these parameters 34"
}
"You cannot update these fields": "You cannot update these fields"
}

View File

@ -338,6 +338,7 @@
"The alias cant be modified": "Este alias de correo no puede ser modificado",
"No tickets to invoice": "No hay tickets para facturar",
"Name should be uppercase": "El nombre debe ir en mayúscula",
"Bank entity must be specified": "La entidad bancaria es obligatoria",
"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,
c.id clientId,
c.socialName clientSocialName,
u.nickname workerSocialName,
SUM(s.quantity * s.price * ( 100 - s.discount ) / 100) amount,
negativeBase.taxableBase,
negativeBase.ticketFk,
@ -80,6 +81,7 @@ module.exports = Self => {
JOIN vn.client c ON c.id = t.clientFk
JOIN vn.country cou ON cou.id = c.countryFk
LEFT JOIN vn.worker w ON w.id = c.salesPersonFk
JOIN account.user u ON u.id = w.id
LEFT JOIN (
SELECT ticketFk, taxableBase
FROM tmp.ticketAmount

View File

@ -16,7 +16,7 @@ class Controller extends Section {
this.filter = {
where: {
itemFk: this.$params.id,
shipped: {
landed: {
between: [from, to]
}
}
@ -36,7 +36,7 @@ class Controller extends Section {
const to = new Date(this._dateTo);
to.setHours(23, 59, 59, 59);
this.filter.where.shipped = {
this.filter.where.landed = {
between: [from, to]
};
this.$.model.refresh();
@ -53,7 +53,7 @@ class Controller extends Section {
const to = new Date(value);
to.setHours(23, 59, 59, 59);
this.filter.where.shipped = {
this.filter.where.landed = {
between: [from, to]
};
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');
describe('Supplier updateFiscalData', () => {
describe('Supplier updateFiscalData()', () => {
const supplierId = 1;
const administrativeId = 5;
const employeeId = 1;
const defaultData = {
name: 'PLANTS SL',
nif: '06089160W',
account: '4100000001',
sageTaxTypeFk: 4,
sageWithholdingFk: 1,
sageTransactionTypeFk: 1,
postCode: '15214',
city: 'PONTEVEDRA',
provinceFk: 1,
countryFk: 1,
};
const buyerId = 35;
it('should return an error if the user is not administrative', async() => {
const ctx = {req: {accessToken: {userId: employeeId}}};
ctx.args = {};
const name = 'NEW PLANTS';
const city = 'PONTEVEDRA';
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;
await app.models.Supplier.updateFiscalData(ctx, supplierId)
.catch(e => {
error = e;
});
let ctx;
let options;
let tx;
expect(error.message).toBeDefined();
});
it('should check that the supplier fiscal data is untainted', async() => {
const supplier = await app.models.Supplier.findById(supplierId);
expect(supplier.name).toEqual(defaultData.name);
expect(supplier.nif).toEqual(defaultData.nif);
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},
beforeEach(async() => {
ctx = {
req: {
accessToken: {userId: buyerId},
headers: {origin: 'http://localhost'},
__: value => value
},
args: {}
};
const ctx = {req: activeCtx};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
active: ctx.req
});
ctx.args = {
name: 'WEAPON DEALER',
nif: 'A68446004',
account: '4000000005',
sageTaxTypeFk: 5,
sageWithholdingFk: 2,
sageTransactionTypeFk: 2,
postCode: '46460',
city: 'VALENCIA',
provinceFk: 2,
countryFk: 1,
supplierActivityFk: 'animals',
healthRegister: '400664487H'
};
options = {transaction: tx};
tx = await models.Sale.beginTransaction({});
options.transaction = tx;
});
const result = await app.models.Supplier.updateFiscalData(ctx, supplierId);
afterEach(async() => {
await tx.rollback();
});
expect(result.name).toEqual('WEAPON DEALER');
expect(result.nif).toEqual('A68446004');
expect(result.account).toEqual('4000000005');
expect(result.sageTaxTypeFk).toEqual(5);
expect(result.sageWithholdingFk).toEqual(2);
expect(result.sageTransactionTypeFk).toEqual(2);
expect(result.postCode).toEqual('46460');
expect(result.city).toEqual('VALENCIA');
expect(result.provinceFk).toEqual(2);
expect(result.countryFk).toEqual(1);
expect(result.supplierActivityFk).toEqual('animals');
expect(result.healthRegister).toEqual('400664487H');
it('should throw an error if it is a buyer and tries to update forbidden fiscal data', async() => {
try {
await models.Supplier.updateFiscalData(ctx,
supplierId,
name,
nif,
account,
undefined,
sageTaxTypeFk,
undefined,
sageTransactionTypeFk,
undefined,
undefined,
undefined,
provinceFk,
countryFk,
supplierActivityFk,
healthRegister,
undefined,
undefined,
options);
} catch (e) {
expect(e.message).toEqual('You cannot update these fields');
}
});
// Restores
ctx.args = defaultData;
await app.models.Supplier.updateFiscalData(ctx, supplierId);
it('should update the granted fiscal data if it is a buyer', async() => {
const supplier = await models.Supplier.updateFiscalData(ctx,
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 => {
Self.remoteMethod('updateFiscalData', {
Self.remoteMethodCtx('updateFiscalData', {
description: 'Updates fiscal data of a supplier',
accessType: 'WRITE',
accepts: [{
arg: 'ctx',
type: 'Object',
http: {source: 'context'}
},
{
arg: 'id',
type: 'Number',
description: 'The supplier id',
http: {source: 'path'}
},
{
}, {
arg: 'name',
type: 'string'
},
{
}, {
arg: 'nif',
type: 'string'
},
{
}, {
arg: 'account',
type: 'any'
},
{
}, {
arg: 'phone',
type: 'string'
}, {
arg: 'sageTaxTypeFk',
type: 'any'
},
{
}, {
arg: 'sageWithholdingFk',
type: 'any'
},
{
}, {
arg: 'sageTransactionTypeFk',
type: 'any'
},
{
}, {
arg: 'postCode',
type: 'any'
},
{
}, {
arg: 'street',
type: 'any'
},
{
}, {
arg: 'city',
type: 'string'
},
{
}, {
arg: 'provinceFk',
type: 'any'
},
{
}, {
arg: 'countryFk',
type: 'any'
},
{
}, {
arg: 'supplierActivityFk',
type: 'string'
},
{
}, {
arg: 'healthRegister',
type: 'string'
},
{
}, {
arg: 'isVies',
type: 'boolean'
},
{
}, {
arg: 'isTrucker',
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 args = ctx.args;
const {args} = ctx;
const myOptions = {};
const supplier = await models.Supplier.findById(supplierId);
// Remove unwanted properties
if (typeof options == 'object') Object.assign(myOptions, options);
delete args.ctx;
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

@ -90,7 +90,6 @@
"js-yaml": "^4.1.0",
"json-loader": "^0.5.7",
"merge-stream": "^1.0.1",
"minimist": "^1.2.5",
"node-sass": "^9.0.0",
"nodemon": "^2.0.16",
"plugin-error": "^1.0.1",

View File

@ -232,9 +232,6 @@ devDependencies:
merge-stream:
specifier: ^1.0.1
version: 1.0.1
minimist:
specifier: ^1.2.5
version: 1.2.8
node-sass:
specifier: ^9.0.0
version: 9.0.0