Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 4832-refactor_workerTimeControl.sendMail
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Vicent Llopis 2022-11-17 07:22:26 +01:00
commit 161886c936
17 changed files with 294 additions and 15 deletions

View File

@ -1,7 +1,7 @@
import selectors from '../../helpers/selectors.js';
import getBrowser from '../../helpers/puppeteer';
fdescribe('Ticket expeditions and log path', () => {
describe('Ticket expeditions and log path', () => {
let browser;
let page;

View File

@ -104,7 +104,6 @@ describe('Ticket Edit basic data path', () => {
await page.waitToClick(selectors.ticketBasicData.nextStepButton);
await page.waitToClick(selectors.ticketBasicData.withoutNegatives);
await page.waitToClick(selectors.ticketBasicData.finalizeButton);
await page.waitForState('ticket.card.summary');

View File

@ -49,6 +49,10 @@ module.exports = Self => {
const provisionalName = params.provisionalName;
delete params.provisionalName;
const itemType = await models.ItemType.findById(params.typeFk, myOptions);
params.isLaid = itemType.isLaid;
const item = await models.Item.create(params, myOptions);
const typeTags = await models.ItemTypeTag.find({

View File

@ -15,6 +15,11 @@ describe('item new()', () => {
};
let item = await models.Item.new(itemParams, options);
let itemType = await models.ItemType.findById(item.typeFk, options);
item.isLaid = itemType.isLaid;
const temporalNameTag = await models.Tag.findOne({where: {name: 'Nombre temporal'}}, options);
const temporalName = await models.ItemTag.findOne({
@ -26,9 +31,14 @@ describe('item new()', () => {
item = await models.Item.findById(item.id, null, options);
itemType = await models.ItemType.findById(item.typeFk, options);
item.isLaid = itemType.isLaid;
expect(item.intrastatFk).toEqual(5080000);
expect(item.originFk).toEqual(1);
expect(item.typeFk).toEqual(2);
expect(item.isLaid).toBeFalse();
expect(item.name).toEqual('planta');
expect(temporalName.value).toEqual('planta');

View File

@ -26,6 +26,9 @@
},
"isUnconventionalSize": {
"type": "number"
},
"isLaid": {
"type": "boolean"
}
},
"relations": {

View File

@ -143,6 +143,9 @@
},
"packingShelve": {
"type": "number"
},
"isLaid": {
"type": "boolean"
}
},
"relations": {

View File

@ -0,0 +1,39 @@
module.exports = Self => {
Self.remoteMethodCtx('sendSms', {
description: 'Sends a SMS to each client of the routes, each client only recieves the SMS once',
accessType: 'WRITE',
accepts: [
{
arg: 'destination',
type: 'string',
description: 'A comma separated string of destinations',
required: true,
},
{
arg: 'message',
type: 'string',
required: true,
}],
returns: {
type: 'object',
root: true
},
http: {
path: `/sendSms`,
verb: 'POST'
}
});
Self.sendSms = async(ctx, destination, message) => {
const targetClients = destination.split(',');
const allSms = [];
for (let client of targetClients) {
let sms = await Self.app.models.Sms.send(ctx, client, message);
allSms.push(sms);
}
return allSms;
};
};

View File

@ -12,6 +12,7 @@ module.exports = Self => {
require('../methods/route/updateWorkCenter')(Self);
require('../methods/route/driverRoutePdf')(Self);
require('../methods/route/driverRouteEmail')(Self);
require('../methods/route/sendSms')(Self);
Self.validate('kmStart', validateDistance, {
message: 'Distance must be lesser than 1000'

View File

@ -15,3 +15,4 @@ import './agency-term/index';
import './agency-term/createInvoiceIn';
import './agency-term-search-panel';
import './ticket-popup';
import './sms';

View File

@ -8,4 +8,6 @@ Hour finished: Hora fin
Go to route: Ir a la ruta
You must select a valid time: Debe seleccionar una hora válida
You must select a valid date: Debe seleccionar una fecha válida
Mark as served: Marcar como servidas
Mark as served: Marcar como servidas
Retrieving data from the routes: Recuperando datos de las rutas
Send SMS to all clients: Mandar sms a todos los clientes de las rutas

View File

@ -0,0 +1,36 @@
<vn-dialog
vn-id="SMSDialog"
on-accept="$ctrl.onResponse()"
message="Send SMS to the selected tickets">
<tpl-body>
<section class="SMSDialog">
<vn-horizontal>
<vn-textarea vn-one
vn-id="message"
label="Message"
ng-model="$ctrl.sms.message"
info="Special characters like accents counts as a multiple"
rows="5"
required="true"
rule>
</vn-textarea>
</vn-horizontal>
<vn-horizontal>
<span>
{{'Characters remaining' | translate}}:
<vn-chip translate-attr="{title: 'Packing'}" ng-class="{
'colored': $ctrl.charactersRemaining() > 25,
'warning': $ctrl.charactersRemaining() <= 25,
'alert': $ctrl.charactersRemaining() < 0,
}">
{{$ctrl.charactersRemaining()}}
</vn-chip>
</span>
</vn-horizontal>
</section>
</tpl-body>
<tpl-buttons>
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
<button response="accept" translate>Send</button>
</tpl-buttons>
</vn-dialog>

View File

@ -0,0 +1,47 @@
import ngModule from '../module';
import Component from 'core/lib/component';
import './style.scss';
class Controller extends Component {
open() {
this.$.SMSDialog.show();
}
charactersRemaining() {
const element = this.$.message;
const value = element.input.value;
const maxLength = 160;
const textAreaLength = new Blob([value]).size;
return maxLength - textAreaLength;
}
onResponse() {
try {
if (!this.sms.destination)
throw new Error(`The destination can't be empty`);
if (!this.sms.message)
throw new Error(`The message can't be empty`);
if (this.charactersRemaining() < 0)
throw new Error(`The message it's too long`);
this.$http.post(`Routes/sendSms`, this.sms).then(res => {
this.vnApp.showMessage(this.$t('SMS sent!'));
if (res.data) this.emit('send', {response: res.data});
});
} catch (e) {
this.vnApp.showError(this.$t(e.message));
return false;
}
return true;
}
}
ngModule.vnComponent('vnRouteSms', {
template: require('./index.html'),
controller: Controller,
bindings: {
sms: '<',
}
});

View File

@ -0,0 +1,71 @@
import './index';
describe('Route', () => {
describe('Component vnRouteSms', () => {
let controller;
let $httpBackend;
beforeEach(ngModule('route'));
beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
let $scope = $rootScope.$new();
const $element = angular.element('<vn-dialog></vn-dialog>');
controller = $componentController('vnRouteSms', {$element, $scope});
controller.$.message = {
input: {
value: 'My SMS'
}
};
}));
describe('onResponse()', () => {
it('should perform a POST query and show a success snackbar', () => {
let params = {destinationFk: 1101, destination: 111111111, message: 'My SMS'};
controller.sms = {destinationFk: 1101, destination: 111111111, message: 'My SMS'};
jest.spyOn(controller.vnApp, 'showMessage');
$httpBackend.expect('POST', `Routes/sendSms`, params).respond(200, params);
controller.onResponse();
$httpBackend.flush();
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('SMS sent!');
});
it('should call onResponse without the destination and show an error snackbar', () => {
controller.sms = {destinationFk: 1101, message: 'My SMS'};
jest.spyOn(controller.vnApp, 'showError');
controller.onResponse();
expect(controller.vnApp.showError).toHaveBeenCalledWith(`The destination can't be empty`);
});
it('should call onResponse without the message and show an error snackbar', () => {
controller.sms = {destinationFk: 1101, destination: 222222222};
jest.spyOn(controller.vnApp, 'showError');
controller.onResponse();
expect(controller.vnApp.showError).toHaveBeenCalledWith(`The message can't be empty`);
});
});
describe('charactersRemaining()', () => {
it('should return the characters remaining in a element', () => {
controller.$.message = {
input: {
value: 'My message 0€'
}
};
let result = controller.charactersRemaining();
expect(result).toEqual(145);
});
});
});
});

View File

@ -0,0 +1,9 @@
Send SMS to the selected tickets: Enviar SMS a los tickets seleccionados
Routes to notify: Rutas a notificar
Message: Mensaje
SMS sent!: ¡SMS enviado!
Characters remaining: Carácteres restantes
The destination can't be empty: El destinatario no puede estar vacio
The message can't be empty: El mensaje no puede estar vacio
The message it's too long: El mensaje es demasiado largo
Special characters like accents counts as a multiple: Carácteres especiales como los acentos cuentan como varios

View File

@ -0,0 +1,5 @@
@import "variables";
.SMSDialog {
min-width: 400px
}

View File

@ -29,13 +29,21 @@
disabled="!$ctrl.isChecked"
ng-click="$ctrl.deletePriority()"
vn-tooltip="Delete priority"
icon="filter_alt_off">
icon="filter_alt">
</vn-button>
<vn-button
ng-click="$ctrl.setOrderedPriority($ctrl.tickets)"
vn-tooltip="Renumber all tickets in the order you see on the screen"
icon="format_list_numbered">
</vn-button>
<vn-button
vn-acl="deliveryBoss"
vn-acl-action="remove"
disabled="!$ctrl.isChecked"
icon="sms"
vn-tooltip="Send SMS to all clients"
ng-click="$ctrl.sendSms()">
</vn-button>
</vn-tool-bar>
<vn-table class="vn-pt-md" model="model" auto-load="false" vn-droppable="$ctrl.onDrop($event)">
<vn-thead>
@ -149,19 +157,29 @@
route="$ctrl.$params"
parent-reload="$ctrl.$.model.refresh()">
</vn-route-ticket-popup>
<vn-float-button
icon="add"
ng-click="$ctrl.$.ticketPopup.show()"
vn-tooltip="Add ticket"
vn-acl="delivery"
vn-acl-action="remove"
vn-bind="+"
fixed-bottom-right>
</vn-float-button>
<div fixed-bottom-right>
<vn-vertical style="align-items: center;">
<a vn-bind="+">
<vn-button
class="round md vn-mb-sm"
ng-click="$ctrl.$.ticketPopup.show()"
icon="add"
vn-tooltip="Add ticket"
vn-acl="delivery"
vn-acl-action="remove"
tooltip-position="left">
</vn-button>
</a>
</vn-vertical>
</div>
<vn-ticket-descriptor-popover
vn-id="ticket-descriptor">
</vn-ticket-descriptor-popover>
<vn-client-descriptor-popover
vn-id="client-descriptor">
</vn-client-descriptor-popover>
</vn-client-descriptor-popover>
<!-- SMS Dialog -->
<vn-route-sms
vn-id="sms"
sms="$ctrl.newSMS">
</vn-route-sms>

View File

@ -161,6 +161,37 @@ class Controller extends Section {
throw error;
});
}
async sendSms() {
try {
const clientsFk = [];
const clientsName = [];
const clients = [];
const selectedTickets = this.getSelectedItems(this.$.$ctrl.tickets);
for (let ticket of selectedTickets) {
clientsFk.push(ticket.clientFk);
let userContact = await this.$http.get(`Clients/${ticket.clientFk}`);
clientsName.push(userContact.data.name);
clients.push(userContact.data.phone);
}
const destinationFk = String(clientsFk);
const destination = String(clients);
this.newSMS = Object.assign({
destinationFk: destinationFk,
destination: destination
});
this.$.sms.open();
return true;
} catch (e) {
this.vnApp.showError(this.$t(e.message));
return false;
}
}
}
ngModule.vnComponent('vnRouteTickets', {