diff --git a/.eslintrc.yml b/.eslintrc.yml index 82a1af501..d8b869d91 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -34,4 +34,5 @@ rules: no-multiple-empty-lines: ["error", { "max": 1, "maxEOF": 1 }] space-in-parens: ["error", "never"] jasmine/no-focused-tests: 0 - jasmine/prefer-toHaveBeenCalledWith: 0 \ No newline at end of file + jasmine/prefer-toHaveBeenCalledWith: 0 + arrow-spacing: ["error", { "before": true, "after": true }] \ No newline at end of file diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 7c1ee93f0..d821c7bfc 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -150,20 +150,20 @@ INSERT INTO `vn`.`shelving` (`code`, `parkingFk`, `isPrinted`, `priority`, `park INSERT INTO `vn`.`accountingType`(`id`, `description`, `receiptDescription`,`code`) VALUES - (1, 'CC y Polizas de crédito', NULL, NULL), - (2, 'Cash', NULL, 'cash'), - (3, 'Credit card', NULL, 'creditCard'), - (4, 'Finalcial lines', NULL, NULL), - (5, 'Other products', NULL, NULL), - (6, 'Loans', NULL, NULL), - (7, 'Leasing', NULL, NULL), - (8, 'Compensations', 'Compensations', 'Compensations'); + (1, 'CC y Polizas de crédito', NULL, NULL), + (2, 'Cash', 'Cash', 'cash'), + (3, 'Credit card', 'Credit Card', 'creditCard'), + (4, 'Finalcial lines', NULL, NULL), + (5, 'Other products', NULL, NULL), + (6, 'Loans', NULL, NULL), + (7, 'Leasing', NULL, NULL), + (8, 'Compensations', 'Compensations', 'compensation'); INSERT INTO `vn`.`bank`(`id`, `bank`, `account`, `cash`, `entityFk`, `isActive`, `currencyFk`) VALUES - (1, 'Pay on receipt', '0000000000', 3, 0, 1, 1), - (2, 'Cash', '1111111111', 2, 0, 1, 1), - (3, 'Compensation', '0000000000', 8, 0, 1, 1); + (1, 'Pay on receipt', '5720000001', 3, 0, 1, 1), + (2, 'Cash', '5700000001', 2, 0, 1, 1), + (3, 'Compensation', '4000000000', 8, 0, 1, 1); INSERT INTO `vn`.`deliveryMethod`(`id`, `code`, `description`) VALUES diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 16bd1d361..1b5fbd917 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -171,5 +171,6 @@ "New ticket request has been created with price": "Se ha creado una nueva petición de compra *'{{description}}'* para el día *{{shipped}}*, con una cantidad de *{{quantity}}* y un precio de *{{price}} €*", "New ticket request has been created": "Se ha creado una nueva petición de compra *'{{description}}'* para el día *{{shipped}}*, con una cantidad de *{{quantity}}*", "That item doesn't exists": "Ese artículo no existe", - "There's a new urgent ticket": "Hay un nuevo ticket urgente: [{{title}}](https://cau.verdnatura.es/WorkOrder.do?woMode=viewWO&woID={{issueId}})" + "There's a new urgent ticket": "Hay un nuevo ticket urgente: [{{title}}](https://cau.verdnatura.es/WorkOrder.do?woMode=viewWO&woID={{issueId}})", + "Compensation account is empty": "La cuenta para compensar está vacia" } \ No newline at end of file diff --git a/modules/client/back/methods/client/createReceipt.js b/modules/client/back/methods/client/createReceipt.js index 75ad02373..976ff7cf2 100644 --- a/modules/client/back/methods/client/createReceipt.js +++ b/modules/client/back/methods/client/createReceipt.js @@ -62,7 +62,10 @@ module.exports = function(Self) { const bank = await models.Bank.findById(args.bankFk); const accountingType = await models.AccountingType.findById(bank.accountingTypeFk); - if (args.compensationAccount) { + if (accountingType.code == 'compensation') { + if (!args.compensationAccount) + throw new UserError('Compensation account is empty'); + const supplierCompensation = await models.Supplier.findOne({ where: { account: args.compensationAccount @@ -92,12 +95,11 @@ module.exports = function(Self) { ], options); } else { - const description = `${clientOriginal.id} : ${clientOriginal.nickname} - ${accountingType.receiptDescription}`; + const description = `${clientOriginal.id} : ${clientOriginal.socialName} - ${accountingType.receiptDescription}`; const [xdiarioNew] = await Self.rawSql( - `SELECT xdiario_new(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ledger;`, + `SELECT xdiario_new(?, CURDATE(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ledger;`, [ null, - Date(), bank.account, clientOriginal.accountingAccount, description, @@ -114,10 +116,9 @@ module.exports = function(Self) { options); await Self.rawSql( - `SELECT xdiario_new(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`, + `SELECT xdiario_new(?, CURDATE(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`, [ xdiarioNew.ledger, - Date(), clientOriginal.accountingAccount, bank.account, description, diff --git a/modules/client/back/methods/client/specs/createReceipt.spec.js b/modules/client/back/methods/client/specs/createReceipt.spec.js index 59bf8f52a..3bd560cdd 100644 --- a/modules/client/back/methods/client/specs/createReceipt.spec.js +++ b/modules/client/back/methods/client/specs/createReceipt.spec.js @@ -38,6 +38,29 @@ describe('Client createReceipt', () => { await till.destroy(); }); + it('should throw Compensation account is empty', async() => { + const bankFk = 3; + let ctx = { + args: { + clientFk: clientFk, + payed: payed, + companyFk: companyFk, + bankFk: bankFk, + amountPaid: amountPaid, + description: description + } + }; + + try { + await app.models.Client.createReceipt(ctx); + } catch (e) { + error = e; + } + + expect(error).toBeDefined(); + expect(error.message).toEqual('Compensation account is empty'); + }); + it('should throw Invalid account if compensationAccount does not belongs to a client nor a supplier', async() => { let error; const bankFk = 3; diff --git a/modules/order/front/create/card.js b/modules/order/front/create/card.js index 315cc8255..de04484bd 100644 --- a/modules/order/front/create/card.js +++ b/modules/order/front/create/card.js @@ -37,7 +37,7 @@ class Controller extends Component { }; filter = encodeURIComponent(JSON.stringify(filter)); let query = `Clients?filter=${filter}`; - this.$http.get(query).then(res => { + this.$http.get(query).then(res=> { if (res.data) { let client = res.data[0]; let defaultAddress = client.defaultAddress; diff --git a/modules/ticket/back/methods/ticket/new.js b/modules/ticket/back/methods/ticket/new.js index 8bafe5403..cec7857bd 100644 --- a/modules/ticket/back/methods/ticket/new.js +++ b/modules/ticket/back/methods/ticket/new.js @@ -101,7 +101,7 @@ module.exports = Self => { if (!shipped && landed) { const shippedResult = await models.Agency.getShipped(landed, address.id, agencyModeId, warehouseId); - shipped = shippedResult && shippedResult.shipped; + shipped = (shippedResult && shippedResult.shipped) || landed; } if (shipped && !landed) { diff --git a/modules/ticket/back/methods/ticket/specs/new.spec.js b/modules/ticket/back/methods/ticket/specs/new.spec.js index f240ce372..671b9bffd 100644 --- a/modules/ticket/back/methods/ticket/specs/new.spec.js +++ b/modules/ticket/back/methods/ticket/specs/new.spec.js @@ -28,7 +28,7 @@ describe('ticket new()', () => { params.shipped, params.landed, params.warehouseId, - params.companyFk, + params.companyId, params.addressId ).catch(e => { error = e; @@ -53,7 +53,7 @@ describe('ticket new()', () => { params.shipped, params.landed, params.warehouseId, - params.companyFk, + params.companyId, params.addressId ).catch(response => { expect(response.message).toEqual(`This address doesn't exist`); @@ -79,7 +79,7 @@ describe('ticket new()', () => { params.shipped, params.landed, params.warehouseId, - params.companyFk, + params.companyId, params.addressId, params.agencyModeId); @@ -87,4 +87,27 @@ describe('ticket new()', () => { expect(ticket.id).toBeGreaterThan(newestTicketIdInFixtures); }); + + it('should return the set a shipped when the agency is not especified', async() => { + let params = { + clientId: 104, + landed: today, + shipped: null, + warehouseId: 2, + companyId: 442, + addressId: 4, + agencyModeId: null + }; + + ticket = await app.models.Ticket.new(ctx, + params.clientId, + params.shipped, + params.landed, + params.warehouseId, + params.companyId, + params.addressId, + params.agencyModeId); + + expect(ticket.shipped).toEqual(jasmine.any(Date)); + }); }); diff --git a/modules/ticket/front/create/card.html b/modules/ticket/front/create/card.html index 36e62d8e6..65c45d3dc 100644 --- a/modules/ticket/front/create/card.html +++ b/modules/ticket/front/create/card.html @@ -39,7 +39,7 @@ { - this._availableAgencies = res.data; - - this.agencyModeId = this.defaultAddress.agencyModeFk; + this.agencies = res.data; + const defaultAgency = this.agencies.find(agency=> { + return agency.agencyModeFk == this.defaultAddress.agencyModeFk; + }); + if (defaultAgency) + this.agencyModeId = defaultAgency.agencyModeFk; }); } }