Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 3607-supplier_agencyTerm

This commit is contained in:
Vicent Llopis 2022-03-10 10:36:02 +01:00
commit ba31d96cdf
12 changed files with 277 additions and 221 deletions

View File

@ -11,3 +11,4 @@ import './create';
import './basic-data';
import './log';
import './tickets';
import './ticket-popup';

View File

@ -48,6 +48,11 @@
<vn-td number>{{::route.m3 | dashIfEmpty}}</vn-td>
<vn-td>{{::route.description | dashIfEmpty}}</vn-td>
<vn-td>
<vn-icon-button
vn-click-stop="$ctrl.showTicketPopup(route)"
vn-tooltip="Añadir tickets"
icon="icon-ticketAdd">
</vn-icon-button>
<vn-icon-button
vn-click-stop="$ctrl.preview(route)"
vn-tooltip="Preview"
@ -66,9 +71,20 @@
</vn-route-summary>
</vn-popup>
<vn-route-ticket-popup
vn-id="ticketPopup"
route="$ctrl.routeSelected">
</vn-route-ticket-popup>
<vn-worker-descriptor-popover
vn-id="workerDescriptor">
</vn-worker-descriptor-popover>
<vn-ticket-descriptor-popover
vn-id="ticketDescriptor">
</vn-ticket-descriptor-popover>
<vn-client-descriptor-popover
vn-id="clientDescriptor">
</vn-client-descriptor-popover>
<div fixed-bottom-right>
<vn-vertical style="align-items: center;">

View File

@ -13,6 +13,11 @@ export default class Controller extends Section {
this.$.summary.show();
}
showTicketPopup(route) {
this.routeSelected = route;
this.$.ticketPopup.show();
}
get checked() {
const rows = this.$.model.data || [];
const checkedRows = [];

View File

@ -0,0 +1,79 @@
<tpl-title>
<vn-horizontal>
<span translate>Tickets to add</span>
<div class="button-right">
<vn-button label="Add" ng-click="$ctrl.setTicketsRoute()"></vn-button>
</div>
</vn-horizontal>
</tpl-title>
<tpl-body id="manifold-form">
<vn-crud-model
vn-id="model"
url="Routes/{{$ctrl.route.id}}/getSuggestedTickets"
data="$ctrl.possibleTickets"
auto-load="true">
</vn-crud-model>
<vn-data-viewer data="$ctrl.possibleTickets" class="manifold-panel">
<vn-table auto-load="true">
<vn-thead>
<vn-tr>
<vn-th shrink>
<vn-multi-check
model="model">
</vn-multi-check>
</vn-th>
<vn-th number>Ticket</vn-th>
<vn-th>Client</vn-th>
<vn-th shrink>Province</vn-th>
<vn-th shrink>
<span translate>
Population
</span>
</vn-th>
<vn-th expand>PC</vn-th>
<vn-th>Address</vn-th>
<vn-th shrink>Warehouse</vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr ng-repeat="ticket in $ctrl.possibleTickets">
<vn-td shrink>
<vn-check
ng-model="ticket.checked">
</vn-check>
</vn-td>
<vn-td number>
<span class="link" ng-click="ticketDescriptor.show($event, ticket.id)">
{{::ticket.id}}
</span>
</vn-td>
<vn-td expand>
<span class="link" ng-click="clientDescriptor.show($event, ticket.clientFk)">
{{::ticket.nickname}}
</span>
</vn-td>
<vn-td shrink>{{::ticket.address.province.name}}</vn-td>
<vn-td shrink>{{::ticket.address.city}}</vn-td>
<vn-td number shrink>{{::ticket.address.postalCode}}</vn-td>
<vn-td expand title="{{::ticket.address.street}}">{{::ticket.address.street}}</vn-td>
<vn-td expand>
{{::ticket.zone.name}}
<vn-icon-button
icon="link_off"
class="pointer"
translate-attr="{title: 'Unlink zone: {{::ticket.zone.name}} from agency: {{::ticket.agencyMode.name}}'}"
ng-click="unlinkZoneConfirmation.show(ticket)">
</vn-icon-button>
</vn-td>
</vn-tr>
</vn-tbody>
</vn-table>
</vn-data-viewer>
<vn-confirm
vn-id="unlinkZoneConfirmation"
on-accept="$ctrl.unlinkZone($data)"
question="{{$ctrl.confirmationMessage}}"
message="Unlink selected zone?">
</vn-confirm>
</tpl-body>

View File

@ -0,0 +1,80 @@
import ngModule from '../module';
import Dialog from 'core/components/dialog';
import './style.scss';
class Controller extends Dialog {
constructor($element, $, $transclude) {
super($element, $, $transclude);
}
getSelectedTickets(tickets) {
const selectedTickets = [];
if (tickets) {
for (let i = 0; i < tickets.length; i++) {
if (tickets[i].checked)
selectedTickets.push(tickets[i]);
}
}
return selectedTickets;
}
updateVolume() {
let url = `Routes/${this.route.id}/updateVolume`;
this.$http.post(url).then(() => {
this.$.model.refresh();
if (this.parentReload)
this.parentReload();
});
}
setTicketsRoute() {
const tickets = this.getSelectedTickets(this.possibleTickets);
if (tickets.length === 0) return;
const updates = [];
for (let ticket of tickets) {
delete ticket.checked;
const update = {
where: {id: ticket.id},
data: {routeFk: this.route.id}
};
updates.push(update);
}
const data = {creates: [], updates: updates, deletes: []};
return this.$http.post(`Tickets/crud`, data)
.then(() => {
this.vnApp.showSuccess(this.$t('Data saved!'));
this.updateVolume();
this.hide();
});
}
unlinkZone(ticket) {
const params = {
agencyModeId: this.route.agencyModeFk,
zoneId: ticket.zoneFk,
};
const query = `Routes/unlink`;
this.$http.post(query, params).then(() => {
this.vnApp.showSuccess(this.$t('Data saved!'));
this.$.model.refresh();
this.hide();
});
}
}
Controller.$inject = ['$element', '$scope', '$transclude'];
ngModule.vnComponent('vnRouteTicketPopup', {
slotTemplate: require('./index.html'),
controller: Controller,
bindings: {
route: '<',
model: '<?',
parentReload: '&'
}
});

View File

@ -0,0 +1,82 @@
/* eslint max-len: ["error", { "code": 150 }]*/
import './index';
describe('Route', () => {
let controller;
let $httpBackend;
let $scope;
beforeEach(ngModule('route'));
beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
$scope = $rootScope.$new();
const $element = angular.element('<vn-route-ticket-popup></vn-route-ticket-popup>');
const $transclude = {
$$boundTransclude: {
$$slots: []
}
};
controller = $componentController('vnRouteTicketPopup', {$element, $scope, $transclude});
controller.route = {id: 1};
controller.$.model = {
refresh: () => {},
remove: () => {}
};
controller.card = {reload: () => {}};
}));
describe('unlink()', () => {
it('should call the route unlink endpoint with the agency and zone ids', () => {
controller.$.model = {refresh: jest.fn()};
jest.spyOn(controller.vnApp, 'showSuccess');
jest.spyOn(controller, 'hide');
controller.route = {
agencyModeFk: 1
};
const ticket = {
zoneFk: 2,
};
const params = {
agencyModeId: controller.route.agencyModeFk,
zoneId: ticket.zoneFk,
};
$httpBackend.expectPOST(`Routes/unlink`, params).respond('ok');
controller.unlinkZone(ticket);
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
expect(controller.hide).toHaveBeenCalled();
expect(controller.$.model.refresh).toHaveBeenCalledWith();
});
});
describe('setTicketsRoute()', () => {
it('should perform a POST query to add tickets to the route', () => {
controller.$.model = {refresh: jest.fn()};
jest.spyOn(controller.vnApp, 'showSuccess');
jest.spyOn(controller, 'hide');
controller.route = {id: 111};
controller.possibleTickets = [
{id: 2, checked: false},
{id: 3, checked: true},
{id: 4, checked: false},
{id: 5, checked: true},
];
$httpBackend.whenPOST(`Routes/${controller.route.id}/updateVolume`).respond(200);
$httpBackend.expectPOST('Tickets/crud').respond();
controller.setTicketsRoute();
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
expect(controller.hide).toHaveBeenCalled();
expect(controller.$.model.refresh).toHaveBeenCalledWith();
});
});
});

View File

@ -0,0 +1,5 @@
@import "variables";
.dialog{
padding: $float-spacing
}

View File

@ -115,83 +115,16 @@
question="Delete ticket from route?"
on-accept="$ctrl.removeTicketFromRoute($index)">
</vn-confirm>
<vn-crud-model
vn-id="possibleTicketsModel"
url="Routes/{{$ctrl.$params.id}}/getSuggestedTickets"
data="$ctrl.possibleTickets">
</vn-crud-model>
<vn-dialog
vn-id="possibleTicketsDialog">
<tpl-title>
<vn-horizontal>
<span translate>Tickets to add</span>
<div class="button-right">
<vn-button label="Add" ng-click="$ctrl.setTicketsRoute()"></vn-button>
</div>
</vn-horizontal>
</tpl-title>
<tpl-body>
<vn-data-viewer model="possibleTicketsModel">
<vn-table model="possibleTicketsModel" auto-load="false">
<vn-thead>
<vn-tr>
<vn-th shrink>
<vn-multi-check
model="possibleTicketsModel">
</vn-multi-check>
</vn-th>
<vn-th number>Ticket</vn-th>
<vn-th>Client</vn-th>
<vn-th shrink>Province</vn-th>
<vn-th shrink>
<span translate>
Population
</span>
</vn-th>
<vn-th expand>PC</vn-th>
<vn-th>Address</vn-th>
<vn-th shrink>Zone</vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr ng-repeat="ticket in $ctrl.possibleTickets">
<vn-td shrink>
<vn-check
ng-model="ticket.checked">
</vn-check>
</vn-td>
<vn-td number>
<span class="link" ng-click="ticketDescriptor.show($event, ticket.id)">
{{::ticket.id}}
</span>
</vn-td>
<vn-td expand>
<span class="link" ng-click="clientDescriptor.show($event, ticket.clientFk)">
{{::ticket.nickname}}
</span>
</vn-td>
<vn-td shrink>{{::ticket.address.province.name}}</vn-td>
<vn-td shrink>{{::ticket.address.city}}</vn-td>
<vn-td number shrink>{{::ticket.address.postalCode}}</vn-td>
<vn-td expand title="{{::ticket.address.street}}">{{::ticket.address.street}}</vn-td>
<vn-td expand>
{{::ticket.zone.name}}
<vn-icon-button
icon="link_off"
class="pointer"
translate-attr="{title: 'Unlink zone: {{::ticket.zone.name}} from agency: {{::ticket.agencyMode.name}}'}"
ng-click="unlinkZoneConfirmation.show(ticket)">
</vn-icon-button>
</vn-td>
</vn-tr>
</vn-tbody>
</vn-table>
</vn-data-viewer>
</tpl-body>
</vn-dialog>
<vn-route-ticket-popup
vn-id="ticketPopup"
route="$ctrl.$params"
parent-reload="$ctrl.$.model.refresh()">
</vn-route-ticket-popup>
<vn-float-button
icon="add"
ng-click="$ctrl.openPossibleTicketsDialog()"
ng-click="$ctrl.$.ticketPopup.show()"
vn-tooltip="Add ticket"
vn-acl="delivery"
vn-acl-action="remove"
@ -204,11 +137,3 @@
<vn-client-descriptor-popover
vn-id="client-descriptor">
</vn-client-descriptor-popover>
<!-- Unlink zone confirmation dialog -->
<vn-confirm
vn-id="unlinkZoneConfirmation"
on-accept="$ctrl.unlinkZone($data)"
question="{{$ctrl.confirmationMessage}}"
message="Unlink selected zone?">
</vn-confirm>

View File

@ -4,14 +4,6 @@ import './style.scss';
import UserError from 'core/lib/user-error';
class Controller extends Section {
get route() {
return this._route;
}
set route(value) {
this._route = value;
}
get isChecked() {
if (this.tickets) {
for (let instance of this.tickets)
@ -37,19 +29,6 @@ class Controller extends Section {
});
}
unlinkZone(ticket) {
const params = {
agencyModeId: this.route.agencyModeFk,
zoneId: ticket.zoneFk,
};
const query = `Routes/unlink`;
this.$http.post(query, params).then(() => {
this.vnApp.showSuccess(this.$t('Data saved!'));
this.$.possibleTicketsModel.refresh();
});
}
getSelectedItems(items) {
const selectedItems = [];
@ -117,38 +96,6 @@ class Controller extends Section {
});
}
openPossibleTicketsDialog() {
this.$.possibleTicketsModel.refresh();
this.$.possibleTicketsDialog.show();
}
setTicketsRoute() {
let tickets = this.getSelectedItems(this.possibleTickets);
if (tickets.length === 0) return;
const updates = [];
for (let ticket of tickets) {
delete ticket.checked;
const update = {
where: {id: ticket.id},
data: {routeFk: this.route.id}
};
updates.push(update);
}
const data = {creates: [], updates: updates, deletes: []};
return this.$http.post(`Tickets/crud`, data)
.then(() => {
this.$.model.data = this.$.model.data.concat(tickets);
this.vnApp.showSuccess(this.$t('Data saved!'));
this.updateVolume();
this.$.possibleTicketsDialog.hide();
});
}
onDrop($event) {
const ticketId = $event.dataTransfer.getData('Text');

View File

@ -74,32 +74,6 @@ describe('Route', () => {
});
});
describe('unlink()', () => {
it('should call the route unlink endpoint with the agency and zone ids', () => {
controller.$.possibleTicketsModel = {refresh: jest.fn()};
jest.spyOn(controller.vnApp, 'showSuccess');
controller.route = {
agencyModeFk: 1
};
const ticket = {
zoneFk: 2,
};
const params = {
agencyModeId: controller.route.agencyModeFk,
zoneId: ticket.zoneFk,
};
$httpBackend.expectPOST(`Routes/unlink`, params).respond('ok');
controller.unlinkZone(ticket);
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
expect(controller.$.possibleTicketsModel.refresh).toHaveBeenCalledWith();
});
});
describe('getSelectedItems()', () => {
it('should return the selected items', () => {
let items = [
@ -208,55 +182,6 @@ describe('Route', () => {
});
});
describe('openPossibleTicketsDialog()', () => {
it('should call both refresh and show methods in posible tickets model and dialog', () => {
controller.$.possibleTicketsModel = {refresh: () => {}};
jest.spyOn(controller.$.possibleTicketsModel, 'refresh');
controller.$.possibleTicketsDialog = {show: () => {}};
jest.spyOn(controller.$.possibleTicketsDialog, 'show');
controller.openPossibleTicketsDialog();
expect(controller.$.possibleTicketsModel.refresh).toHaveBeenCalledWith();
expect(controller.$.possibleTicketsDialog.show).toHaveBeenCalledWith();
});
});
describe('setTicketsRoute()', () => {
it('should perform a POST query to add tickets to the route', () => {
controller.$.possibleTicketsDialog = {hide: () => {}};
jest.spyOn(controller.$.possibleTicketsDialog, 'hide');
controller.$params = {id: 1101};
controller.$.model.data = [{id: 1, checked: false}];
const existingTicket = controller.$.model.data[0];
controller.route = {id: 111};
controller.possibleTickets = [
{id: 2, checked: false},
{id: 3, checked: true},
{id: 4, checked: false},
{id: 5, checked: true},
];
let expectedResult = [
existingTicket,
{id: 3},
{id: 5}
];
$httpBackend.whenPOST(`Routes/${controller.$params.id}/updateVolume`).respond(200);
$httpBackend.expectPOST('Tickets/crud').respond();
controller.setTicketsRoute();
$httpBackend.flush();
expect(controller.$.model.data).toEqual(expectedResult);
expect(controller.$.possibleTicketsDialog.hide).toHaveBeenCalledWith();
});
});
describe('onDrop()', () => {
it('should call the insert method when dragging a ticket number', () => {
jest.spyOn(controller, 'insert');

View File

@ -17,11 +17,6 @@ module.exports = Self => {
arg: 'year',
type: 'date',
required: true,
},
{
arg: 'all',
type: 'boolean',
required: false,
}],
returns: [{
arg: 'absences',

View File

@ -139,10 +139,6 @@
<th class="font gray align-right">{{$t('salesPerson')}}</th>
<td>{{ticket.salesPersonName}}</td>
</tr>
<tr>
<th class="font gray align-right">{{$t('import')}}</th>
<td>{{ticket.import | currency('EUR', $i18n.locale)}}</td>
</tr>
</tbody>
</table>
<div v-if="ticket.description || ticket.shipFk" class="text-area">