diff --git a/client/order/routes.json b/client/order/routes.json index d2e8fb76f..00cd3e18b 100644 --- a/client/order/routes.json +++ b/client/order/routes.json @@ -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"} diff --git a/client/order/src/basic-data/index.html b/client/order/src/basic-data/index.html new file mode 100644 index 000000000..8e92188da --- /dev/null +++ b/client/order/src/basic-data/index.html @@ -0,0 +1,55 @@ + + + +
+ + Basic data + + + {{id}}: {{name}} + + + + + + + + + + + + This form has been disabled because there are lines in this order or it's confirmed + + + + + +
diff --git a/client/order/src/basic-data/index.js b/client/order/src/basic-data/index.js new file mode 100644 index 000000000..1272e5353 --- /dev/null +++ b/client/order/src/basic-data/index.js @@ -0,0 +1,9 @@ +import ngModule from '../module'; +import './style.scss'; + +ngModule.component('vnOrderBasicData', { + template: require('./index.html'), + bindings: { + order: '<' + } +}); diff --git a/client/order/src/basic-data/locale/es.yml b/client/order/src/basic-data/locale/es.yml new file mode 100644 index 000000000..5c6014c9c --- /dev/null +++ b/client/order/src/basic-data/locale/es.yml @@ -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 \ No newline at end of file diff --git a/client/order/src/basic-data/style.scss b/client/order/src/basic-data/style.scss new file mode 100644 index 000000000..34d6c2931 --- /dev/null +++ b/client/order/src/basic-data/style.scss @@ -0,0 +1,9 @@ +vn-order-basic-data { + .disabledForm { + text-align: center; + color: red; + span { + margin: 0 auto; + } + } +} \ No newline at end of file diff --git a/client/order/src/card/index.js b/client/order/src/card/index.js index 71119ad9a..f5c88f381 100644 --- a/client/order/src/card/index.js +++ b/client/order/src/card/index.js @@ -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; - } }); } } diff --git a/client/order/src/descriptor/index.html b/client/order/src/descriptor/index.html index 1f90e0339..fc5e6f10c 100644 --- a/client/order/src/descriptor/index.html +++ b/client/order/src/descriptor/index.html @@ -31,7 +31,7 @@ value="{{$ctrl.order.address.nickname}}"> + value="{{$ctrl.order.rows.length || 0}}"> diff --git a/client/order/src/index.js b/client/order/src/index.js index 6da1a918f..27b5699a0 100644 --- a/client/order/src/index.js +++ b/client/order/src/index.js @@ -13,3 +13,4 @@ import './prices-popover'; import './volume'; import './create'; import './create/card'; +import './basic-data'; diff --git a/services/loopback/common/methods/order/specs/updateBasicData.spec.js b/services/loopback/common/methods/order/specs/updateBasicData.spec.js new file mode 100644 index 000000000..76a108749 --- /dev/null +++ b/services/loopback/common/methods/order/specs/updateBasicData.spec.js @@ -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'); + }); +}); diff --git a/services/loopback/common/methods/order/updateBasicData.js b/services/loopback/common/methods/order/updateBasicData.js new file mode 100644 index 000000000..505b6f654 --- /dev/null +++ b/services/loopback/common/methods/order/updateBasicData.js @@ -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); + }; +}; diff --git a/services/loopback/common/models/order.js b/services/loopback/common/models/order.js index 09d04a010..24a778440 100644 --- a/services/loopback/common/models/order.js +++ b/services/loopback/common/models/order.js @@ -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); };