Merge branch 'test' of https://gitea.verdnatura.es/verdnatura/salix into dev
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2024-10-22 15:08:29 +02:00
commit b4e1b015de
6 changed files with 88 additions and 39 deletions

View File

@ -404,7 +404,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, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 0, 1, 0, NULL, 1, 0, NULL, 0, 'others','loses'); (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, 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`, `quality`, `payMethodFk`,`created`, `isTaxDataChecked`) INSERT INTO `vn`.`client`(`id`, `name`, `fi`, `socialName`, `contact`, `street`, `city`, `postcode`, `isRelevant`, `email`, `iban`,`dueDay`,`accountingAccount`, `isEqualizated`, `provinceFk`, `hasToInvoice`, `credit`, `countryFk`, `isActive`, `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, 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, 10, 5, util.VN_CURDATE(), 1
FROM `account`.`role` `r` FROM `account`.`role` `r`
WHERE `r`.`hasLogin` = 1; WHERE `r`.`hasLogin` = 1;
@ -3951,9 +3951,9 @@ INSERT INTO vn.medicalReview
(id, workerFk, centerFk, `date`, `time`, isFit, amount, invoice, remark) (id, workerFk, centerFk, `date`, `time`, isFit, amount, invoice, remark)
VALUES(3, 9, 2, '2000-01-01', '8:00', 1, 150.0, NULL, NULL); VALUES(3, 9, 2, '2000-01-01', '8:00', 1, 150.0, NULL, NULL);
INSERT INTO vn.stockBought (workerFk, bought, reserve, dated) INSERT INTO vn.stockBought (workerFk, bought, reserve, dated)
VALUES(35, 1.00, 1.00, '2001-01-01'); VALUES(35, 1.00, 1.00, '2001-01-01');
INSERT INTO vn.auctionConfig (id,conversionCoefficient,warehouseFk) INSERT INTO vn.auctionConfig (id,conversionCoefficient,warehouseFk)
VALUES (1,0.6,6); VALUES (1,0.6,6);
INSERT INTO vn.payrollComponent INSERT INTO vn.payrollComponent

View File

@ -37,23 +37,23 @@ BEGIN
WHERE t.id = vTicketFk; WHERE t.id = vTicketFk;
CALL cache.available_refresh( CALL cache.available_refresh(
vCacheAvailableFk, vCacheAvailableFk,
FALSE, FALSE,
vWarehouseFk, vWarehouseFk,
util.VN_CURDATE()); util.VN_CURDATE());
SELECT available INTO vAvailable SELECT available INTO vAvailable
FROM cache.available FROM cache.available
WHERE calc_id = vCacheAvailableFk WHERE calc_id = vCacheAvailableFk
AND item_id = vItemFk; AND item_id = vItemFk;
IF vAvailable < vQuantity THEN IF vAvailable < vQuantity THEN
SET vHasThrow = TRUE; SET vHasThrow = TRUE;
ELSE ELSE
SELECT `name`, SELECT `name`,
CONCAT(getUser(), ' ', DATE_FORMAT(util.VN_NOW(), '%H:%i'), ' ', name) CONCAT(getUser(), ' ', DATE_FORMAT(util.VN_NOW(), '%H:%i'), ' ', name)
INTO vItemName, vConcept INTO vItemName, vConcept
FROM item FROM item
WHERE id = vItemFk; WHERE id = vItemFk;
START TRANSACTION; START TRANSACTION;
@ -69,7 +69,7 @@ BEGIN
CALL sale_calculateComponent(vSaleFk, NULL); CALL sale_calculateComponent(vSaleFk, NULL);
CALL itemShelvingSale_addBySale(vSaleFk, vSectorFk); CALL itemShelvingSale_addBySale(vSaleFk, vSectorFk);
IF NOT EXISTS (SELECT TRUE FROM itemShelvingSale WHERE saleFk = vSaleFk LIMIT 1) THEN IF NOT EXISTS (SELECT TRUE FROM itemShelvingSale WHERE saleFk = vSaleFk LIMIT 1) THEN
SET vHasThrow = TRUE; SET vHasThrow = TRUE;
END IF; END IF;
@ -78,13 +78,13 @@ BEGIN
IF vHasThrow THEN IF vHasThrow THEN
CALL util.throw("There is no available for the selected item"); CALL util.throw("There is no available for the selected item");
END IF; END IF;
IF vSaleGroupFk THEN IF vSaleGroupFk THEN
INSERT INTO saleGroupDetail INSERT INTO saleGroupDetail
SET saleFk = vSaleFk, SET saleFk = vSaleFk,
saleGroupFk = vSaleGroupFk; saleGroupFk = vSaleGroupFk;
END IF; END IF;
COMMIT; COMMIT;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -18,8 +18,9 @@ proc: BEGIN
DECLARE vReservedQuantity INT; DECLARE vReservedQuantity INT;
DECLARE vOutStanding INT; DECLARE vOutStanding INT;
DECLARE vUserFk INT; DECLARE vUserFk INT;
DECLARE vTotalReservedQuantity INT; DECLARE vTotalReservedQuantity INT;
DECLARE vSaleQuantity INT; DECLARE vSaleQuantity INT;
DECLARE vIsRequiredTx BOOL DEFAULT NOT @@in_transaction;
DECLARE vItemShelvingAvailable CURSOR FOR DECLARE vItemShelvingAvailable CURSOR FOR
SELECT ish.id itemShelvingFk, SELECT ish.id itemShelvingFk,
@ -29,7 +30,7 @@ proc: BEGIN
JOIN shelving sh ON sh.code = ish.shelvingFk JOIN shelving sh ON sh.code = ish.shelvingFk
JOIN parking p ON p.id = sh.parkingFk JOIN parking p ON p.id = sh.parkingFk
JOIN sector sc ON sc.id = p.sectorFk JOIN sector sc ON sc.id = p.sectorFk
JOIN productionConfig pc JOIN productionConfig pc
WHERE s.id = vSaleFk WHERE s.id = vSaleFk
AND NOT sc.isHideForPickers AND NOT sc.isHideForPickers
AND (sc.id = vSectorFk OR vSectorFk IS NULL) AND (sc.id = vSectorFk OR vSectorFk IS NULL)
@ -44,15 +45,15 @@ proc: BEGIN
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
DECLARE EXIT HANDLER FOR SQLEXCEPTION DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN BEGIN
ROLLBACK; CALL util.tx_rollback(vIsRequiredTx);
RESIGNAL; RESIGNAL;
END; END;
START TRANSACTION; CALL util.tx_start(vIsRequiredTx);
SELECT id INTO vSaleFk SELECT id INTO vSaleFk
FROM sale FROM sale
WHERE id = vSaleFk WHERE id = vSaleFk
FOR UPDATE; FOR UPDATE;
SELECT MAX(p.pickingOrder), s.quantity - SUM(IFNULL(iss.quantity, 0)), s.quantity SELECT MAX(p.pickingOrder), s.quantity - SUM(IFNULL(iss.quantity, 0)), s.quantity
@ -65,7 +66,7 @@ proc: BEGIN
WHERE s.id = vSaleFk; WHERE s.id = vSaleFk;
IF vOutStanding <= 0 THEN IF vOutStanding <= 0 THEN
COMMIT; CALL util.tx_commit(vIsRequiredTx);
LEAVE proc; LEAVE proc;
END IF; END IF;
@ -85,7 +86,7 @@ proc: BEGIN
IF vTotalReservedQuantity <> vSaleQuantity THEN IF vTotalReservedQuantity <> vSaleQuantity THEN
CALL util.debugAdd('itemShelvingSale_addBySale', CALL util.debugAdd('itemShelvingSale_addBySale',
CONCAT(vSaleFk, ' - ', vSaleQuantity,' - ', vTotalReservedQuantity,'-', vOutStanding,'-', account.myUser_getId())); CONCAT(vSaleFk, ' - ', vSaleQuantity,' - ', vTotalReservedQuantity,'-', vOutStanding,'-', account.myUser_getId()));
UPDATE sale UPDATE sale
SET quantity = vTotalReservedQuantity SET quantity = vTotalReservedQuantity
WHERE id = vSaleFk; WHERE id = vSaleFk;
@ -93,7 +94,7 @@ proc: BEGIN
LEAVE l; LEAVE l;
END IF; END IF;
SELECT id INTO vItemShelvingFk SELECT id INTO vItemShelvingFk
FROM itemShelving FROM itemShelving
WHERE id = vItemShelvingFk WHERE id = vItemShelvingFk
FOR UPDATE; FOR UPDATE;
@ -102,19 +103,19 @@ proc: BEGIN
SET vOutStanding = vOutStanding - vReservedQuantity; SET vOutStanding = vOutStanding - vReservedQuantity;
IF vReservedQuantity > 0 THEN IF vReservedQuantity > 0 THEN
CALL util.debugAdd('itemShelvingSale_addBySale_reservedQuantity', CALL util.debugAdd('itemShelvingSale_addBySale_reservedQuantity',
CONCAT(vSaleFk, ' - ', vReservedQuantity, ' - ', vOutStanding, account.myUser_getId())); CONCAT(vSaleFk, ' - ', vReservedQuantity, ' - ', vOutStanding, account.myUser_getId()));
INSERT INTO itemShelvingSale( INSERT INTO itemShelvingSale(
itemShelvingFk, itemShelvingFk,
saleFk, saleFk,
quantity, quantity,
userFk, userFk,
isPicked) isPicked)
SELECT vItemShelvingFk, SELECT vItemShelvingFk,
vSaleFk, vSaleFk,
vReservedQuantity, vReservedQuantity,
vUserFk, vUserFk,
FALSE; FALSE;
UPDATE itemShelving UPDATE itemShelving
SET available = available - vReservedQuantity SET available = available - vReservedQuantity
@ -123,6 +124,6 @@ proc: BEGIN
END IF; END IF;
END LOOP; END LOOP;
CLOSE vItemShelvingAvailable; CLOSE vItemShelvingAvailable;
COMMIT; CALL util.tx_commit(vIsRequiredTx);
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -51,7 +51,8 @@ BEGIN
origin.companyFk futureCompanyFk, origin.companyFk futureCompanyFk,
IFNULL(dest.nickname, origin.nickname) nickname, IFNULL(dest.nickname, origin.nickname) nickname,
dest.landed, dest.landed,
dest.preparation dest.preparation,
origin.departmentFk
FROM ( FROM (
SELECT s.ticketFk, SELECT s.ticketFk,
c.salesPersonFk workerFk, c.salesPersonFk workerFk,
@ -71,9 +72,11 @@ BEGIN
t.addressFk, t.addressFk,
t.warehouseFk, t.warehouseFk,
t.companyFk, t.companyFk,
t.agencyModeFk t.agencyModeFk,
wd.departmentFk
FROM ticket t FROM ticket t
JOIN client c ON c.id = t.clientFk 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 sale s ON s.ticketFk = t.id
JOIN saleVolume sv ON sv.saleFk = s.id JOIN saleVolume sv ON sv.saleFk = s.id
JOIN item i ON i.id = s.itemFk JOIN item i ON i.id = s.itemFk

View File

@ -50,6 +50,11 @@ module.exports = Self => {
type: 'boolean', type: 'boolean',
description: 'True when lines and stock of origin are equal' description: 'True when lines and stock of origin are equal'
}, },
{
arg: 'departmentFk',
type: 'number',
description: 'Department identifier'
},
{ {
arg: 'filter', arg: 'filter',
type: 'object', type: 'object',
@ -96,6 +101,8 @@ module.exports = Self => {
}; };
case 'isFullMovable': case 'isFullMovable':
return {'f.isFullMovable': value}; return {'f.isFullMovable': value};
case 'departmentFk':
return {'f.departmentFk': value};
} }
}); });

View File

@ -6,6 +6,9 @@ describe('TicketFuture getTicketsAdvance()', () => {
today.setHours(0, 0, 0, 0); today.setHours(0, 0, 0, 0);
let tomorrow = Date.vnNew(); let tomorrow = Date.vnNew();
tomorrow.setDate(today.getDate() + 1); tomorrow.setDate(today.getDate() + 1);
const salesDeptId = 43;
const spain1DeptId = 95;
beforeAll.mockLoopBackContext();
it('should return the tickets passing the required data', async() => { it('should return the tickets passing the required data', async() => {
const tx = await models.Ticket.beginTransaction({}); const tx = await models.Ticket.beginTransaction({});
@ -129,4 +132,39 @@ describe('TicketFuture getTicketsAdvance()', () => {
throw e; 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;
}
});
}); });