#849 order.basic-data

This commit is contained in:
Gerard 2018-11-30 11:45:17 +01:00
parent eda5a937f6
commit 8aa969c5b4
11 changed files with 206 additions and 3 deletions

View File

@ -64,9 +64,19 @@
"state": "order.create",
"component": "vn-order-create",
"description": "New order"
},
{
"url": "/basic-data",
"state": "order.card.basicData",
"component": "vn-order-basic-data",
"description": "Basic data",
"params": {
"order": "$ctrl.order"
}
}
],
"menu": [
{"state": "order.card.basicData", "icon": "settings"},
{"state": "order.card.catalog", "icon": "shopping_cart"},
{"state": "order.card.volume", "icon": "icon-volume"},
{"state": "order.card.line", "icon": "icon-lines"}

View File

@ -0,0 +1,55 @@
<mg-ajax path="/order/api/Orders/{{patch.params.id}}/updateBasicData" options="vnPatch"></mg-ajax>
<vn-watcher
vn-id="watcher"
data="$ctrl.order"
form="form"
save="patch">
</vn-watcher>
<form name="form" ng-submit="watcher.submit()">
<vn-card pad-large>
<vn-title>Basic data</vn-title>
<vn-horizontal>
<vn-autocomplete
disabled="$ctrl.order.rows.length || $ctrl.order.isConfirmed"
vn-one
url="/api/Clients"
label="Client"
search-function="{or: [{id: {regexp: $search}}, {name: {regexp: $search}}]}"
show-field="name"
value-field="id"
field="$ctrl.order.clientFk">
<tpl-item>{{id}}: {{name}}</tpl-item>
</vn-autocomplete>
<vn-autocomplete
vn-one
disabled="$ctrl.order.rows.length || $ctrl.order.isConfirmed"
url="/api/Companies"
label="Company"
show-field="code"
value-field="id"
field="$ctrl.order.companyFk">
</vn-autocomplete>
<vn-date-picker
vn-one
disabled="$ctrl.order.rows.length || $ctrl.order.isConfirmed"
label="Landed"
model="$ctrl.order.landed"
ini-options="{enableTime: false}">
</vn-date-picker>
</vn-horizontal>
<vn-horizontal>
<vn-textarea
vn-three
disabled="$ctrl.order.rows.length || $ctrl.order.isConfirmed"
label="Observation"
field="$ctrl.order.note">
</vn-textarea>
</vn-horizontal>
<vn-horizontal ng-if="$ctrl.order.rows.length|| $ctrl.order.isConfirmed" class="disabledForm">
<span class="disabled" translate>This form has been disabled because there are lines in this order or it's confirmed</span>
</vn-horizontal>
</vn-card>
<vn-button-bar>
<vn-submit label="Save"></vn-submit>
</vn-button-bar>
</form>

View File

@ -0,0 +1,9 @@
import ngModule from '../module';
import './style.scss';
ngModule.component('vnOrderBasicData', {
template: require('./index.html'),
bindings: {
order: '<'
}
});

View File

@ -0,0 +1 @@
This form has been disabled because there are lines in this order or it's confirmed: Este formulario ha sido deshabilitado por que esta orden contiene líneas o está confirmada

View File

@ -0,0 +1,9 @@
vn-order-basic-data {
.disabledForm {
text-align: center;
color: red;
span {
margin: 0 auto;
}
}
}

View File

@ -33,6 +33,8 @@ class Controller {
let query = `/order/api/Orders/${this.$state.params.id}?filter=${json}`;
this.$http.get(query).then(res => {
if (res.data) {
if (res.data.rows.length == 0)
delete res.data.rows;
this.order = res.data;
this.getTotal();
}
@ -46,9 +48,8 @@ class Controller {
getTotal() {
let query = `/order/api/Orders/${this.$state.params.id}/getTotal`;
this.$http.get(query).then(res => {
if (res.data) {
if (res.data)
this.order.total = res.data;
}
});
}
}

View File

@ -31,7 +31,7 @@
value="{{$ctrl.order.address.nickname}}">
</vn-label-value>
<vn-label-value label="Items"
value="{{$ctrl.order.rows.length}}">
value="{{$ctrl.order.rows.length || 0}}">
</vn-label-value>
<vn-label-value label="Total"
value="{{$ctrl.order.total | currency: ' €': 2}}">

View File

@ -13,3 +13,4 @@ import './prices-popover';
import './volume';
import './create';
import './create/card';
import './basic-data';

View File

@ -0,0 +1,65 @@
const app = require(`${servicesDir}/order/server/server`);
describe('Order updateBasicData', () => {
afterAll(async () => {
let validparams = {note: null};
let orderId = 22;
await app.models.Order.updateBasicData(validparams, orderId);
});
it('should return an error if the order is confirmed', async () => {
let error;
let params = [];
let orderConfirmed = 1;
await app.models.Order.updateBasicData(params, orderConfirmed)
.catch(e => {
error = e;
});
expect(error.toString()).toContain(`You can't make changes on the basic data of an confirmed order or with rows`);
});
it('should return an error if the order has rows', async () => {
let error;
let params = [];
let orderWithRows = 16;
await app.models.Order.updateBasicData(params, orderWithRows)
.catch(e => {
error = e;
});
expect(error.toString()).toContain(`You can't make changes on the basic data of an confirmed order or with rows`);
});
it('should return an error if the user is administrative and the isTaxDataChecked value is true BUT the params aint valid', async () => {
let error;
let invalidparams = {invalid: 'param for update'};
let orderId = 22;
await app.models.Order.updateBasicData(invalidparams, orderId)
.catch(e => {
error = e;
});
expect(error.toString()).toContain(`You don't have enough privileges to do that`);
});
it('should update the client fiscal data and return the count if changes made', async () => {
let validparams = {note: 'test note'};
let orderId = 22;
let order = await app.models.Order.findById(orderId);
expect(order.note).toEqual(null);
let result = await app.models.Order.updateBasicData(validparams, orderId);
expect(result.note).toEqual('test note');
});
});

View File

@ -0,0 +1,51 @@
let UserError = require('../../helpers').UserError;
module.exports = Self => {
Self.remoteMethod('updateBasicData', {
description: 'Updates basic data of an order',
accessType: 'WRITE',
accepts: [{
arg: 'data',
type: 'Object',
required: true,
description: 'Params to update',
http: {source: 'body'}
}, {
arg: 'id',
type: 'string',
required: true,
description: 'Model id',
http: {source: 'path'}
}],
returns: {
arg: 'order',
type: 'Object',
root: true
},
http: {
path: `/:id/updateBasicData`,
verb: 'PATCH'
}
});
Self.updateBasicData = async (params, id) => {
let order = await Self.app.models.Order.findById(id);
let orderRows = await Self.app.models.OrderRow.find({where: {orderFk: id}});
if (order.confirmed || orderRows.length != 0)
throw new UserError(`You can't make changes on the basic data of an confirmed order or with rows`);
let validUpdateParams = [
'clientFk',
'companyFk',
'landed',
'note',
];
for (const key in params) {
if (validUpdateParams.indexOf(key) === -1)
throw new UserError(`You don't have enough privileges to do that`);
}
return await order.updateAttributes(params);
};
};

View File

@ -10,4 +10,5 @@ module.exports = Self => {
require('../methods/order/getVAT')(Self);
require('../methods/order/getSourceValues')(Self);
require('../methods/order/newFromTicket')(Self);
require('../methods/order/updateBasicData')(Self);
};