Merge branch 'master' into 6403-useServiceWeightOnCreateShipment
This commit is contained in:
commit
f48b5bae70
|
@ -4,21 +4,45 @@ module.exports = Self => {
|
|||
/**
|
||||
* Returns basic headers
|
||||
*
|
||||
* @param {string} cookie - The docuware cookie
|
||||
* @return {object} - The headers
|
||||
*/
|
||||
Self.getOptions = async() => {
|
||||
const docuwareConfig = await Self.app.models.DocuwareConfig.findOne();
|
||||
const now = Date.vnNow();
|
||||
let {url, username, password, token, expired} = docuwareConfig;
|
||||
|
||||
if (process.env.NODE_ENV && (!expired || expired < now + 60)) {
|
||||
const {data: {IdentityServiceUrl}} = await axios.get(`${url}/Home/IdentityServiceInfo`);
|
||||
const {data: {token_endpoint}} = await axios.get(`${IdentityServiceUrl}/.well-known/openid-configuration`);
|
||||
const {data} = await axios.post(token_endpoint, {
|
||||
grant_type: 'password',
|
||||
scope: 'docuware.platform',
|
||||
client_id: 'docuware.platform.net.client',
|
||||
username,
|
||||
password
|
||||
}, {headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
}});
|
||||
|
||||
const newToken = data.access_token;
|
||||
token = data.token_type + ' ' + newToken;
|
||||
await docuwareConfig.updateAttributes({
|
||||
token,
|
||||
expired: now + data.expires_in
|
||||
});
|
||||
}
|
||||
|
||||
const headers = {
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
'Cookie': docuwareConfig.cookie
|
||||
'Authorization': token
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
url: docuwareConfig.url,
|
||||
url,
|
||||
headers
|
||||
};
|
||||
};
|
||||
|
|
|
@ -2,87 +2,54 @@ const axios = require('axios');
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
describe('Docuware core', () => {
|
||||
beforeAll(() => {
|
||||
const fileCabinetCode = 'deliveryNote';
|
||||
beforeAll(async() => {
|
||||
process.env.NODE_ENV = 'testing';
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
delete process.env.NODE_ENV;
|
||||
});
|
||||
|
||||
describe('getOptions()', () => {
|
||||
it('should return url and headers', async() => {
|
||||
const result = await models.Docuware.getOptions();
|
||||
|
||||
expect(result.url).toBeDefined();
|
||||
expect(result.headers).toBeDefined();
|
||||
const docuwareInfo = await models.Docuware.findOne({
|
||||
where: {
|
||||
code: fileCabinetCode
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('getDialog()', () => {
|
||||
it('should return dialogId', async() => {
|
||||
const dialogs = {
|
||||
data: {
|
||||
Dialog: [
|
||||
{
|
||||
DisplayName: 'find',
|
||||
Id: 'getDialogTest'
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(dialogs)));
|
||||
const result = await models.Docuware.getDialog('deliveryNote', 'find', 'randomFileCabinetId');
|
||||
spyOn(axios, 'get').and.callFake(url => {
|
||||
if (url.includes('IdentityServiceInfo')) return {data: {IdentityServiceUrl: 'IdentityServiceUrl'}};
|
||||
if (url.includes('IdentityServiceUrl')) return {data: {token_endpoint: 'token_endpoint'}};
|
||||
if (url.includes('dialogs')) {
|
||||
return {
|
||||
data: {
|
||||
Dialog: [
|
||||
{
|
||||
DisplayName: 'find',
|
||||
Id: 'getDialogTest'
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
expect(result).toEqual('getDialogTest');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getFileCabinet()', () => {
|
||||
it('should return fileCabinetId', async() => {
|
||||
const code = 'deliveryNote';
|
||||
const docuwareInfo = await models.Docuware.findOne({
|
||||
where: {
|
||||
code
|
||||
}
|
||||
});
|
||||
const dialogs = {
|
||||
data: {
|
||||
if (url.includes('FileCabinets')) {
|
||||
return {data: {
|
||||
FileCabinet: [
|
||||
{
|
||||
Name: docuwareInfo.fileCabinetName,
|
||||
Id: 'getFileCabinetTest'
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(dialogs)));
|
||||
const result = await models.Docuware.getFileCabinet(code);
|
||||
|
||||
expect(result).toEqual('getFileCabinetTest');
|
||||
});
|
||||
});
|
||||
|
||||
describe('get()', () => {
|
||||
it('should return data without parse', async() => {
|
||||
spyOn(models.Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
||||
spyOn(models.Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
||||
const data = {
|
||||
data: {
|
||||
id: 1
|
||||
}
|
||||
};
|
||||
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data)));
|
||||
const result = await models.Docuware.get('deliveryNote');
|
||||
|
||||
expect(result.id).toEqual(1);
|
||||
}};
|
||||
}
|
||||
});
|
||||
|
||||
it('should return data with parse', async() => {
|
||||
spyOn(models.Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
||||
spyOn(models.Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
||||
const data = {
|
||||
data: {
|
||||
spyOn(axios, 'post').and.callFake(url => {
|
||||
if (url.includes('token_endpoint')) {
|
||||
return {data: {
|
||||
access_token: 'access_token',
|
||||
token_type: 'bearer',
|
||||
expires_in: 10000
|
||||
}};
|
||||
}
|
||||
if (url.includes('DialogExpression')) {
|
||||
return {data: {
|
||||
Items: [{
|
||||
Fields: [
|
||||
{
|
||||
|
@ -103,12 +70,52 @@ describe('Docuware core', () => {
|
|||
]
|
||||
}]
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
delete process.env.NODE_ENV;
|
||||
});
|
||||
|
||||
describe('getOptions()', () => {
|
||||
it('should return url and headers', async() => {
|
||||
const result = await models.Docuware.getOptions();
|
||||
|
||||
expect(result.url).toBeDefined();
|
||||
expect(result.headers).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Dialog()', () => {
|
||||
it('should return dialogId', async() => {
|
||||
const result = await models.Docuware.getDialog('deliveryNote', 'find', 'randomFileCabinetId');
|
||||
|
||||
expect(result).toEqual('getDialogTest');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getFileCabinet()', () => {
|
||||
it('should return fileCabinetId', async() => {
|
||||
const result = await models.Docuware.getFileCabinet(fileCabinetCode);
|
||||
|
||||
expect(result).toEqual('getFileCabinetTest');
|
||||
});
|
||||
});
|
||||
|
||||
describe('get()', () => {
|
||||
it('should return data without parse', async() => {
|
||||
const [result] = await models.Docuware.get('deliveryNote');
|
||||
|
||||
expect(result.firstRequiredField).toEqual(1);
|
||||
});
|
||||
|
||||
it('should return data with parse', async() => {
|
||||
const parse = {
|
||||
'firstRequiredField': 'id',
|
||||
'secondRequiredField': 'name',
|
||||
};
|
||||
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data)));
|
||||
const [result] = await models.Docuware.get('deliveryNote', null, parse);
|
||||
|
||||
expect(result.id).toEqual(1);
|
||||
|
@ -119,17 +126,14 @@ describe('Docuware core', () => {
|
|||
|
||||
describe('getById()', () => {
|
||||
it('should return data', async() => {
|
||||
spyOn(models.Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
||||
spyOn(models.Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
||||
const data = {
|
||||
data: {
|
||||
id: 1
|
||||
}
|
||||
};
|
||||
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data)));
|
||||
const result = await models.Docuware.getById('deliveryNote', 1);
|
||||
spyOn(models.Docuware, 'get');
|
||||
await models.Docuware.getById('deliveryNote', 1);
|
||||
|
||||
expect(result.id).toEqual(1);
|
||||
expect(models.Docuware.get).toHaveBeenCalledWith(
|
||||
'deliveryNote',
|
||||
{condition: [Object({DBName: 'N__ALBAR_N', Value: [1]})]},
|
||||
undefined
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -143,7 +143,7 @@ module.exports = Self => {
|
|||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
'X-File-ModifiedDate': Date.vnNew(),
|
||||
'Cookie': docuwareOptions.headers.headers.Cookie,
|
||||
'Authorization': docuwareOptions.headers.headers.Authorization,
|
||||
...data.getHeaders()
|
||||
},
|
||||
};
|
||||
|
|
|
@ -72,9 +72,9 @@ describe('Renew Token', () => {
|
|||
}
|
||||
|
||||
expect(error).toBeDefined();
|
||||
const query = 'SELECT * FROM util.debug';
|
||||
|
||||
const debugLog = await models.Application.rawSql(query, null);
|
||||
const query = 'SELECT * FROM util.debug WHERE variable = "renewToken"';
|
||||
const debugLog = await models.Application.rawSql(query);
|
||||
|
||||
expect(debugLog.length).toEqual(1);
|
||||
});
|
||||
|
|
|
@ -16,17 +16,17 @@
|
|||
"url": {
|
||||
"type": "string"
|
||||
},
|
||||
"cookie": {
|
||||
"token": {
|
||||
"type": "string"
|
||||
},
|
||||
"username": {
|
||||
"type": "string"
|
||||
},
|
||||
"password": {
|
||||
"type": "string"
|
||||
},
|
||||
"expired":{
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"acls": [
|
||||
{
|
||||
"property": "*",
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -403,7 +403,7 @@ INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city
|
|||
(1112, 'Trash', NULL, 'GARBAGE MAN', 'Unknown name', 'NEW YORK CITY, UNDERGROUND', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 0, 1, 0, NULL, 1, 0, NULL, 0, 'others','loses');
|
||||
|
||||
INSERT INTO `vn`.`client`(`id`, `name`, `fi`, `socialName`, `contact`, `street`, `city`, `postcode`, `isRelevant`, `email`, `iban`,`dueDay`,`accountingAccount`, `isEqualizated`, `provinceFk`, `hasToInvoice`, `credit`, `countryFk`, `isActive`, `gestdocFk`, `quality`, `payMethodFk`,`created`, `isTaxDataChecked`)
|
||||
SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), UPPER(CONCAT(name, 'Social')), CONCAT(name, 'Contact'), CONCAT(name, 'Street'), 'GOTHAM', 46460, 1, CONCAT(name,'@mydomain.com'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5, util.VN_CURDATE(), 1
|
||||
SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), UPPER(CONCAT(name, 'Social')), CONCAT(name, 'Contact'), UPPER(CONCAT(name, 'Street')), 'GOTHAM', 46460, 1, CONCAT(name,'@mydomain.com'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5, util.VN_CURDATE(), 1
|
||||
FROM `account`.`role` `r`
|
||||
WHERE `r`.`hasLogin` = 1;
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` EVENT `vn`.`itemCampaig_add`
|
||||
ON SCHEDULE EVERY 1 DAY
|
||||
STARTS '2024-10-18 03:00:00.000'
|
||||
ON COMPLETION PRESERVE
|
||||
ENABLE
|
||||
DO CALL itemCampaign_add()$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,54 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemCampaign_add`()
|
||||
proc: BEGIN
|
||||
/**
|
||||
* Añade registros a tabla itemCampaign.
|
||||
*
|
||||
* @param vDateFrom Fecha desde
|
||||
* @param vDateTo Fecha hasta
|
||||
* @param vCampaign Código de la campaña
|
||||
*/
|
||||
DECLARE vYesterday DATE;
|
||||
DECLARE vCampaign VARCHAR(100);
|
||||
DECLARE vScopeDays INT;
|
||||
DECLARE vPreviousDays INT;
|
||||
DECLARE vDateSumFrom DATE;
|
||||
DECLARE vDateSumTo DATE;
|
||||
|
||||
SET vYesterday = util.yesterday();
|
||||
|
||||
SELECT dated, code, scopeDays, previousDays
|
||||
INTO vDateSumTo, vCampaign, vScopeDays, vPreviousDays
|
||||
FROM campaign
|
||||
WHERE dated >= vYesterday
|
||||
ORDER BY dated
|
||||
LIMIT 1;
|
||||
|
||||
IF vCampaign IS NULL THEN
|
||||
CALL util.throw('Missing data in campaign table');
|
||||
END IF;
|
||||
|
||||
IF NOT vYesterday BETWEEN vDateSumTo - INTERVAL vPreviousDays DAY
|
||||
AND vDateSumTo THEN
|
||||
LEAVE proc;
|
||||
END IF;
|
||||
|
||||
SET vDateSumFrom = vDateSumTo - INTERVAL vScopeDays DAY;
|
||||
SET vDateSumTo = vDateSumTo - INTERVAL 1 DAY;
|
||||
|
||||
INSERT INTO itemCampaign(dated, itemFk, quantity, total, campaign)
|
||||
SELECT vYesterday,
|
||||
s.itemFk,
|
||||
SUM(s.quantity) quantity,
|
||||
SUM((s.quantity * s.price) * (100 - s.discount) / 100) total,
|
||||
vCampaign
|
||||
FROM sale s
|
||||
JOIN ticket t ON t.id = s.ticketFk
|
||||
JOIN client c ON c.id = t.clientFk
|
||||
WHERE t.shipped BETWEEN vDateSumFrom AND util.dayEnd(vDateSumTo)
|
||||
AND c.typeFk = 'normal'
|
||||
AND NOT t.isDeleted
|
||||
GROUP BY s.itemFk
|
||||
HAVING quantity;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -20,6 +20,7 @@ proc: BEGIN
|
|||
DECLARE vUserFk INT;
|
||||
DECLARE vTotalReservedQuantity INT;
|
||||
DECLARE vSaleQuantity INT;
|
||||
DECLARE vIsRequiredTx BOOL DEFAULT NOT @@in_transaction;
|
||||
|
||||
DECLARE vItemShelvingAvailable CURSOR FOR
|
||||
SELECT ish.id itemShelvingFk,
|
||||
|
@ -44,11 +45,11 @@ proc: BEGIN
|
|||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||
BEGIN
|
||||
ROLLBACK;
|
||||
CALL util.tx_rollback(vIsRequiredTx);
|
||||
RESIGNAL;
|
||||
END;
|
||||
|
||||
START TRANSACTION;
|
||||
CALL util.tx_start(vIsRequiredTx);
|
||||
|
||||
SELECT id INTO vSaleFk
|
||||
FROM sale
|
||||
|
@ -65,7 +66,7 @@ proc: BEGIN
|
|||
WHERE s.id = vSaleFk;
|
||||
|
||||
IF vOutStanding <= 0 THEN
|
||||
COMMIT;
|
||||
CALL util.tx_commit(vIsRequiredTx);
|
||||
LEAVE proc;
|
||||
END IF;
|
||||
|
||||
|
@ -93,7 +94,7 @@ proc: BEGIN
|
|||
LEAVE l;
|
||||
END IF;
|
||||
|
||||
SELECT id INTO vItemShelvingFk
|
||||
SELECT id INTO vItemShelvingFk
|
||||
FROM itemShelving
|
||||
WHERE id = vItemShelvingFk
|
||||
FOR UPDATE;
|
||||
|
@ -102,19 +103,19 @@ proc: BEGIN
|
|||
SET vOutStanding = vOutStanding - vReservedQuantity;
|
||||
|
||||
IF vReservedQuantity > 0 THEN
|
||||
CALL util.debugAdd('itemShelvingSale_addBySale_reservedQuantity',
|
||||
CONCAT(vSaleFk, ' - ', vReservedQuantity, ' - ', vOutStanding, account.myUser_getId()));
|
||||
INSERT INTO itemShelvingSale(
|
||||
itemShelvingFk,
|
||||
saleFk,
|
||||
quantity,
|
||||
userFk,
|
||||
isPicked)
|
||||
SELECT vItemShelvingFk,
|
||||
vSaleFk,
|
||||
vReservedQuantity,
|
||||
vUserFk,
|
||||
FALSE;
|
||||
CALL util.debugAdd('itemShelvingSale_addBySale_reservedQuantity',
|
||||
CONCAT(vSaleFk, ' - ', vReservedQuantity, ' - ', vOutStanding, account.myUser_getId()));
|
||||
INSERT INTO itemShelvingSale(
|
||||
itemShelvingFk,
|
||||
saleFk,
|
||||
quantity,
|
||||
userFk,
|
||||
isPicked)
|
||||
SELECT vItemShelvingFk,
|
||||
vSaleFk,
|
||||
vReservedQuantity,
|
||||
vUserFk,
|
||||
FALSE;
|
||||
|
||||
UPDATE itemShelving
|
||||
SET available = available - vReservedQuantity
|
||||
|
@ -123,6 +124,6 @@ proc: BEGIN
|
|||
END IF;
|
||||
END LOOP;
|
||||
CLOSE vItemShelvingAvailable;
|
||||
COMMIT;
|
||||
CALL util.tx_commit(vIsRequiredTx);
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -24,6 +24,7 @@ BEGIN
|
|||
|
||||
CALL cache.available_refresh(vAvailableCalcFk, FALSE, vWarehouseFk, vDated);
|
||||
CALL cache.visible_refresh(vVisibleCalcFk, FALSE, vWarehouseFk);
|
||||
CALL buy_getUltimate(NULL, vWarehouseFk, vDated);
|
||||
|
||||
WITH itemTags AS (
|
||||
SELECT i.id,
|
||||
|
@ -74,14 +75,13 @@ BEGIN
|
|||
AND a.calc_id = vAvailableCalcFk
|
||||
LEFT JOIN cache.visible v ON v.item_id = i.id
|
||||
AND v.calc_id = vVisibleCalcFk
|
||||
LEFT JOIN cache.last_buy lb ON lb.item_id = i.id
|
||||
AND lb.warehouse_id = vWarehouseFk
|
||||
LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = i.id
|
||||
LEFT JOIN vn.itemProposal ip ON ip.mateFk = i.id
|
||||
AND ip.itemFk = vSelf
|
||||
LEFT JOIN vn.itemTag it ON it.itemFk = i.id
|
||||
AND it.priority = vPriority
|
||||
LEFT JOIN vn.tag t ON t.id = it.tagFk
|
||||
LEFT JOIN vn.buy b ON b.id = lb.buy_id
|
||||
LEFT JOIN vn.buy b ON b.id = bu.buyFk
|
||||
JOIN itemTags its
|
||||
WHERE a.available > 0
|
||||
AND (i.typeFk = its.typeFk OR NOT vShowType)
|
||||
|
@ -98,5 +98,7 @@ BEGIN
|
|||
(i.tag8 = its.tag8) DESC,
|
||||
match8 DESC
|
||||
LIMIT 100;
|
||||
|
||||
DROP TEMPORARY TABLE tmp.buyUltimate;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`saleTracking_sectorCollectionAddPrevOK`(
|
||||
vSectorCollectionFk INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Inserta los registros de sectorCollection con el estado PREVIA OK si la reserva está picked
|
||||
*
|
||||
* @param vSectorCollectionFk Identificador de vn.sectorCollection
|
||||
*/
|
||||
REPLACE saleTracking(saleFk, isChecked, workerFk, stateFk)
|
||||
SELECT sgd.saleFk, TRUE, sc.userFk, s.id
|
||||
FROM sectorCollection sc
|
||||
JOIN sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id
|
||||
JOIN saleGroupDetail sgd ON sgd.saleGroupFk = scsg.saleGroupFk
|
||||
JOIN state s ON s.code = 'OK PREVIOUS'
|
||||
JOIN itemShelvingSale iss ON iss.saleFk = sgd.saleFk
|
||||
WHERE sc.id = vSectorCollectionFk AND iss.isPicked;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -51,7 +51,8 @@ BEGIN
|
|||
origin.companyFk futureCompanyFk,
|
||||
IFNULL(dest.nickname, origin.nickname) nickname,
|
||||
dest.landed,
|
||||
dest.preparation
|
||||
dest.preparation,
|
||||
origin.departmentFk
|
||||
FROM (
|
||||
SELECT s.ticketFk,
|
||||
c.salesPersonFk workerFk,
|
||||
|
@ -71,9 +72,11 @@ BEGIN
|
|||
t.addressFk,
|
||||
t.warehouseFk,
|
||||
t.companyFk,
|
||||
t.agencyModeFk
|
||||
t.agencyModeFk,
|
||||
wd.departmentFk
|
||||
FROM ticket t
|
||||
JOIN client c ON c.id = t.clientFk
|
||||
JOIN workerDepartment wd ON wd.workerFk = c.salesPersonFk
|
||||
JOIN sale s ON s.ticketFk = t.id
|
||||
JOIN saleVolume sv ON sv.saleFk = s.id
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
ALTER TABLE vn.docuwareConfig ADD IF NOT EXISTS username varchar(100) NULL;
|
||||
ALTER TABLE vn.docuwareConfig ADD IF NOT EXISTS password varchar(100) NULL;
|
||||
ALTER TABLE vn.docuwareConfig ADD IF NOT EXISTS token text NULL;
|
||||
ALTER TABLE vn.docuwareConfig ADD IF NOT EXISTS expired int(11) NULL;
|
|
@ -0,0 +1,137 @@
|
|||
CREATE TABLE IF NOT EXISTS `vn`.`itemFarmingTag` (
|
||||
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(50) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `name_UNIQUE` (`name`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT
|
||||
CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
|
||||
|
||||
INSERT IGNORE INTO `vn`.`itemFarmingTag` (`name`) VALUES ('Enraizado');
|
||||
|
||||
UPDATE vn.tag
|
||||
SET isFree=0,
|
||||
sourceTable='itemFarmingTag'
|
||||
WHERE name= 'cultivo';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `vn`.`itemWrappingTag` (
|
||||
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(50) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `name_UNIQUE` (`name`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT
|
||||
CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
|
||||
|
||||
INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Bolsa');
|
||||
INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Caja cartón');
|
||||
INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Caja decorativa');
|
||||
INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Celofán');
|
||||
INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Papel kraft');
|
||||
INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Plástico');
|
||||
INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Variable');
|
||||
|
||||
UPDATE vn.tag
|
||||
SET isFree=0,
|
||||
sourceTable='itemWrappingTag'
|
||||
WHERE name= 'Envoltorio';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `vn`.`itemLanguageTag` (
|
||||
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(50) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `name_UNIQUE` (`name`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT
|
||||
CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
|
||||
|
||||
INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Castellano');
|
||||
INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Catalán');
|
||||
INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Euskera');
|
||||
INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Francés');
|
||||
INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Gallego');
|
||||
INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Inglés');
|
||||
INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Portugués');
|
||||
|
||||
UPDATE vn.tag
|
||||
SET isFree=0,
|
||||
sourceTable='itemLanguageTag'
|
||||
WHERE name= 'Idioma';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `vn`.`itemStemTag` (
|
||||
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(50) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `name_UNIQUE` (`name`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT
|
||||
CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
|
||||
|
||||
INSERT IGNORE INTO `vn`.`itemStemTag` (`name`) VALUES ('Natural');
|
||||
INSERT IGNORE INTO `vn`.`itemStemTag` (`name`) VALUES ('Seminatural');
|
||||
INSERT IGNORE INTO `vn`.`itemStemTag` (`name`) VALUES ('Sintético');
|
||||
|
||||
UPDATE vn.tag
|
||||
SET isFree=0,
|
||||
sourceTable='itemStemTag'
|
||||
WHERE name= 'Tronco';
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `vn`.`itemBreederTag` (
|
||||
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(50) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `name_UNIQUE` (`name`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT
|
||||
CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
|
||||
|
||||
INSERT IGNORE INTO `vn`.`itemBreederTag` (`name`) VALUES ('David Austin');
|
||||
|
||||
UPDATE vn.tag
|
||||
SET isFree=0,
|
||||
sourceTable='itemBreederTag'
|
||||
WHERE name= 'Obtentor';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `vn`.`itemBaseTag` (
|
||||
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(50) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `name_UNIQUE` (`name`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT
|
||||
CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
|
||||
|
||||
INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Biodegradable');
|
||||
INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Caballete');
|
||||
INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Cerámica');
|
||||
INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Cristal');
|
||||
INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Plástico por inyección');
|
||||
INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Madera');
|
||||
INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Plástico');
|
||||
INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Rígido');
|
||||
INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Ruedas');
|
||||
INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Sin soporte rígido');
|
||||
|
||||
UPDATE vn.tag
|
||||
SET isFree=0,
|
||||
sourceTable='itemBaseTag'
|
||||
WHERE name= 'Soporte';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `vn`.`itemVatRateTag` (
|
||||
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(50) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `name_UNIQUE` (`name`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT
|
||||
CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
|
||||
|
||||
INSERT IGNORE INTO `vn`.`itemVatRateTag` (`name`) VALUES ('General');
|
||||
INSERT IGNORE INTO `vn`.`itemVatRateTag` (`name`) VALUES ('Reducido');
|
||||
|
||||
UPDATE vn.tag
|
||||
SET isFree=0,
|
||||
sourceTable='itemVatRateTag'
|
||||
WHERE name= 'Tipo de IVA';
|
||||
|
||||
GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemFarmingTag TO logisticAssist;
|
||||
GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemWrappingTag TO logisticAssist;
|
||||
GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemLanguageTag TO logisticAssist;
|
||||
GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemStemTag TO logisticAssist;
|
||||
GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemWrappingTag TO logisticAssist;
|
||||
GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemBaseTag TO logisticAssist;
|
||||
GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemBreederTag TO logisticAssist;
|
|
@ -0,0 +1,25 @@
|
|||
CREATE TABLE IF NOT EXISTS `vn`.`itemCampaign` (
|
||||
`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
dated date NOT NULL,
|
||||
itemFk int(11) NOT NULL,
|
||||
quantity decimal(10,2) NOT NULL,
|
||||
total decimal(10,2) NOT NULL,
|
||||
campaign varchar(100) NOT NULL,
|
||||
UNIQUE KEY `itemCampaign_UNIQUE` (`dated`,`itemFk`),
|
||||
CONSTRAINT itemCampaign_item_FK FOREIGN KEY (itemFk) REFERENCES vn.item(id) ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
)
|
||||
ENGINE=InnoDB
|
||||
DEFAULT CHARSET=utf8mb3
|
||||
COLLATE=utf8mb3_unicode_ci
|
||||
COMMENT='Tallos confirmados por día en los días de más producción de una campaña. La tabla está pensada para que sea una foto.';
|
||||
|
||||
ALTER TABLE vn.campaign
|
||||
ADD previousDays int(10) unsigned DEFAULT 30 NOT NULL COMMENT 'Días previos para calcular e insertar en la tabla itemCampaign';
|
||||
|
||||
UPDATE vn.campaign
|
||||
SET previousDays = 90
|
||||
WHERE code = 'allSaints';
|
||||
|
||||
UPDATE vn.campaign
|
||||
SET previousDays = 60
|
||||
WHERE code IN ('valentinesDay', 'mothersDay');
|
|
@ -29,7 +29,7 @@ module.exports = Self => {
|
|||
Object.assign(myOptions, options);
|
||||
|
||||
const stmt = new ParameterizedSQL(
|
||||
`SELECT es.created, u.name, u.id workerFk, est.description state
|
||||
`SELECT es.created, u.name, u.id workerFk, est.description state, es.isScanned
|
||||
FROM vn.expeditionState es
|
||||
JOIN vn.expeditionStateType est ON est.id = es.typeFk
|
||||
JOIN account.user u ON u.id = es.userFk
|
||||
|
|
|
@ -48,7 +48,7 @@ module.exports = Self => {
|
|||
CALL vn.sale_recalcComponent(null);
|
||||
DROP TEMPORARY TABLE tmp.recalculateSales;`;
|
||||
|
||||
const recalculation = await Self.rawSql(query, salesIds, myOptions);
|
||||
const recalculation = await Self.rawSql(query, [salesIds], myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
|
|
|
@ -85,6 +85,25 @@ describe('sale updatePrice()', () => {
|
|||
}
|
||||
});
|
||||
|
||||
it('should check if priceFixed has changed', async() => {
|
||||
const tx = await models.Sale.beginTransaction({});
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
const price = 3;
|
||||
const beforeUpdate = await models.Sale.findById(saleId, null, options);
|
||||
await models.Sale.updatePrice(ctx, saleId, price, options);
|
||||
const afterUpdate = await models.Sale.findById(saleId, null, options);
|
||||
|
||||
expect(beforeUpdate.priceFixed).not.toEqual(afterUpdate.priceFixed);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it('should set price as a decimal number and check the sale has the mana component changing the salesPersonMana', async() => {
|
||||
const tx = await models.Sale.beginTransaction({});
|
||||
|
||||
|
|
|
@ -91,7 +91,21 @@ module.exports = Self => {
|
|||
value: componentValue
|
||||
}, myOptions);
|
||||
}
|
||||
await sale.updateAttributes({price: newPrice}, myOptions);
|
||||
|
||||
const [priceFixed] = await Self.rawSql(`
|
||||
SELECT SUM(value) value
|
||||
FROM sale s
|
||||
JOIN saleComponent sc ON sc.saleFk = s.id
|
||||
JOIN component c ON c.id = sc.componentFk
|
||||
JOIN componentType ct ON ct.id = c.typeFk
|
||||
WHERE ct.isBase
|
||||
AND s.id = ?
|
||||
`, [id], myOptions);
|
||||
|
||||
await sale.updateAttributes({
|
||||
price: newPrice,
|
||||
priceFixed: priceFixed.value
|
||||
}, myOptions);
|
||||
|
||||
await Self.rawSql('CALL vn.manaSpellersRequery(?)', [userId], myOptions);
|
||||
await Self.rawSql('CALL vn.ticket_recalc(?, NULL)', [sale.ticketFk], myOptions);
|
||||
|
|
|
@ -50,6 +50,11 @@ module.exports = Self => {
|
|||
type: 'boolean',
|
||||
description: 'True when lines and stock of origin are equal'
|
||||
},
|
||||
{
|
||||
arg: 'departmentFk',
|
||||
type: 'number',
|
||||
description: 'Department identifier'
|
||||
},
|
||||
{
|
||||
arg: 'filter',
|
||||
type: 'object',
|
||||
|
@ -96,6 +101,8 @@ module.exports = Self => {
|
|||
};
|
||||
case 'isFullMovable':
|
||||
return {'f.isFullMovable': value};
|
||||
case 'departmentFk':
|
||||
return {'f.departmentFk': value};
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -6,6 +6,9 @@ describe('TicketFuture getTicketsAdvance()', () => {
|
|||
today.setHours(0, 0, 0, 0);
|
||||
let tomorrow = Date.vnNew();
|
||||
tomorrow.setDate(today.getDate() + 1);
|
||||
const salesDeptId = 43;
|
||||
const spain1DeptId = 95;
|
||||
beforeAll.mockLoopBackContext();
|
||||
|
||||
it('should return the tickets passing the required data', async() => {
|
||||
const tx = await models.Ticket.beginTransaction({});
|
||||
|
@ -129,4 +132,39 @@ describe('TicketFuture getTicketsAdvance()', () => {
|
|||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it('should return the tickets matching the right department', async() => {
|
||||
const tx = await models.Ticket.beginTransaction({});
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
ctx.args = {
|
||||
dateFuture: tomorrow,
|
||||
dateToAdvance: today,
|
||||
warehouseFk: 1,
|
||||
};
|
||||
|
||||
await models.Ticket.updateAll({id: {inq: [12, 31]}}, {clientFk: 1}, options);
|
||||
const client = await models.Client.findById(1, null, options);
|
||||
await client.updateAttribute('salesPersonFk', 1, options);
|
||||
const business = await models.Business.findById(1, null, options);
|
||||
await business.updateAttributes({departmentFk: spain1DeptId}, options);
|
||||
|
||||
const saleTickets = await models.Ticket.getTicketsAdvance(ctx, options);
|
||||
const filteredSaleTickets = await models.Ticket.getTicketsAdvance(
|
||||
{args: {...ctx.args, departmentFk: spain1DeptId}},
|
||||
options);
|
||||
|
||||
expect(saleTickets.length).toBeGreaterThan(filteredSaleTickets.length);
|
||||
expect(saleTickets.some(ticket => ticket.departmentFk === salesDeptId)).toBeTrue();
|
||||
expect(saleTickets.some(ticket => ticket.departmentFk === spain1DeptId)).toBeTrue();
|
||||
|
||||
expect(filteredSaleTickets.some(ticket => ticket.departmentFk === salesDeptId)).toBeFalse();
|
||||
expect(filteredSaleTickets.some(ticket => ticket.departmentFk === spain1DeptId)).toBeTrue();
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,63 +1,66 @@
|
|||
{
|
||||
"name": "Expedition",
|
||||
"base": "VnModel",
|
||||
"mixins": {
|
||||
"Loggable": true
|
||||
"name": "Expedition",
|
||||
"base": "VnModel",
|
||||
"mixins": {
|
||||
"Loggable": true
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "expedition"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"id": {
|
||||
"id": true,
|
||||
"type": "number",
|
||||
"description": "Identifier"
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "expedition"
|
||||
}
|
||||
"freightItemFk": {
|
||||
"type": "number"
|
||||
},
|
||||
"properties": {
|
||||
"id": {
|
||||
"id": true,
|
||||
"type": "number",
|
||||
"description": "Identifier"
|
||||
},
|
||||
"freightItemFk": {
|
||||
"type": "number"
|
||||
},
|
||||
"created": {
|
||||
"type": "date"
|
||||
},
|
||||
"counter": {
|
||||
"type": "number"
|
||||
},
|
||||
"externalId": {
|
||||
"type": "string"
|
||||
}
|
||||
"created": {
|
||||
"type": "date"
|
||||
},
|
||||
"relations": {
|
||||
"ticket": {
|
||||
"type": "belongsTo",
|
||||
"model": "Ticket",
|
||||
"foreignKey": "ticketFk"
|
||||
},
|
||||
"agencyMode": {
|
||||
"type": "belongsTo",
|
||||
"model": "AgencyMode",
|
||||
"foreignKey": "agencyModeFk"
|
||||
},
|
||||
"worker": {
|
||||
"type": "belongsTo",
|
||||
"model": "Worker",
|
||||
"foreignKey": "workerFk"
|
||||
},
|
||||
"packages": {
|
||||
"type": "hasMany",
|
||||
"model": "TicketPackaging",
|
||||
"foreignKey": "ticketFk"
|
||||
},
|
||||
"freightItem": {
|
||||
"type": "belongsTo",
|
||||
"model": "Item",
|
||||
"foreignKey": "freightItemFk"
|
||||
},
|
||||
"packaging": {
|
||||
"type": "belongsTo",
|
||||
"model": "Package",
|
||||
"foreignKey": "packagingFk"
|
||||
}
|
||||
"counter": {
|
||||
"type": "number"
|
||||
},
|
||||
"externalId": {
|
||||
"type": "string"
|
||||
},
|
||||
"stateTypeFk": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"relations": {
|
||||
"ticket": {
|
||||
"type": "belongsTo",
|
||||
"model": "Ticket",
|
||||
"foreignKey": "ticketFk"
|
||||
},
|
||||
"agencyMode": {
|
||||
"type": "belongsTo",
|
||||
"model": "AgencyMode",
|
||||
"foreignKey": "agencyModeFk"
|
||||
},
|
||||
"worker": {
|
||||
"type": "belongsTo",
|
||||
"model": "Worker",
|
||||
"foreignKey": "workerFk"
|
||||
},
|
||||
"packages": {
|
||||
"type": "hasMany",
|
||||
"model": "TicketPackaging",
|
||||
"foreignKey": "ticketFk"
|
||||
},
|
||||
"freightItem": {
|
||||
"type": "belongsTo",
|
||||
"model": "Item",
|
||||
"foreignKey": "freightItemFk"
|
||||
},
|
||||
"packaging": {
|
||||
"type": "belongsTo",
|
||||
"model": "Package",
|
||||
"foreignKey": "packagingFk"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -28,6 +28,9 @@
|
|||
"discount": {
|
||||
"type": "number"
|
||||
},
|
||||
"priceFixed": {
|
||||
"type": "number"
|
||||
},
|
||||
"reserved": {
|
||||
"type": "boolean"
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue