Merge pull request '4515-addBuyCheck' (!1974) from 4515-addBuyCheck into dev
gitea/salix/pipeline/head There was a failure building this commit Details

Reviewed-on: #1974
This commit is contained in:
Pablo Natek 2024-02-02 11:59:27 +00:00
commit 986d3532ed
6 changed files with 64 additions and 12 deletions

View File

@ -74,6 +74,8 @@ BEGIN
WHERE b.id = vSelf; WHERE b.id = vSelf;
END IF; END IF;
CREATE OR REPLACE TEMPORARY TABLE tmp.buysToCheck
SELECT vSelf id;
CALL buy_checkItem();
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -0,0 +1,28 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_checkItem`()
BEGIN
/**
* Checks if the item has weightByPiece or size null on any buy.
*
* @param tmp.buysToCheck(id as INT).
*/
DECLARE hasVolumetricAgency INT;
SELECT a.hasWeightVolumetric INTO hasVolumetricAgency
FROM entry e
JOIN travel t ON t.id = e.travelFk
JOIN agencyMode a ON a.id = t.agencyModeFk
JOIN buy b ON b.entryFk = e.id
JOIN item i ON i.id = b.itemFk
JOIN tmp.buysToCheck bt ON bt.id = b.id
WHERE (i.weightByPiece IS NULL OR i.`size` IS NULL)
AND a.hasWeightVolumetric
LIMIT 1;
DROP TEMPORARY TABLE IF EXISTS tmp.buysToCheck;
IF hasVolumetricAgency THEN
CALL util.throw('Some purchase line has an item without size or weight per stem in the volumetric agency.');
END IF;
END$$
DELIMITER ;

View File

@ -41,8 +41,8 @@ trig:BEGIN
FROM genericAllocation ga FROM genericAllocation ga
JOIN entry e ON e.id = NEW.entryFk JOIN entry e ON e.id = NEW.entryFk
JOIN travel tr on tr.id = e.travelFk JOIN travel tr on tr.id = e.travelFk
WHERE ga.itemFk = vGenericFk WHERE ga.itemFk = vGenericFk
AND tr.landed BETWEEN ga.startDated AND ga.endDated; AND tr.landed BETWEEN ga.startDated AND ga.endDated;
IF vGenericInDate THEN IF vGenericInDate THEN
SET NEW.itemOriginalFk = NEW.itemFk; SET NEW.itemOriginalFk = NEW.itemFk;
SET NEW.itemFk = vGenericFk; SET NEW.itemFk = vGenericFk;
@ -64,5 +64,12 @@ trig:BEGIN
IF NEW.quantity < 0 THEN IF NEW.quantity < 0 THEN
SET NEW.isIgnored = TRUE; SET NEW.isIgnored = TRUE;
END IF; END IF;
IF NOT (NEW.itemFk <=> OLD.itemFk) OR
NOT (OLD.entryFk <=> NEW.entryFk) THEN
CREATE OR REPLACE TEMPORARY TABLE tmp.buysToCheck
SELECT NEW.id;
CALL buy_checkItem();
END IF;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -13,5 +13,15 @@ BEGIN
CALL travel_requestRecalc(OLD.travelFk); CALL travel_requestRecalc(OLD.travelFk);
CALL travel_requestRecalc(NEW.travelFk); CALL travel_requestRecalc(NEW.travelFk);
END IF; END IF;
IF NOT (NEW.travelFk <=> OLD.travelFk) THEN
CREATE OR REPLACE TEMPORARY TABLE tmp.buysToCheck
SELECT b.id
FROM buy b
WHERE b.entryFk = NEW.id;
CALL buy_checkItem();
END IF;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -10,5 +10,18 @@ BEGIN
SET commission = entry_getCommission(travelFk, currencyFk,supplierFk) SET commission = entry_getCommission(travelFk, currencyFk,supplierFk)
WHERE travelFk = NEW.id; WHERE travelFk = NEW.id;
END IF; END IF;
IF NOT (NEW.agencyModeFk <=> OLD.agencyModeFk) THEN
IF (SELECT hasWeightVolumetric FROM agencyMode WHERE id = NEW.agencyModeFk) THEN
CREATE OR REPLACE TEMPORARY TABLE tmp.buysToCheck
SELECT b.id
FROM entry e
JOIN buy b ON b.entryFk = e.id
JOIN item i ON i.id = b.itemFk
WHERE e.travelFk = NEW.id;
CALL buy_checkItem();
END IF;
END IF;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -4,15 +4,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`travel_beforeUpdate`
FOR EACH ROW FOR EACH ROW
BEGIN BEGIN
SET NEW.editorFk = account.myUser_getId(); SET NEW.editorFk = account.myUser_getId();
/*
IF ((NOT NEW.shipped <=> OLD.shipped )
OR (NOT NEW.landed <=> OLD.landed )
OR (NOT NEW.warehouseInFk <=> OLD.warehouseInFk )
OR (NOT NEW.warehouseOutFk <=> OLD.warehouseOutFk ))
AND (OLD.totalEntries AND OLD.landed < CURDATE()) THEN
CALL util.throw("Cannot past travels with entries");
END IF;
*/
IF NOT (NEW.landed <=> OLD.landed) IF NOT (NEW.landed <=> OLD.landed)
OR NOT (NEW.shipped <=> OLD.shipped) THEN OR NOT (NEW.shipped <=> OLD.shipped) THEN
CALL travel_checkDates(NEW.shipped, NEW.landed); CALL travel_checkDates(NEW.shipped, NEW.landed);