Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into dev
gitea/salix/dev This commit looks good Details

This commit is contained in:
Carlos Jimenez Ruiz 2019-09-25 11:53:42 +02:00
commit 1841e4edb0
11 changed files with 64 additions and 46 deletions

View File

@ -55,5 +55,6 @@
"This ticket can not be modified": "This ticket can not be modified", "This ticket can not be modified": "This ticket can not be modified",
"You can't delete a confirmed order": "You can't delete a confirmed order", "You can't delete a confirmed order": "You can't delete a confirmed order",
"Value has an invalid format": "Value has an invalid format", "Value has an invalid format": "Value has an invalid format",
"The postcode doesn't exists. Ensure you put the correct format": "The postcode doesn't exists. Ensure you put the correct format" "The postcode doesn't exists. Ensure you put the correct format": "The postcode doesn't exists. Ensure you put the correct format",
"Can't create stowaway for this ticket": "Can't create stowaway for this ticket"
} }

View File

@ -1,7 +1,7 @@
module.exports = Self => { module.exports = Self => {
Self.remoteMethod('canBeStowawayed', { Self.remoteMethod('canHaveStowaway', {
description: 'Returns if a ticket can be stowawayed', description: 'Returns if a ticket can have stowaway',
accessType: 'READ', accessType: 'READ',
accepts: [{ accepts: [{
arg: 'id', arg: 'id',
@ -14,14 +14,15 @@ module.exports = Self => {
root: true root: true
}, },
http: { http: {
path: `/:id/canBeStowawayed`, path: `/:id/canHaveStowaway`,
verb: 'GET' verb: 'GET'
} }
}); });
Self.canBeStowawayed = async id => { Self.canHaveStowaway = async id => {
const ticket = await Self.app.models.Ticket.findById(id); const models = Self.app.models;
const warehouse = await Self.app.models.Warehouse.findById(ticket.warehouseFk); const ticket = await models.Ticket.findById(id);
const warehouse = await models.Warehouse.findById(ticket.warehouseFk);
if (warehouse && warehouse.hasStowaway) if (warehouse && warehouse.hasStowaway)
return true; return true;

View File

@ -21,12 +21,13 @@ module.exports = Self => {
}); });
Self.getPossibleStowaways = async ticketFk => { Self.getPossibleStowaways = async ticketFk => {
let canStowaway = await Self.app.models.Ticket.canBeStowawayed(ticketFk); const models = Self.app.models;
const canHaveStowaway = await models.Ticket.canHaveStowaway(ticketFk);
if (!canStowaway) if (!canHaveStowaway)
throw new UserError(`Can't create stowaway for this ticket`); throw new UserError(`Can't create stowaway for this ticket`);
let ship = await Self.app.models.Ticket.findById(ticketFk); let ship = await models.Ticket.findById(ticketFk);
if (!ship || !ship.shipped) if (!ship || !ship.shipped)
return []; return [];
@ -38,7 +39,7 @@ module.exports = Self => {
highestDate.setHours(23, 59, 59); highestDate.setHours(23, 59, 59);
let possibleStowaways = await Self.app.models.Ticket.find({ let possibleStowaways = await models.Ticket.find({
where: { where: {
id: {neq: ticketFk}, id: {neq: ticketFk},
clientFk: ship.clientFk, clientFk: ship.clientFk,

View File

@ -1,16 +1,16 @@
const app = require('vn-loopback/server/server'); const app = require('vn-loopback/server/server');
describe('ticket canBeStowawayed()', () => { describe('ticket canHaveStowaway()', () => {
it('should return true if the ticket warehouse have hasStowaway equal 1', async() => { it('should return true if the ticket warehouse have hasStowaway equal 1', async() => {
const ticketId = 16; const ticketId = 16;
let canStowaway = await app.models.Ticket.canBeStowawayed(ticketId); let canStowaway = await app.models.Ticket.canHaveStowaway(ticketId);
expect(canStowaway).toBeTruthy(); expect(canStowaway).toBeTruthy();
}); });
it('should return false if the ticket warehouse dont have hasStowaway equal 0', async() => { it('should return false if the ticket warehouse dont have hasStowaway equal 0', async() => {
const ticketId = 10; const ticketId = 10;
let canStowaway = await app.models.Ticket.canBeStowawayed(ticketId); let canStowaway = await app.models.Ticket.canHaveStowaway(ticketId);
expect(canStowaway).toBeFalsy(); expect(canStowaway).toBeFalsy();
}); });

View File

@ -3,21 +3,22 @@ const UserError = require('vn-loopback/util/user-error');
module.exports = function(Self) { module.exports = function(Self) {
Self.observe('before save', async function(ctx) { Self.observe('before save', async function(ctx) {
let isStowaway = await Self.app.models.Ticket.canBeStowawayed(ctx.instance.id); const models = Self.app.models;
const canHaveStowaway = await models.Ticket.canHaveStowaway(ctx.instance.shipFk);
if (!isStowaway) if (!canHaveStowaway)
throw new UserError(`Can't create stowaway for this ticket`); throw new UserError(`Can't create stowaway for this ticket`);
if (ctx.isNewInstance) { if (ctx.isNewInstance) {
let where = { let where = {
code: 'BOARDING' code: 'BOARDING'
}; };
let state = await Self.app.models.State.findOne({where}); let state = await models.State.findOne({where});
let params = {ticketFk: ctx.instance.id, stateFk: state.id}; let params = {ticketFk: ctx.instance.id, stateFk: state.id};
const loopBackContext = LoopBackContext.getCurrentContext(); const loopBackContext = LoopBackContext.getCurrentContext();
let httpCtx = {req: loopBackContext.active}; let httpCtx = {req: loopBackContext.active};
await Self.app.models.TicketTracking.changeState(httpCtx, params); await models.TicketTracking.changeState(httpCtx, params);
} }
}); });
}; };

View File

@ -25,7 +25,7 @@ module.exports = Self => {
require('../methods/ticket/uploadFile')(Self); require('../methods/ticket/uploadFile')(Self);
require('../methods/ticket/addSale')(Self); require('../methods/ticket/addSale')(Self);
require('../methods/ticket/transferSales')(Self); require('../methods/ticket/transferSales')(Self);
require('../methods/ticket/canBeStowawayed')(Self); require('../methods/ticket/canHaveStowaway')(Self);
Self.observe('before save', async function(ctx) { Self.observe('before save', async function(ctx) {
if (ctx.isNewInstance) return; if (ctx.isNewInstance) return;

View File

@ -1,13 +1,18 @@
<vn-crud-model
url="/api/Tickets/{{$ctrl.$stateParams.id}}/getPossibleStowaways"
vn-id="model"
data="possibleStowaways">
</vn-crud-model>
<vn-dialog <vn-dialog
vn-id="dialog" vn-id="dialog"
class="modal-form" class="modal-form"
on-open="$ctrl.getPossibleStowaways()"> on-open="model.reload()">
<tpl-body> <tpl-body>
<vn-horizontal pad-medium class="header"> <vn-horizontal pad-medium class="header">
<h5><span translate>Stowaways to add</span></h5> <h5><span translate>Stowaways to add</span></h5>
</vn-horizontal> </vn-horizontal>
<vn-horizontal pad-medium> <vn-horizontal pad-medium>
<vn-table> <vn-table model="model">
<vn-thead> <vn-thead>
<vn-tr> <vn-tr>
<vn-th number>Ticket id</vn-th> <vn-th number>Ticket id</vn-th>
@ -18,7 +23,7 @@
</vn-tr> </vn-tr>
</vn-thead> </vn-thead>
<vn-tbody> <vn-tbody>
<vn-tr ng-repeat="ticket in $ctrl.possibleStowaways" class="clickable" ng-click="$ctrl.addStowaway($index)"> <vn-tr ng-repeat="ticket in possibleStowaways" class="clickable" ng-click="$ctrl.addStowaway(ticket)">
<vn-td number>{{ticket.id}}</vn-td> <vn-td number>{{ticket.id}}</vn-td>
<vn-td number>{{ticket.landed | dateTime: 'dd/MM/yyyy'}}</vn-td> <vn-td number>{{ticket.landed | dateTime: 'dd/MM/yyyy'}}</vn-td>
<vn-td number>{{ticket.agencyMode.name}}</vn-td> <vn-td number>{{ticket.agencyMode.name}}</vn-td>

View File

@ -1,23 +1,16 @@
import ngModule from '../module'; import ngModule from '../module';
class Controller { class Controller {
constructor($state, $, $http, vnApp, $translate) { constructor($stateParams, $, $http, vnApp, $translate) {
this.vnApp = vnApp; this.vnApp = vnApp;
this.$translate = $translate; this.$translate = $translate;
this.$ = $; this.$ = $;
this.$state = $state; this.$stateParams = $stateParams;
this.$http = $http; this.$http = $http;
} }
getPossibleStowaways() { addStowaway(stowaway) {
this.$http.get(`/api/Tickets/${this.ticket.id}/getPossibleStowaways`) let params = {id: stowaway.id, shipFk: this.ticket.id};
.then(res => {
this.possibleStowaways = res.data;
});
}
addStowaway(index) {
let params = {id: this.possibleStowaways[index].id, shipFk: this.ticket.id};
this.$http.post(`/api/Stowaways/`, params) this.$http.post(`/api/Stowaways/`, params)
.then(() => { .then(() => {
this.cardReload(); this.cardReload();
@ -35,7 +28,7 @@ class Controller {
} }
} }
Controller.$inject = ['$state', '$scope', '$http', 'vnApp', '$translate']; Controller.$inject = ['$stateParams', '$scope', '$http', 'vnApp', '$translate'];
ngModule.component('vnAddStowaway', { ngModule.component('vnAddStowaway', {
template: require('./addStowaway.html'), template: require('./addStowaway.html'),

View File

@ -158,7 +158,10 @@
question="You are going to delete this ticket" question="You are going to delete this ticket"
message="This ticket will be removed from current route! Continue anyway?"> message="This ticket will be removed from current route! Continue anyway?">
</vn-confirm> </vn-confirm>
<vn-add-stowaway vn-id="addStowaway" card-reload="$ctrl.cardReload()" ticket="$ctrl.ticket"></vn-add-stowaway> <vn-add-stowaway vn-id="addStowaway"
card-reload="$ctrl.cardReload()"
ticket="$ctrl.ticket">
</vn-add-stowaway>
<vn-remove-stowaway vn-id="removeStowaway" card-reload="$ctrl.cardReload()" ticket="$ctrl.ticket"></vn-remove-stowaway> <vn-remove-stowaway vn-id="removeStowaway" card-reload="$ctrl.cardReload()" ticket="$ctrl.ticket"></vn-remove-stowaway>
<vn-confirm <vn-confirm
vn-id="confirm-dialog" vn-id="confirm-dialog"

View File

@ -41,14 +41,6 @@ class Controller {
]; ];
} }
set canShowStowaway(value) {
this._canShowStowaway = value;
}
get canShowStowaway() {
return this._canShowStowaway;
}
showChangeShipped() { showChangeShipped() {
if (!this.isEditable) { if (!this.isEditable) {
this.vnApp.showError(this.$translate.instant('This ticket can\'t be modified')); this.vnApp.showError(this.$translate.instant('This ticket can\'t be modified'));
@ -81,7 +73,7 @@ class Controller {
canStowaway() { canStowaway() {
if (!this.isTicketModule()) return; if (!this.isTicketModule()) return;
this.$http.get(`/api/Tickets/${this.ticket.id}/canBeStowawayed`).then(response => { this.$http.get(`/api/Tickets/${this.ticket.id}/canHaveStowaway`).then(response => {
if (response.data === true) if (response.data === true)
return this.canShowStowaway = true; return this.canShowStowaway = true;

View File

@ -135,12 +135,33 @@ describe('Ticket Component vnTicketDescriptor', () => {
}); });
}); });
describe('showAddStowaway()', () => {
it('should show a dialog with a list of tickets available for an stowaway', () => {
controller.$scope.addStowaway = {};
controller.$scope.addStowaway.show = jasmine.createSpy('show');
controller.showAddStowaway();
expect(controller.$scope.addStowaway.show).toHaveBeenCalledWith();
});
});
describe('showRemoveStowaway()', () => {
it('should show a dialog for an stowaway removal', () => {
controller.$scope.removeStowaway = {};
controller.$scope.removeStowaway.show = jasmine.createSpy('show');
controller.showRemoveStowaway();
expect(controller.$scope.removeStowaway.show).toHaveBeenCalledWith();
});
});
describe('canStowaway()', () => { describe('canStowaway()', () => {
it('should make a query and return if the ticket can be stowawayed', () => { it('should make a query and return if the ticket can be stowawayed', () => {
controller.ticket.id = 16; controller.ticket.id = 16;
spyOn(controller, 'isTicketModule').and.callThrough(); spyOn(controller, 'isTicketModule').and.callThrough();
$httpBackend.when('GET', '/api/Tickets/16/canBeStowawayed').respond(true); $httpBackend.when('GET', '/api/Tickets/16/canHaveStowaway').respond(true);
$httpBackend.expect('GET', '/api/Tickets/16/canBeStowawayed').respond(true); $httpBackend.expect('GET', '/api/Tickets/16/canHaveStowaway').respond(true);
controller.canStowaway(); controller.canStowaway();
$httpBackend.flush(); $httpBackend.flush();