#9848 fix test and update fixtures

This commit is contained in:
Bernat 2019-02-13 13:19:15 +01:00
parent 8fa7abe191
commit bbd4188695
4 changed files with 206 additions and 98 deletions

View File

@ -3,16 +3,16 @@ const app = require('vn-loopback/server/server');
describe('order addToOrder()', () => { describe('order addToOrder()', () => {
let rowToDelete; let rowToDelete;
afterAll(async() => { afterAll(async() => {
await app.models.OrderRow.removes({rows: [rowToDelete], actualOrderId: 16}); await app.models.OrderRow.removes({rows: [rowToDelete], actualOrderId: 20});
}); });
it('should add a row to a given order', async() => { it('should add a row to a given order', async() => {
let unmodifiedRows = await app.models.OrderRow.find({where: {orderFk: 16}}); let unmodifiedRows = await app.models.OrderRow.find({where: {orderFk: 20}});
expect(unmodifiedRows.length).toBe(4); expect(unmodifiedRows.length).toBe(1);
let params = { let params = {
orderFk: 16, orderFk: 20,
items: [{ items: [{
itemFk: 1, itemFk: 1,
quantity: 1, quantity: 1,
@ -22,10 +22,10 @@ describe('order addToOrder()', () => {
await app.models.OrderRow.addToOrder(params); await app.models.OrderRow.addToOrder(params);
let modifiedRows = await app.models.OrderRow.find({where: {orderFk: 16}}); let modifiedRows = await app.models.OrderRow.find({where: {orderFk: 20}});
rowToDelete = modifiedRows[modifiedRows.length - 1].id; rowToDelete = modifiedRows[modifiedRows.length - 1].id;
expect(modifiedRows.length).toBe(5); expect(modifiedRows.length).toBe(2);
}); });
}); });

View File

@ -0,0 +1,108 @@
USE `hedera`;
DROP procedure IF EXISTS `orderAddItem`;
DELIMITER $$
USE `hedera`$$
CREATE DEFINER=`root`@`%` PROCEDURE `orderAddItem`(IN `vOrder` INT, IN `vWarehouse` INT, IN `vItem` INT, IN `vAmount` INT)
BEGIN
DECLARE vRow INT;
DECLARE vAdd INT;
DECLARE vAvailable INT;
DECLARE vDone BOOL;
DECLARE vGrouping INT;
DECLARE vRate INT;
DECLARE vShipment DATE;
DECLARE vPrice DECIMAL(10,2);
DECLARE vDate DATE;
DECLARE vAddress INT;
DECLARE vAgencyMode INT;
DECLARE cur CURSOR FOR
SELECT grouping, price, rate
FROM tmp.bionic_price
WHERE warehouse_id = vWarehouse
AND item_id = vItem
ORDER BY grouping DESC;
DECLARE CONTINUE HANDLER FOR NOT FOUND
SET vDone = TRUE;
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;
RESIGNAL;
END;
SELECT date_send, address_id, agency_id
INTO vDate, vAddress, vAgencyMode
FROM `order`
WHERE id = vOrder;
CALL vn2008.bionic_from_item(vDate, vAddress, vAgencyMode, vItem);
START TRANSACTION;
SELECT shipped INTO vShipment
FROM tmp.travel_tree
WHERE warehouseFk = vWarehouse;
SELECT available INTO vAvailable
FROM tmp.bionic_lot
WHERE warehouse_id = vWarehouse
AND item_id = vItem;
IF vAmount > IFNULL(vAvailable, 0)
THEN
CALL util.throw ('ORDER_ROW_UNAVAILABLE');
END IF;
OPEN cur;
l: LOOP
SET vDone = FALSE;
FETCH cur INTO vGrouping, vPrice, vRate;
IF vDone THEN
LEAVE l;
END IF;
SET vAdd = vAmount - MOD(vAmount, vGrouping);
SET vAmount = vAmount - vAdd;
IF vAdd = 0 THEN
ITERATE l;
END IF;
INSERT INTO order_row SET
order_id = vOrder,
item_id = vItem,
warehouse_id = vWarehouse,
shipment = vShipment,
rate = vRate,
amount = vAdd,
price = vPrice;
SET vRow = LAST_INSERT_ID();
INSERT INTO order_component (order_row_id, component_id, price)
SELECT vRow, c.component_id, c.cost
FROM tmp.bionic_component c
JOIN bi.tarifa_componentes t
ON t.Id_Componente = c.component_id
AND (t.tarifa_class IS NULL OR t.tarifa_class = vRate)
WHERE c.warehouse_id = vWarehouse
AND c.item_id = vItem;
END LOOP;
CLOSE cur;
IF vAmount > 0
THEN
CALL util.throw ('AMOUNT_NOT_MATCH_GROUPING');
END IF;
COMMIT;
CALL vn2008.bionic_free ();
END$$
DELIMITER ;

View File

@ -879,7 +879,7 @@ INSERT INTO `hedera`.`order`(`id`, `date_send`, `customer_id`, `delivery_method_
(17, CURDATE(), 106, 2, 4, 126, 442, NULL, 'SALIX', 0, CURDATE() , CURDATE() , CURDATE() ), (17, CURDATE(), 106, 2, 4, 126, 442, NULL, 'SALIX', 0, CURDATE() , CURDATE() , CURDATE() ),
(18, CURDATE(), 107, 3, 4, 127, 442, NULL, 'SALIX', 0, CURDATE() , CURDATE() , CURDATE() ), (18, CURDATE(), 107, 3, 4, 127, 442, NULL, 'SALIX', 0, CURDATE() , CURDATE() , CURDATE() ),
(19, CURDATE(), 108, 1, 5, 128, 442, NULL, 'SALIX', 0, CURDATE() , CURDATE() , CURDATE() ), (19, CURDATE(), 108, 1, 5, 128, 442, NULL, 'SALIX', 0, CURDATE() , CURDATE() , CURDATE() ),
(20, CURDATE() , 109, 2, 5, 119, 442, NULL, 'SALIX', 0, CURDATE() , CURDATE() , CURDATE() ), (20, CURDATE(), 109, 2, 1, 119, 442, NULL, 'SALIX', 0, CURDATE() , CURDATE() , CURDATE() ),
(21, CURDATE(), 110, 3, 5, 129, 442, NULL, 'SALIX', 0, CURDATE() , CURDATE() , CURDATE() ); (21, CURDATE(), 110, 3, 5, 129, 442, NULL, 'SALIX', 0, CURDATE() , CURDATE() , CURDATE() );
INSERT INTO `hedera`.`orderRow`(`id`, `orderFk`, `itemFk`, `warehouseFk`, `shipment`, `amount`, `price`, `rate`, `created`, `saleFk`) INSERT INTO `hedera`.`orderRow`(`id`, `orderFk`, `itemFk`, `warehouseFk`, `shipment`, `amount`, `price`, `rate`, `created`, `saleFk`)
@ -895,7 +895,8 @@ INSERT INTO `hedera`.`orderRow`(`id`, `orderFk`, `itemFk`, `warehouseFk`, `shipm
(9, 16, 1, 1, CURDATE(), 5, 9.10, 0, CURDATE(), 9), (9, 16, 1, 1, CURDATE(), 5, 9.10, 0, CURDATE(), 9),
(10, 16, 2, 1, CURDATE(), 10, 1.07, 0, CURDATE(), 10), (10, 16, 2, 1, CURDATE(), 10, 1.07, 0, CURDATE(), 10),
(11, 16, 1, 1, CURDATE(), 2, 9.10, 0, CURDATE(), 11), (11, 16, 1, 1, CURDATE(), 2, 9.10, 0, CURDATE(), 11),
( 12, 16, 4, 1, CURDATE(), 20, 3.06, 0, CURDATE(), 12); (12, 16, 4, 1, CURDATE(), 20, 3.06, 0, CURDATE(), 12),
(13, 20, 1, 1, CURDATE(), 2, 9.10, 0, CURDATE(), NULL);
INSERT INTO `hedera`.`orderRowComponent`(`rowFk`, `componentFk`, `price`) INSERT INTO `hedera`.`orderRowComponent`(`rowFk`, `componentFk`, `price`)
VALUES VALUES
@ -956,7 +957,12 @@ INSERT INTO `hedera`.`orderRowComponent`(`rowFk`, `componentFk`, `price`)
(12, 28, 20.72), (12, 28, 20.72),
(12, 29, -19.72), (12, 29, -19.72),
(12, 37, 2), (12, 37, 2),
( 12, 39, 0.01); (12, 39, 0.01),
(13, 15, 0.58),
(13, 23, 6.5),
(13, 28, 20.72),
(13, 29, -18.72),
(13, 39, 0.02);
INSERT INTO `vn`.`clientContact`(`id`, `clientFk`, `name`, `phone`) INSERT INTO `vn`.`clientContact`(`id`, `clientFk`, `name`, `phone`)
VALUES VALUES
@ -1042,13 +1048,7 @@ INSERT INTO `vn`.`orderTicket`(`orderFk`, `ticketFk`)
(12, 12), (12, 12),
(13, 13), (13, 13),
(14, 14), (14, 14),
(15, 15), (15, 15);
(16, 16),
(17, 17),
(18, 18),
(19, 19),
(20, 20),
(21, 21);
INSERT INTO `vn`.`userConfig` (`userFk`, `warehouseFk`, `companyFk`) INSERT INTO `vn`.`userConfig` (`userFk`, `warehouseFk`, `companyFk`)
VALUES VALUES