#1642 order.summary en el descriptor

This commit is contained in:
Carlos Jimenez Ruiz 2019-08-29 13:16:38 +02:00
parent 6daabed202
commit b9234fc1a8
9 changed files with 107 additions and 10 deletions

View File

@ -580,6 +580,10 @@ export default {
searchButton: 'vn-order-index vn-searchbar vn-icon[icon="search"]',
createOrderButton: `${components.vnFloatButton}`,
},
orderDescriptor: {
returnToModuleIndexButton: 'vn-order-descriptor a[ui-sref="order.index"]',
acceptNavigationButton: 'vn-order-basic-data vn-confirm button[response=ACCEPT]'
},
createOrderView: {
clientAutocomplete: 'vn-autocomplete[label="Client"]',
addressAutocomplete: 'vn-autocomplete[label="Address"]',

View File

@ -28,8 +28,8 @@ describe('Order edit basic data path', () => {
it('should now navigate to order index', async() => {
const orderId = 16;
const url = await nightmare
.waitToClick(selectors.globalItems.returnToModuleIndexButton)
.waitToClick(selectors.globalItems.acceptButton)
.waitToClick(selectors.orderDescriptor.returnToModuleIndexButton)
.waitToClick(selectors.orderDescriptor.acceptNavigationButton)
.wait(selectors.ordersIndex.createOrderButton)
.accessToSearchResult(orderId)
.accessToSection('order.card.basicData')

View File

@ -52,5 +52,6 @@
"Concept cannot be blank": "Concept cannot be blank",
"Ticket id cannot be blank": "Ticket id cannot be blank",
"Weekday cannot be blank": "Weekday cannot be blank",
"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"
}

View File

@ -100,5 +100,6 @@
"You don't have privileges to change the zone": "No tienes permisos para cambiar la zona",
"This ticket is already on weekly tickets": "Este ticket ya está en tickets programados",
"Ticket id cannot be blank": "El id de ticket no puede quedar en blanco",
"Weekday cannot be blank": "El día de la semana no puede quedar en blanco"
"Weekday cannot be blank": "El día de la semana no puede quedar en blanco",
"You can't delete a confirmed order": "No puedes borrar un pedido confirmado"
}

View File

@ -1,3 +1,5 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
require('../methods/order/new')(Self);
require('../methods/order/getTotalVolume')(Self);
@ -14,4 +16,11 @@ module.exports = Self => {
require('../methods/order/confirm')(Self);
require('../methods/order/filter')(Self);
require('../methods/order/getItemTypeAvailable')(Self);
Self.beforeRemote('deleteById', async function(ctx) {
const targetOrder = await Self.findById(ctx.args.id);
if (targetOrder.isConfirmed === 1)
throw new UserError(`You can't delete a confirmed order`);
});
};

View File

@ -6,7 +6,15 @@
<a translate-attr="{title: 'Preview'}" ui-sref="order.card.summary">
<vn-icon icon="desktop_windows"></vn-icon>
</a>
<div></div>
<vn-icon-menu
vn-id="more-button"
icon="more_vert"
show-filter="false"
value-field="callback"
translate-fields="['name']"
data="$ctrl.moreOptions"
on-change="value()">
</vn-icon-menu>
</div>
<div class="body">
<div class="attributes">
@ -17,7 +25,7 @@
value="{{$ctrl.order.client.name}}">
</vn-label-value>
<vn-label-value label="State"
value="{{$ctrl.order.isConfirmed ? $ctrl.translate.instant('Confirmed') : $ctrl.translate.instant('Not confirmed')}}">
value="{{$ctrl.order.isConfirmed ? $ctrl.$translate.instant('Confirmed') : $ctrl.$translate.instant('Not confirmed')}}">
</vn-label-value>
<vn-label-value label="Sales person"
value="{{$ctrl.order.client.salesPerson.user.nickname}}">
@ -66,3 +74,9 @@
</div>
</div>
</div>
<vn-confirm
vn-id="deleteOrderConfirmation"
on-response="$ctrl.deleteOrder(response)"
message="You are going to delete this order"
question="continue anyway?">
</vn-confirm>

View File

@ -2,8 +2,15 @@ import ngModule from '../module';
import './style.scss';
class Controller {
constructor($translate) {
this.translate = $translate;
constructor($translate, $scope, vnApp, $http, $state) {
this.$state = $state;
this.$scope = $scope;
this.vnApp = vnApp;
this.$http = $http;
this.$translate = $translate;
this.moreOptions = [
{name: 'Delete order', callback: () => this.showDeleteOrderDialog()}
];
}
set order(value) {
@ -36,9 +43,23 @@ class Controller {
get quicklinks() {
return this._quicklinks;
}
deleteOrder(response) {
if (response === 'ACCEPT') {
const params = {id: this.order.id};
this.$http.delete(`/api/Orders/${params.id}`).then(() => {
this.$state.go('order.index');
this.vnApp.showSuccess(this.$translate.instant('Order deleted'));
});
}
}
showDeleteOrderDialog() {
this.$scope.deleteOrderConfirmation.show();
}
}
Controller.$inject = ['$translate'];
Controller.$inject = ['$translate', '$scope', 'vnApp', '$http', '$state'];
ngModule.component('vnOrderDescriptor', {
template: require('./index.html'),

View File

@ -0,0 +1,44 @@
import './index.js';
describe('Order Component vnOrderDescriptor', () => {
let $httpBackend;
let controller;
beforeEach(() => {
ngModule('order');
});
beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
controller = $componentController('vnOrderDescriptor');
controller.order = {id: 1};
}));
describe('deleteOrder()', () => {
it(`should do nothing if the response isn't ACCEPT`, () => {
let response = 'WAGH!';
spyOn(controller.vnApp, 'showSuccess');
spyOn(controller.$state, 'go');
controller.deleteOrder(response);
expect(controller.vnApp.showSuccess).not.toHaveBeenCalledWith('Order deleted!');
expect(controller.$state.go).not.toHaveBeenCalledWith('order.index');
});
it(`should perform a DELETE query if the response was ACCEPT`, () => {
let response = 'ACCEPT';
spyOn(controller.vnApp, 'showSuccess');
spyOn(controller.$state, 'go');
$httpBackend.when('DELETE', `/api/Orders/${controller.order.id}`).respond(200);
$httpBackend.expect('DELETE', `/api/Orders/${controller.order.id}`);
controller.deleteOrder(response);
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Order deleted');
expect(controller.$state.go).toHaveBeenCalledWith('order.index');
});
});
});

View File

@ -7,3 +7,6 @@ Items: Articulos
Agency: Agencia
Sales person: Comercial
Order ticket list: Ticket del pedido
Delete order: Borrar pedido
You are going to delete this order: El pedido se borrará
continue anyway?: ¿Continuar de todos modos?