#6276 createNewWarehouse methods migrated from silex to salix #1850
|
@ -0,0 +1,60 @@
|
||||||
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
module.exports = Self => {
|
||||||
jorgep marked this conversation as resolved
Outdated
|
|||||||
|
Self.remoteMethodCtx('addItem', {
|
||||||
|
description: 'Add a collection',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'code',
|
||||||
|
type: 'string',
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'quantity',
|
||||||
|
type: 'number',
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'ticketFk',
|
||||||
|
type: 'number',
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'warehouseFk',
|
||||||
|
type: 'number',
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
],
|
||||||
|
http: {
|
||||||
|
path: `/addItem`,
|
||||||
|
verb: 'POST'
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.addItem = async(ctx, code, quantity, ticketFk, warehouseFk, options) => {
|
||||||
|
const models = Self.app.models;
|
||||||
|
const myOptions = {};
|
||||||
|
let tx;
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
if (!myOptions.transaction) {
|
||||||
|
tx = await Self.beginTransaction({});
|
||||||
|
myOptions.transaction = tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const [[item]] = await Self.rawSql('CALL vn.item_getInfo(?,?)', [code, warehouseFk]);
|
||||||
|
|
||||||
|
if (!item.available) throw new UserError('We do not have availability for the selected item');
|
||||||
|
|
||||||
jorgep marked this conversation as resolved
Outdated
alexm
commented
No hace falta usar $t, UserError traduce por defecto. No hace falta usar $t, UserError traduce por defecto.
jorgep
commented
Ahora el error se maneja desde Sale.js Ahora el error se maneja desde Sale.js
|
|||||||
|
await models.Ticket.addSale(ctx, ticketFk, item.id, quantity, myOptions);
|
||||||
|
|
||||||
|
if (tx) await tx.commit();
|
||||||
|
} catch (e) {
|
||||||
|
if (tx) await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
|
@ -5,4 +5,5 @@ module.exports = Self => {
|
||||||
require('../methods/collection/previousLabel')(Self);
|
require('../methods/collection/previousLabel')(Self);
|
||||||
require('../methods/collection/getTickets')(Self);
|
require('../methods/collection/getTickets')(Self);
|
||||||
require('../methods/collection/assignCollection')(Self);
|
require('../methods/collection/assignCollection')(Self);
|
||||||
|
require('../methods/collection/addItem')(Self);
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,4 +8,5 @@ INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalTyp
|
||||||
('SaleTracking','deleteTracking','WRITE','ALLOW','ROLE','employee'),
|
('SaleTracking','deleteTracking','WRITE','ALLOW','ROLE','employee'),
|
||||||
('SaleTracking','updateTracking','WRITE','ALLOW','ROLE','employee'),
|
('SaleTracking','updateTracking','WRITE','ALLOW','ROLE','employee'),
|
||||||
('SaleTracking','mark','WRITE','ALLOW','ROLE','employee'),
|
('SaleTracking','mark','WRITE','ALLOW','ROLE','employee'),
|
||||||
('ItemBarcode','deleteByItemAndCode','WRITE','ALLOW','ROLE','employee');
|
('ItemBarcode','deleteByItemAndCode','WRITE','ALLOW','ROLE','employee'),
|
||||||
|
('Collection','addItem','WRITE','ALLOW','ROLE','employee');
|
|
@ -71,7 +71,8 @@ module.exports = Self => {
|
||||||
}, ctx.options);
|
}, ctx.options);
|
||||||
if (item.family == 'EMB') return;
|
if (item.family == 'EMB') return;
|
||||||
|
|
||||||
if (await models.ACL.checkAccessAcl(ctx, 'Sale', 'isInPreparing', '*')) return;
|
const isInPreparing = await models.ACL.checkAccessAcl(ctx, 'Sale', 'isInPreparing', '*');
|
||||||
|
if (!ctx.isNEwInstance && isInPreparing) return;
|
||||||
jorgep marked this conversation as resolved
Outdated
alexm
commented
isNEwInstance o isNewInstance. isNEwInstance o isNewInstance.
Añadir test para este caso
|
|||||||
|
|
||||||
await models.Sale.rawSql(`CALL catalog_calcFromItem(?,?,?,?)`, [
|
await models.Sale.rawSql(`CALL catalog_calcFromItem(?,?,?,?)`, [
|
||||||
ticket.landed,
|
ticket.landed,
|
||||||
|
@ -89,7 +90,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
if (await models.ACL.checkAccessAcl(ctx, 'Ticket', 'isRoleAdvanced', '*')) return;
|
if (await models.ACL.checkAccessAcl(ctx, 'Ticket', 'isRoleAdvanced', '*')) return;
|
||||||
|
|
||||||
if (newQuantity < item.minQuantity && newQuantity != available)
|
if (newQuantity < item.minQuantity && newQuantity != available && !isInPreparing)
|
||||||
throw new UserError('The amount cannot be less than the minimum');
|
throw new UserError('The amount cannot be less than the minimum');
|
||||||
|
|
||||||
if (ctx.isNewInstance || isReduction) return;
|
if (ctx.isNewInstance || isReduction) return;
|
||||||
|
|
Loading…
Reference in New Issue
veo un enfoque extraño, se crea este método en collection, pero dentro no trata con colecciones, sino que añade a un ticket, porque no lo mueves a ticket o miras si en ticket ya existe uno que te sirva?
El propio modelo de sale (sale.js L87) ya hace la validación de disponible.
Valoraria que sergio usara directamente ticket/addSale