From f4add0942c2dc2f0e11ab379dda90270f649b4f2 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez <=> Date: Wed, 24 Oct 2018 13:45:59 +0200 Subject: [PATCH 1/3] #751 removes.spec.js repairs --- .../common/methods/client/specs/getMana.spec.js | 1 - .../common/methods/sale/specs/removes.spec.js | 15 +++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/services/loopback/common/methods/client/specs/getMana.spec.js b/services/loopback/common/methods/client/specs/getMana.spec.js index 1b621faab..fcaeb3730 100644 --- a/services/loopback/common/methods/client/specs/getMana.spec.js +++ b/services/loopback/common/methods/client/specs/getMana.spec.js @@ -7,4 +7,3 @@ describe('client getMana()', () => { expect(result.mana).toEqual(151.33); }); }); - diff --git a/services/loopback/common/methods/sale/specs/removes.spec.js b/services/loopback/common/methods/sale/specs/removes.spec.js index 1032129f9..fd74f3641 100644 --- a/services/loopback/common/methods/sale/specs/removes.spec.js +++ b/services/loopback/common/methods/sale/specs/removes.spec.js @@ -1,14 +1,13 @@ const app = require(`${servicesDir}/ticket/server/server`); -xdescribe('sale removes()', () => { +describe('sale removes()', () => { let sale; + let newsale; beforeAll(async() => { - sale = await app.models.Sale.findOne({where: {id: 1}}); - }); - - afterAll(async() => { - await app.models.Sale.create(sale); + sale = await app.models.Sale.findOne({where: {id: 9}}); + sale.id = null; + newsale = await app.models.Sale.create(sale); }); it('should throw an error if the ticket of the given sales is not editable', async() => { @@ -30,8 +29,8 @@ xdescribe('sale removes()', () => { it('should delete the sales', async() => { let params = { - sales: [{id: 1, instance: 0}], - actualTicketFk: 1 + sales: [{id: newsale.id, instance: 0}], + actualTicketFk: 16 }; let res = await app.models.Sale.removes(params); From 7a6b2f19d3f2e54c1822a246d6940db9febf6574 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez <=> Date: Wed, 24 Oct 2018 14:10:08 +0200 Subject: [PATCH 2/3] #753 order - removes.spec.js repairs + refactors --- .../order/common/methods/order-row/removes.js | 7 ++++-- .../order-row/specs/addToOrder.spec.js | 8 ++++++- .../methods/order-row/specs/removes.spec.js | 24 +++++++++++++++++-- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/services/order/common/methods/order-row/removes.js b/services/order/common/methods/order-row/removes.js index c08ac9a8f..0f8aaa86e 100644 --- a/services/order/common/methods/order-row/removes.js +++ b/services/order/common/methods/order-row/removes.js @@ -23,9 +23,12 @@ module.exports = Self => { Self.removes = async params => { if (!params.rows || !params.rows.length) - throw new UserError('There is nothing delete'); + throw new UserError('There is nothing to delete'); - await Self.app.models.Order.isEditable(params.actualOrderId); + let isEditable = await Self.app.models.Order.isEditable(params.actualOrderId); + + if (!isEditable) + throw new UserError('This order is not editable'); let promises = []; for (let i = 0; i < params.rows.length; i++) { diff --git a/services/order/common/methods/order-row/specs/addToOrder.spec.js b/services/order/common/methods/order-row/specs/addToOrder.spec.js index c9c1a53cd..9cef506d6 100644 --- a/services/order/common/methods/order-row/specs/addToOrder.spec.js +++ b/services/order/common/methods/order-row/specs/addToOrder.spec.js @@ -1,6 +1,11 @@ const app = require(`../../../../server/server`); describe('order addToOrder()', () => { + let rowToDelete; + afterAll(async() => { + await app.models.OrderRow.removes({rows: [rowToDelete], actualOrderId: 16}); + }); + it('should add a row to a given order', async() => { let unmodifiedRows = await app.models.OrderRow.find({where: {orderFk: 16}}); @@ -19,7 +24,8 @@ describe('order addToOrder()', () => { let modifiedRows = await app.models.OrderRow.find({where: {orderFk: 16}}); + rowToDelete = modifiedRows[modifiedRows.length - 1].id; + expect(modifiedRows.length).toBe(5); - await app.models.OrderRow.removes({rows: [modifiedRows[modifiedRows.length - 1].id]}); }); }); diff --git a/services/order/common/methods/order-row/specs/removes.spec.js b/services/order/common/methods/order-row/specs/removes.spec.js index b6dafae24..f8a90e2c0 100644 --- a/services/order/common/methods/order-row/specs/removes.spec.js +++ b/services/order/common/methods/order-row/specs/removes.spec.js @@ -1,6 +1,15 @@ const app = require(`../../../../server/server`); -xdescribe('order removes()', () => { +describe('order removes()', () => { + let row; + let newRow; + + beforeAll(async() => { + row = await app.models.OrderRow.findOne({where: {id: 12}}); + row.id = null; + newRow = await app.models.OrderRow.create(row); + }); + it('should throw an error if rows property is empty', async() => { let error; try { @@ -9,7 +18,7 @@ xdescribe('order removes()', () => { error = e; } - expect(error).toEqual(new Error('There is nothing delete')); + expect(error).toEqual(new Error('There is nothing to delete')); }); it('should throw an error if the row selected is not editable', async() => { @@ -22,4 +31,15 @@ xdescribe('order removes()', () => { expect(error).toEqual(new Error('This order is not editable')); }); + + it('should delete the row', async() => { + let params = { + rows: [newRow.id], + actualOrderId: 16 + }; + + let res = await app.models.OrderRow.removes(params); + + expect(res).toEqual([{count: 1}]); + }); }); From 3b2466e1210e4a09c0eb5def4b14c0625e033e92 Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 24 Oct 2018 14:10:48 +0200 Subject: [PATCH 3/3] Tarea #703 client.risk.new --- client/client/routes.json | 9 +++ client/client/src/client.js | 1 + client/client/src/greuge/create/index.js | 4 +- client/client/src/risk/create/index.html | 45 +++++++++++++ client/client/src/risk/create/index.js | 66 +++++++++++++++++++ client/client/src/risk/index/index.html | 2 - .../client/common/methods/receipt/filter.js | 2 +- services/client/common/models/receipt.js | 10 +++ 8 files changed, 134 insertions(+), 5 deletions(-) create mode 100644 client/client/src/risk/create/index.html create mode 100644 client/client/src/risk/create/index.js diff --git a/client/client/routes.json b/client/client/routes.json index 3969fbc69..b53394ce2 100644 --- a/client/client/routes.json +++ b/client/client/routes.json @@ -224,6 +224,15 @@ "icon": "icon-invoices" } }, + { + "url": "/create?payed&companyFk&bankFk&payedAmount", + "state": "client.card.risk.create", + "component": "vn-client-risk-create", + "description": "New payment", + "params": { + "client": "$ctrl.client" + } + }, { "url": "/recovery", "abstract": true, diff --git a/client/client/src/client.js b/client/client/src/client.js index b496e2336..007a1c970 100644 --- a/client/client/src/client.js +++ b/client/client/src/client.js @@ -20,6 +20,7 @@ import './credit/create'; import './greuge/index'; import './greuge/create'; import './risk/index'; +import './risk/create'; import './mandate'; import './summary'; import './recovery/index'; diff --git a/client/client/src/greuge/create/index.js b/client/client/src/greuge/create/index.js index 31e760ea3..b0a2eec93 100644 --- a/client/client/src/greuge/create/index.js +++ b/client/client/src/greuge/create/index.js @@ -5,7 +5,8 @@ class Controller { this.$ = $scope; this.$state = $state; this.greuge = { - shipped: new Date() + shipped: new Date(), + clientFk: $state.params.id }; } @@ -18,7 +19,6 @@ class Controller { } onSubmit() { - this.greuge.clientFk = this.$state.params.id; this.$.watcher.submit().then( () => { this.goToIndex(); diff --git a/client/client/src/risk/create/index.html b/client/client/src/risk/create/index.html new file mode 100644 index 000000000..2ebb216dd --- /dev/null +++ b/client/client/src/risk/create/index.html @@ -0,0 +1,45 @@ + + + +
+ + New payment + + + + + + + + + + + + + + + + + +
\ No newline at end of file diff --git a/client/client/src/risk/create/index.js b/client/client/src/risk/create/index.js new file mode 100644 index 000000000..c040b9348 --- /dev/null +++ b/client/client/src/risk/create/index.js @@ -0,0 +1,66 @@ +import ngModule from '../../module'; + +class Controller { + constructor($scope, $state, $http, $stateParams) { + this.$http = $http; + this.$ = $scope; + this.$state = $state; + this.$stateParams = $stateParams; + + this.receipt = { + payed: new Date(), + clientFk: this.$state.params.id, + companyFk: window.localStorage.defaultCompanyFk, + bankFk: window.localStorage.defaultBankFk + }; + + if (this.$stateParams.payed) + this.receipt.payed = this.$stateParams.payed; + + if (this.$stateParams.bankFk) + this.receipt.bankFk = this.$stateParams.bankFk; + + if (this.$stateParams.amountPaid) + this.receipt.amountPaid = this.$stateParams.amountPaid; + + if (this.$stateParams.companyFk) { + this.receipt.companyFk = this.$stateParams.companyFk; + } + } + + $onInit() { + let filter = { + where: { + clientFk: this.$state.params.id, + companyFk: this.receipt.companyFk + } + }; + + let query = `/client/api/ClientRisks?filter=${JSON.stringify(filter)}`; + this.$http.get(query).then(res => { + this.receipt.amountPaid = (res.data.length && res.data[0].amount) || null; + }); + } + + cancel() { + this.goToIndex(); + } + + goToIndex() { + this.$state.go('client.card.risk.index'); + } + + onSubmit() { + this.$.watcher.submit().then( + () => { + this.goToIndex(); + } + ); + } +} +Controller.$inject = ['$scope', '$state', '$http', '$stateParams']; + +ngModule.component('vnClientRiskCreate', { + template: require('./index.html'), + controller: Controller +}); diff --git a/client/client/src/risk/index/index.html b/client/client/src/risk/index/index.html index 95c7fd431..b924da4ab 100644 --- a/client/client/src/risk/index/index.html +++ b/client/client/src/risk/index/index.html @@ -40,7 +40,6 @@ Debit Credit Conciliated - Company @@ -58,7 +57,6 @@ disabled="true"> - {{::risk.company}} diff --git a/services/client/common/methods/receipt/filter.js b/services/client/common/methods/receipt/filter.js index d64413197..12474240a 100644 --- a/services/client/common/methods/receipt/filter.js +++ b/services/client/common/methods/receipt/filter.js @@ -43,7 +43,7 @@ module.exports = Self => { name, r.clientFk FROM vn.receipt r - JOIN vn.worker w ON w.id = r.workerFk + LEFT JOIN vn.worker w ON w.id = r.workerFk JOIN vn.company c ON c.id = r.companyFk WHERE clientFk = ? UNION ALL diff --git a/services/client/common/models/receipt.js b/services/client/common/models/receipt.js index 97907c457..6cc767e2c 100644 --- a/services/client/common/models/receipt.js +++ b/services/client/common/models/receipt.js @@ -1,3 +1,13 @@ module.exports = function(Self) { require('../methods/receipt/filter')(Self); + + Self.observe('before save', async function(ctx) { + if (ctx.isNewInstance) { + let token = ctx.options.accessToken; + let userId = token && token.userId; + let worker = await Self.app.models.Worker.findOne({where: {userFk: userId}}); + + ctx.instance.workerFk = worker.id; + } + }); };