refs #3557 back and test done
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Alexandre Riera 2022-11-15 09:30:36 +01:00
parent 04eefc7dbe
commit 5acbaf036a
4 changed files with 129 additions and 0 deletions

View File

@ -0,0 +1,23 @@
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 ;

View File

@ -0,0 +1,70 @@
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

@ -0,0 +1,35 @@
const models = require('vn-loopback/server/server').models;
fdescribe('sale missingTrash()', () => {
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 saleFk = 1;
const quantity = 3;
const isTrash = true;
const warehouseFk = 1;
const newQuantity = 2;
const ctx = { req: { accessToken: { userId: 9 } } };
let sale = await models.Sale.findById(saleFk, null, options);
expect(sale.quantity).toEqual(5);
expect(sale.originalQuantity).toBe(null);
await models.Sale.missingTrash(ctx, saleFk, quantity, isTrash, warehouseFk, newQuantity, options);
sale = await models.Sale.findById(saleFk, null, options);
expect(sale.quantity).toEqual(2);
expect(sale.originalQuantity).toBe(5);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});

View File

@ -9,6 +9,7 @@ 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`