Merge branch '2195-setDeleted_itemShelving' of verdnatura/salix into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
commit
4691f5e916
|
@ -101,6 +101,16 @@ INSERT INTO `vn`.`sector`(`id`, `description`, `warehouseFk`, `isPreviousPrepare
|
|||
(1, 'First sector', 1, 1, 'FIRST', 999, 999),
|
||||
(2, 'Second sector', 2, 0, 'SECOND', 100, 150);
|
||||
|
||||
INSERT INTO `vn`.`parking` (`id`, `column`, `row`, `sectorFk`, `code`, `pickingOrder`)
|
||||
VALUES
|
||||
('1', '700', '01', '1', '700-01', '70001'),
|
||||
('2', '700', '02', '2', '700-02', '70002');
|
||||
|
||||
INSERT INTO `vn`.`shelving` (`code`, `parkingFk`, `isPrinted`, `priority`, `parked`, `userFk`)
|
||||
VALUES
|
||||
('GVC', '1', '0', '1', '0', '106'),
|
||||
('HEJ', '2', '0', '1', '0', '106');
|
||||
|
||||
INSERT INTO `vn`.`warehouseAlias`(`id`, `name`)
|
||||
VALUES
|
||||
(1, 'Main Warehouse');
|
||||
|
@ -928,6 +938,18 @@ INSERT INTO `vn`.`saleComponent`(`saleFk`, `componentFk`, `value`)
|
|||
(32, 36, -92.324),
|
||||
(32, 39, 0.994);
|
||||
|
||||
INSERT INTO `vn`.`itemShelving` (`id`, `itemFk`, `shelvingFk`, `shelve`, `deep`, `quantity`, `visible`, `available`, `grouping`, `packing`, `level`, `userFk`)
|
||||
VALUES
|
||||
('1', '2', 'GVC', 'A', '0', '1', '1', '1', '1', '1', '1', '106'),
|
||||
('2', '4', 'HEJ', 'A', '0', '2', '1', '1', '1', '1', '1', '106');
|
||||
|
||||
INSERT INTO `vn`.`itemShelvingSale` (`itemShelvingFk`, `saleFk`, `quantity`, `created`, `userFk`)
|
||||
VALUES
|
||||
('1', '1', '1', '', '106'),
|
||||
('2', '2', '5', '', '106'),
|
||||
('1', '7', '1', '', '106'),
|
||||
('2', '8', '5', '', '106');
|
||||
|
||||
INSERT INTO `vncontrol`.`accion`(`accion_id`, `accion`)
|
||||
VALUES
|
||||
(3, 'ACTION ONE'),
|
||||
|
|
|
@ -44,6 +44,9 @@
|
|||
"ItemTypeTag": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"ItemShelving": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"ItemShelvingSale": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
|
|
|
@ -25,6 +25,11 @@
|
|||
"model": "Sale",
|
||||
"foreignKey": "saleFk"
|
||||
},
|
||||
"itemShelving": {
|
||||
"type": "belongsTo",
|
||||
"model": "ItemShelving",
|
||||
"foreignKey": "itemShelvingFk"
|
||||
},
|
||||
"user": {
|
||||
"type": "belongsTo",
|
||||
"model": "Account",
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
{
|
||||
"name": "ItemShelving",
|
||||
"base": "VnModel",
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "itemShelving"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "number",
|
||||
"id": true,
|
||||
"description": "Identifier"
|
||||
},
|
||||
"shelve": {
|
||||
"type": "string"
|
||||
},
|
||||
"deep": {
|
||||
"type": "number"
|
||||
},
|
||||
"quantity": {
|
||||
"type": "number"
|
||||
},
|
||||
"created": {
|
||||
"type": "Date"
|
||||
}
|
||||
},
|
||||
"relations": {
|
||||
"item": {
|
||||
"type": "belongsTo",
|
||||
"model": "Item",
|
||||
"foreignKey": "itemFk"
|
||||
},
|
||||
"user": {
|
||||
"type": "belongsTo",
|
||||
"model": "Account",
|
||||
"foreignKey": "userFk"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -23,6 +23,7 @@ module.exports = Self => {
|
|||
|
||||
Self.setDeleted = async(ctx, id) => {
|
||||
const models = Self.app.models;
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const isEditable = await Self.isEditable(ctx, id);
|
||||
const $t = ctx.req.__; // $translate
|
||||
|
||||
|
@ -30,16 +31,30 @@ module.exports = Self => {
|
|||
throw new UserError(`The sales of this ticket can't be modified`);
|
||||
|
||||
// Check if has sales with shelving
|
||||
const isSalesAssistant = await models.Account.hasRole(userId, 'salesAssistant');
|
||||
const sales = await models.Sale.find({
|
||||
include: {relation: 'itemShelving'},
|
||||
include: {relation: 'itemShelvingSale'},
|
||||
where: {ticketFk: id}
|
||||
});
|
||||
const hasItemShelvingSales = sales.some(sale => {
|
||||
return sale.itemShelving();
|
||||
return sale.itemShelvingSale();
|
||||
});
|
||||
if (hasItemShelvingSales)
|
||||
|
||||
if (hasItemShelvingSales && !isSalesAssistant)
|
||||
throw new UserError(`You cannot delete a ticket that part of it is being prepared`);
|
||||
|
||||
if (hasItemShelvingSales && isSalesAssistant) {
|
||||
const promises = [];
|
||||
for (let sale of sales) {
|
||||
if (sale.itemShelvingSale()) {
|
||||
const itemShelvingSale = sale.itemShelvingSale();
|
||||
const destroyedShelving = models.ItemShelvingSale.destroyById(itemShelvingSale.id);
|
||||
promises.push(destroyedShelving);
|
||||
}
|
||||
}
|
||||
await Promise.all(promises);
|
||||
}
|
||||
|
||||
// Check for existing claim
|
||||
const claimOfATicket = await models.Claim.findOne({where: {ticketFk: id}});
|
||||
if (claimOfATicket)
|
||||
|
|
|
@ -1,29 +1,33 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
const models = app.models;
|
||||
|
||||
describe('ticket deleted()', () => {
|
||||
let ticket;
|
||||
let ctx;
|
||||
let sale;
|
||||
|
||||
beforeAll(async done => {
|
||||
let originalTicket = await app.models.Ticket.findOne({where: {id: 16}});
|
||||
let originalTicket = await models.Ticket.findOne({where: {id: 16}});
|
||||
originalTicket.id = null;
|
||||
ticket = await app.models.Ticket.create(originalTicket);
|
||||
ticket = await models.Ticket.create(originalTicket);
|
||||
sale = await models.Sale.create({
|
||||
ticketFk: ticket.id,
|
||||
itemFk: 4,
|
||||
concept: 'Melee weapon',
|
||||
quantity: 10
|
||||
});
|
||||
|
||||
ctx = {
|
||||
req: {
|
||||
accessToken: {userId: 106},
|
||||
headers: {
|
||||
origin: 'http://localhost:5000'
|
||||
},
|
||||
__: () => {}
|
||||
}
|
||||
};
|
||||
await models.ItemShelvingSale.create({
|
||||
itemShelvingFk: 1,
|
||||
saleFk: sale.id,
|
||||
quantity: 10,
|
||||
userFk: 106
|
||||
});
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
afterAll(async done => {
|
||||
await app.models.Ticket.destroyById(ticket.id);
|
||||
await models.Ticket.destroyById(ticket.id);
|
||||
|
||||
done();
|
||||
});
|
||||
|
@ -32,16 +36,62 @@ describe('ticket deleted()', () => {
|
|||
expect(ticket.isDeleted).toEqual(false);
|
||||
});
|
||||
|
||||
it('should set a ticket to deleted', async() => {
|
||||
it('should make sure the ticket sale has an item shelving', async() => {
|
||||
const sales = await models.Sale.find({
|
||||
include: {relation: 'itemShelvingSale'},
|
||||
where: {ticketFk: ticket.id}
|
||||
});
|
||||
const hasItemShelvingSales = sales.some(sale => {
|
||||
return sale.itemShelvingSale();
|
||||
});
|
||||
|
||||
expect(hasItemShelvingSales).toEqual(true);
|
||||
});
|
||||
|
||||
it('should set a ticket to deleted and remove all item shelvings', async() => {
|
||||
const salesAssistantId = 21;
|
||||
const ctx = {
|
||||
req: {
|
||||
accessToken: {userId: salesAssistantId},
|
||||
headers: {
|
||||
origin: 'http://localhost:5000'
|
||||
},
|
||||
__: () => {}
|
||||
}
|
||||
};
|
||||
await app.models.Ticket.setDeleted(ctx, ticket.id);
|
||||
|
||||
let deletedTicket = await app.models.Ticket.findOne({where: {id: ticket.id}, fields: ['isDeleted']});
|
||||
let deletedTicket = await app.models.Ticket.findOne({
|
||||
where: {id: ticket.id},
|
||||
fields: ['isDeleted']
|
||||
});
|
||||
|
||||
expect(deletedTicket.isDeleted).toEqual(true);
|
||||
});
|
||||
|
||||
it('should not have any item shelving', async() => {
|
||||
const sales = await models.Sale.find({
|
||||
include: {relation: 'itemShelvingSale'},
|
||||
where: {ticketFk: ticket.id}
|
||||
});
|
||||
const hasItemShelvingSales = sales.some(sale => {
|
||||
return sale.itemShelvingSale();
|
||||
});
|
||||
|
||||
expect(hasItemShelvingSales).toEqual(false);
|
||||
});
|
||||
|
||||
it('should throw an error if the given ticket has a claim', async() => {
|
||||
let ticketId = 16;
|
||||
const ticketId = 16;
|
||||
const ctx = {
|
||||
req: {
|
||||
accessToken: {userId: 106},
|
||||
headers: {
|
||||
origin: 'http://localhost:5000'
|
||||
},
|
||||
__: () => {}
|
||||
}
|
||||
};
|
||||
let error;
|
||||
|
||||
try {
|
||||
|
|
|
@ -73,7 +73,7 @@
|
|||
"model": "SaleTracking",
|
||||
"foreignKey": "saleFk"
|
||||
},
|
||||
"itemShelving": {
|
||||
"itemShelvingSale": {
|
||||
"type": "hasOne",
|
||||
"model": "ItemShelvingSale",
|
||||
"foreignKey": "saleFk"
|
||||
|
|
Loading…
Reference in New Issue