feat: refs #7704 Added itemMinimumQuantity_check
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
ce59a2bbbf
commit
ab45b988c8
|
@ -0,0 +1,28 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemMinimumQuantity_check`(
|
||||
vSelf INT,
|
||||
vItemFk INT,
|
||||
vStarted DATE,
|
||||
vEnded DATE,
|
||||
vWarehouseFk INT
|
||||
)
|
||||
BEGIN
|
||||
DECLARE vHasCollision BOOL;
|
||||
|
||||
IF vStarted IS NULL THEN
|
||||
CALL util.throw('The field "started" cannot be null');
|
||||
END IF;
|
||||
|
||||
SELECT COUNT(*) INTO vHasCollision
|
||||
FROM itemMinimumQuantity
|
||||
WHERE vItemFk = itemFk
|
||||
AND ((vStarted <= ended OR ended IS NULL)
|
||||
AND (vStarted >= `started` OR vEnded IS NULL))
|
||||
AND (vWarehouseFk <=> warehouseFk)
|
||||
AND vSelf <> id;
|
||||
|
||||
IF vHasCollision THEN
|
||||
CALL util.throw('A line with the same configuration already exists');
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -4,5 +4,6 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemMinimumQuantity_b
|
|||
FOR EACH ROW
|
||||
BEGIN
|
||||
SET NEW.editorFk = account.myUser_getId();
|
||||
CALL itemMinimumQuantity_check(NEW.id, NEW.itemFk, NEW.started, NEW.ended, NEW.warehouseFk);
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -4,5 +4,6 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemMinimumQuantity_b
|
|||
FOR EACH ROW
|
||||
BEGIN
|
||||
SET NEW.editorFk = account.myUser_getId();
|
||||
CALL itemMinimumQuantity_check(NEW.id, NEW.itemFk, NEW.started, NEW.ended, NEW.warehouseFk);
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -2,9 +2,10 @@ const {models} = require('vn-loopback/server/server');
|
|||
|
||||
describe('itemMinimumQuantity model', () => {
|
||||
const itemFk = 5;
|
||||
const quantity = 100;
|
||||
const warehouseFk = 60;
|
||||
|
||||
beforeAll(async() => {
|
||||
beforeEach(async() => {
|
||||
await models.ItemMinimumQuantity.destroyAll({where: {itemFk: itemFk}});
|
||||
});
|
||||
|
||||
|
@ -12,7 +13,7 @@ describe('itemMinimumQuantity model', () => {
|
|||
it('should create a new itemMinimumQuantity record', async() => {
|
||||
const newRecord = {
|
||||
itemFk: itemFk,
|
||||
quantity: 100,
|
||||
quantity: quantity,
|
||||
started: Date.vnNew(),
|
||||
ended: new Date(Date.vnNew().setFullYear(Date.vnNew().getFullYear() + 1)),
|
||||
warehouseFk: warehouseFk
|
||||
|
@ -27,7 +28,7 @@ describe('itemMinimumQuantity model', () => {
|
|||
it('should read an existing itemMinimumQuantity record', async() => {
|
||||
const newRecord = {
|
||||
itemFk: itemFk,
|
||||
quantity: 100,
|
||||
quantity: quantity,
|
||||
started: Date.vnNew(),
|
||||
ended: new Date(Date.vnNew().setFullYear(Date.vnNew().getFullYear() + 2)),
|
||||
warehouseFk: warehouseFk
|
||||
|
@ -44,7 +45,7 @@ describe('itemMinimumQuantity model', () => {
|
|||
it('should update an existing itemMinimumQuantity record', async() => {
|
||||
const newRecord = {
|
||||
itemFk: itemFk,
|
||||
quantity: 100,
|
||||
quantity: quantity,
|
||||
started: Date.vnNew(),
|
||||
ended: new Date(Date.vnNew().setFullYear(Date.vnNew().getFullYear() + 3)),
|
||||
warehouseFk: warehouseFk
|
||||
|
@ -67,7 +68,7 @@ describe('itemMinimumQuantity model', () => {
|
|||
it('should enforce unique constraint on itemFk, started, ended, and warehouseFk', async() => {
|
||||
const newRecord = {
|
||||
itemFk: itemFk,
|
||||
quantity: 100,
|
||||
quantity: quantity,
|
||||
started: Date.vnNew(),
|
||||
ended: Date.vnNew().setFullYear(Date.vnNew().getFullYear() + 5),
|
||||
warehouseFk: warehouseFk
|
||||
|
@ -78,14 +79,14 @@ describe('itemMinimumQuantity model', () => {
|
|||
await models.ItemMinimumQuantity.create(newRecord);
|
||||
} catch (e) {
|
||||
expect(e).toBeDefined();
|
||||
expect(e.code).toContain('ER_DUP_ENTRY');
|
||||
expect(e.code).toContain('ER_SIGNAL_EXCEPTION');
|
||||
}
|
||||
});
|
||||
|
||||
it('should allow null values for ended and warehouseFk', async() => {
|
||||
const newRecord = {
|
||||
itemFk: itemFk,
|
||||
quantity: 100,
|
||||
quantity: quantity,
|
||||
started: Date.vnNew(),
|
||||
ended: null,
|
||||
warehouseFk: null
|
||||
|
|
Loading…
Reference in New Issue