drop procedure
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Alexandre Riera 2022-11-18 09:36:38 +01:00
parent 153cb48ff0
commit fd58eaf838
6 changed files with 2 additions and 152 deletions

View File

@ -0,0 +1 @@
DROP PROCEDURE IF EXISTS `vn`.`collection_missingTrash`;

View File

@ -1,27 +0,0 @@
DROP PROCEDURE IF EXISTS vn.sale_missingTrash;
DELIMITER $$
$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_missingTrash`(
vSaleFk BIGINT,
vQuantity INT,
vIsTrash BOOLEAN,
vWarehouseFk INT,
vNewQuantity INT)
/**
* Modifica la cantidad de una sale tirándola a faltas o basura
*
* @param vSaleFk el id de la sale
* @param vQuantity cantidad que se va a tirar a faltas o basura
* @param vIsTrash true si es basura, false si es faltas
* @param vWarehouseFk id warehouse
* @param vNewQuantity cantidad que se queda en el ticket original
*/
BEGIN
CALL vn.collection_missingTrash(vSaleFk ,vQuantity ,vIsTrash ,vWarehouseFk ,vNewQuantity);
END$$
DELIMITER ;
INSERT INTO `salix`.`ACL`
(model, property, accessType, permission, principalType, principalId)
VALUES('Sale', 'missingTrash', 'WRITE', 'ALLOW', 'ROLE', 'employee');

View File

@ -333,7 +333,7 @@ INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city
(1109, 'Bruce Banner', '16104829E', 'Hulk', 'Black widow', 'Somewhere in New York', 'Gotham', 46460, 1111111111, 222222222, 1, 'BruceBanner@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, 0, NULL, 0, 0, 9, 0, 1, 'florist'),
(1110, 'Jessica Jones', '58282869H', 'Jessica Jones', 'Luke Cage', 'NYCC 2015 Poster', 'Gotham', 46460, 1111111111, 222222222, 1, 'JessicaJones@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, 0, NULL, 0, 0, NULL, 0, 1, 'florist'),
(1111, 'Missing', NULL, 'Missing man', 'Anton', 'The space, Universe far away', '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', 4, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1, NULL),
(1112, 'Trash', '12345678Z', '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', 4, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1, NULL);
(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', 4, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1, NULL);
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'), 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

View File

@ -1,70 +0,0 @@
module.exports = Self => {
Self.remoteMethodCtx('missingTrash', {
description: 'Modify the amount of a sale by throwing it to faults or garbage',
accessType: 'WRITE',
accepts: [
{
arg: 'saleFk',
type: 'number',
required: true,
description: 'The sale id'
},
{
arg: 'quantity',
type: 'number',
required: true,
description: 'Quantity that is going to be thrown away'
},
{
arg: 'isTrash',
type: 'boolean',
required: true,
description: 'True if garbage, false if fault'
},
{
arg: 'warehouseFk',
type: 'number',
required: true,
description: 'The warehouse id'
},
{
arg: 'newQuantity',
type: 'number',
required: true,
description: 'Amount remaining on the original ticket'
},
],
returns: {
type: ['object'],
root: true
},
http: {
path: `/missingTrash`,
verb: 'POST'
}
});
Self.missingTrash = async function(ctx, saleFk, quantity, isTrash, warehouseFk, newQuantity, options) {
const myOptions = {};
let tx;
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
const missingTrash = await Self.rawSql(`CALL vn.sale_missingTrash(?, ?, ?, ?, ?)`,
[saleFk, quantity, isTrash, warehouseFk, newQuantity], myOptions);
if (tx) await tx.commit();
return missingTrash;
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};

View File

@ -1,53 +0,0 @@
const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
describe('sale missingTrash()', () => {
const activeCtx = {
accessToken: {userId: 9},
headers: {origin: 'localhost:5000'},
__: () => {}
};
const ctx = {
req: activeCtx
};
beforeEach(() => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
});
it('should modify the amount of a sale by throwing it to faults or garbage', async() => {
const tx = await models.Sale.beginTransaction({});
try {
const options = {transaction: tx};
const quantity = 1;
const isTrash = true;
const trashClient = await models.Client.findOne({where: {name: 'Trash'}}, options);
await trashClient.updateAttribute('name', 'BASURA', options);
const sale = await models.Sale.findOne({fields: ['id', 'quantity', 'originalQuantity', 'ticketFk']}
, options);
const ticket = await models.Ticket.findById(sale.ticketFk, {fields: ['warehouseFk']}, options);
const newQuantity = sale.quantity - quantity;
await models.Sale.missingTrash(ctx, sale.id, quantity, isTrash, ticket.warehouseFk, newQuantity, options);
const saleAfter = await models.Sale.findById(sale.id, {fields: ['quantity', 'originalQuantity']}, options);
expect(saleAfter.quantity).toEqual(newQuantity);
expect(saleAfter.originalQuantity).toBe(sale.quantity);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});

View File

@ -9,7 +9,6 @@ module.exports = Self => {
require('../methods/sale/refund')(Self);
require('../methods/sale/canEdit')(Self);
require('../methods/sale/usesMana')(Self);
require('../methods/sale/missingTrash')(Self);
Self.validatesPresenceOf('concept', {
message: `Concept cannot be blank`