From b3a10698afe7563c610527c3d1c6c167eddb34d8 Mon Sep 17 00:00:00 2001 From: alexandre Date: Fri, 21 Apr 2023 08:20:38 +0200 Subject: [PATCH 1/2] hotfix negativeBases --- db/changes/231402/00-negativeBases.sql | 3 + loopback/locale/en.json | 16 ++++- loopback/locale/es.json | 18 ++++- .../methods/invoice-in/negativeBasesCsv.js | 53 --------------- modules/invoiceIn/back/models/invoice-in.js | 2 - modules/invoiceIn/front/index.js | 1 - .../front/negative-bases/locale/es.yml | 14 ---- modules/invoiceIn/front/routes.json | 12 +--- .../back/methods/invoiceOut}/negativeBases.js | 10 +-- .../methods/invoiceOut/negativeBasesCsv.js | 68 +++++++++++++++++++ .../invoiceOut}/specs/negativeBases.spec.js | 13 ++-- modules/invoiceOut/back/models/invoice-out.js | 2 + modules/invoiceOut/front/index.js | 1 + .../front/negative-bases/index.html | 6 +- .../front/negative-bases/index.js | 13 +--- .../front/negative-bases/locale/es.yml | 2 + .../front/negative-bases/style.scss | 0 modules/invoiceOut/front/routes.json | 15 +++- 18 files changed, 134 insertions(+), 115 deletions(-) create mode 100644 db/changes/231402/00-negativeBases.sql delete mode 100644 modules/invoiceIn/back/methods/invoice-in/negativeBasesCsv.js delete mode 100644 modules/invoiceIn/front/negative-bases/locale/es.yml rename modules/{invoiceIn/back/methods/invoice-in => invoiceOut/back/methods/invoiceOut}/negativeBases.js (93%) create mode 100644 modules/invoiceOut/back/methods/invoiceOut/negativeBasesCsv.js rename modules/{invoiceIn/back/methods/invoice-in => invoiceOut/back/methods/invoiceOut}/specs/negativeBases.spec.js (71%) rename modules/{invoiceIn => invoiceOut}/front/negative-bases/index.html (96%) rename modules/{invoiceIn => invoiceOut}/front/negative-bases/index.js (79%) create mode 100644 modules/invoiceOut/front/negative-bases/locale/es.yml rename modules/{invoiceIn => invoiceOut}/front/negative-bases/style.scss (100%) diff --git a/db/changes/231402/00-negativeBases.sql b/db/changes/231402/00-negativeBases.sql new file mode 100644 index 000000000..f7d6cdfb0 --- /dev/null +++ b/db/changes/231402/00-negativeBases.sql @@ -0,0 +1,3 @@ +UPDATE `salix`.`ACL` + SET model = 'InvoiceOut' + WHERE property IN ('negativeBases', 'negativeBasesCsv'); diff --git a/loopback/locale/en.json b/loopback/locale/en.json index c3c8d234d..8bf536cd4 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -155,5 +155,17 @@ "Warehouse inventory not set": "Almacén inventario no está establecido", "Component cost not set": "Componente coste no está estabecido", "Tickets with associated refunds can't be deleted. This ticket is associated with refund Nº 2": "Tickets with associated refunds can't be deleted. This ticket is associated with refund Nº 2", - "Description cannot be blank": "Description cannot be blank" -} \ No newline at end of file + "Description cannot be blank": "Description cannot be blank", + "company": "Company", + "country": "Country", + "clientId": "Id client", + "clientSocialName": "Client", + "amount": "Amount", + "taxableBase": "Taxable base", + "ticketFk": "Id ticket", + "isActive": "Active", + "hasToInvoice": "Invoice", + "isTaxDataChecked": "Data checked", + "comercialId": "Id Comercial", + "comercialName": "Comercial" +} diff --git a/loopback/locale/es.json b/loopback/locale/es.json index d52eacff6..3ef3c4a22 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -275,7 +275,19 @@ "Collection does not exist": "La colección no existe", "Cannot obtain exclusive lock": "No se puede obtener un bloqueo exclusivo", "Insert a date range": "Inserte un rango de fechas", - "Added observation": "{{user}} añadió esta observacion: {{text}}", - "Comment added to client": "Observación añadida al cliente {{clientFk}}", - "Cannot create a new claimBeginning from a different ticket": "No se puede crear una línea de reclamación de un ticket diferente al origen" + "Added observation": "{{user}} añadió esta observacion: {{text}}", + "Comment added to client": "Observación añadida al cliente {{clientFk}}", + "Cannot create a new claimBeginning from a different ticket": "No se puede crear una línea de reclamación de un ticket diferente al origen", + "company": "Compañía", + "country": "País", + "clientId": "Id cliente", + "clientSocialName": "Cliente", + "amount": "Importe", + "taxableBase": "Base", + "ticketFk": "Id ticket", + "isActive": "Activo", + "hasToInvoice": "Facturar", + "isTaxDataChecked": "Datos comprobados", + "comercialId": "Id comercial", + "comercialName": "Comercial" } diff --git a/modules/invoiceIn/back/methods/invoice-in/negativeBasesCsv.js b/modules/invoiceIn/back/methods/invoice-in/negativeBasesCsv.js deleted file mode 100644 index 963151b7d..000000000 --- a/modules/invoiceIn/back/methods/invoice-in/negativeBasesCsv.js +++ /dev/null @@ -1,53 +0,0 @@ -const {toCSV} = require('vn-loopback/util/csv'); - -module.exports = Self => { - Self.remoteMethodCtx('negativeBasesCsv', { - description: 'Returns the negative bases as .csv', - accessType: 'READ', - accepts: [{ - arg: 'negativeBases', - type: ['object'], - required: true - }, - { - arg: 'from', - type: 'date', - description: 'From date' - }, - { - arg: 'to', - type: 'date', - description: 'To date' - }], - returns: [ - { - arg: 'body', - type: 'file', - root: true - }, { - arg: 'Content-Type', - type: 'String', - http: {target: 'header'} - }, { - arg: 'Content-Disposition', - type: 'String', - http: {target: 'header'} - } - ], - http: { - path: '/negativeBasesCsv', - verb: 'GET' - } - }); - - Self.negativeBasesCsv = async ctx => { - const args = ctx.args; - const content = toCSV(args.negativeBases); - - return [ - content, - 'text/csv', - `attachment; filename="negative-bases-${new Date(args.from).toLocaleDateString()}-${new Date(args.to).toLocaleDateString()}.csv"` - ]; - }; -}; diff --git a/modules/invoiceIn/back/models/invoice-in.js b/modules/invoiceIn/back/models/invoice-in.js index 167f2ac34..51905ccb8 100644 --- a/modules/invoiceIn/back/models/invoice-in.js +++ b/modules/invoiceIn/back/models/invoice-in.js @@ -7,6 +7,4 @@ module.exports = Self => { require('../methods/invoice-in/invoiceInPdf')(Self); require('../methods/invoice-in/invoiceInEmail')(Self); require('../methods/invoice-in/getSerial')(Self); - require('../methods/invoice-in/negativeBases')(Self); - require('../methods/invoice-in/negativeBasesCsv')(Self); }; diff --git a/modules/invoiceIn/front/index.js b/modules/invoiceIn/front/index.js index c0374e996..e257cfee3 100644 --- a/modules/invoiceIn/front/index.js +++ b/modules/invoiceIn/front/index.js @@ -15,4 +15,3 @@ import './create'; import './log'; import './serial'; import './serial-search-panel'; -import './negative-bases'; diff --git a/modules/invoiceIn/front/negative-bases/locale/es.yml b/modules/invoiceIn/front/negative-bases/locale/es.yml deleted file mode 100644 index 9095eee22..000000000 --- a/modules/invoiceIn/front/negative-bases/locale/es.yml +++ /dev/null @@ -1,14 +0,0 @@ -Has To Invoice: Facturar -Download as CSV: Descargar como CSV -company: Compañía -country: País -clientId: Id Cliente -clientSocialName: Cliente -amount: Importe -taxableBase: Base -ticketFk: Id Ticket -isActive: Activo -hasToInvoice: Facturar -isTaxDataChecked: Datos comprobados -comercialId: Id Comercial -comercialName: Comercial diff --git a/modules/invoiceIn/front/routes.json b/modules/invoiceIn/front/routes.json index 40d061d1b..6f4d3d1a3 100644 --- a/modules/invoiceIn/front/routes.json +++ b/modules/invoiceIn/front/routes.json @@ -10,8 +10,7 @@ "menus": { "main": [ { "state": "invoiceIn.index", "icon": "icon-invoice-in"}, - { "state": "invoiceIn.serial", "icon": "icon-invoice-in"}, - { "state": "invoiceIn.negative-bases", "icon": "icon-ticket"} + { "state": "invoiceIn.serial", "icon": "icon-invoice-in"} ], "card": [ { @@ -53,15 +52,6 @@ "administrative" ] }, - { - "url": "/negative-bases", - "state": "invoiceIn.negative-bases", - "component": "vn-negative-bases", - "description": "Negative bases", - "acl": [ - "administrative" - ] - }, { "url": "/serial", "state": "invoiceIn.serial", diff --git a/modules/invoiceIn/back/methods/invoice-in/negativeBases.js b/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js similarity index 93% rename from modules/invoiceIn/back/methods/invoice-in/negativeBases.js rename to modules/invoiceOut/back/methods/invoiceOut/negativeBases.js index 4c9a8984b..ae9c404af 100644 --- a/modules/invoiceIn/back/methods/invoice-in/negativeBases.js +++ b/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js @@ -96,16 +96,18 @@ module.exports = Self => { SELECT f.* FROM tmp.filter f`); - stmt.merge(conn.makeWhere(args.filter.where)); - stmt.merge(conn.makeOrderBy(args.filter.order)); - stmt.merge(conn.makeLimit(args.filter)); + if (args.filter) { + stmt.merge(conn.makeWhere(args.filter.where)); + stmt.merge(conn.makeOrderBy(args.filter.order)); + stmt.merge(conn.makeLimit(args.filter)); + } const negativeBasesIndex = stmts.push(stmt) - 1; stmts.push(`DROP TEMPORARY TABLE tmp.filter, tmp.ticket, tmp.ticketTax, tmp.ticketAmount`); const sql = ParameterizedSQL.join(stmts, ';'); - const result = await conn.executeStmt(sql, myOptions); + const result = await conn.executeStmt(sql); return negativeBasesIndex === 0 ? result : result[negativeBasesIndex]; }; diff --git a/modules/invoiceOut/back/methods/invoiceOut/negativeBasesCsv.js b/modules/invoiceOut/back/methods/invoiceOut/negativeBasesCsv.js new file mode 100644 index 000000000..d70a8fce5 --- /dev/null +++ b/modules/invoiceOut/back/methods/invoiceOut/negativeBasesCsv.js @@ -0,0 +1,68 @@ +const {toCSV} = require('vn-loopback/util/csv'); + +module.exports = Self => { + Self.remoteMethodCtx('negativeBasesCsv', { + description: 'Returns the negative bases as .csv', + accessType: 'READ', + accepts: [ + { + arg: 'from', + type: 'date', + description: 'From date', + required: true + }, + { + arg: 'to', + type: 'date', + description: 'To date', + required: true + }], + returns: [ + { + arg: 'body', + type: 'file', + root: true + }, { + arg: 'Content-Type', + type: 'String', + http: {target: 'header'} + }, { + arg: 'Content-Disposition', + type: 'String', + http: {target: 'header'} + } + ], + http: { + path: '/negativeBasesCsv', + verb: 'GET' + } + }); + + Self.negativeBasesCsv = async(ctx, options) => { + const $t = ctx.req.__; // $translate + const args = ctx.args; + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + const negativeBases = await Self.app.models.InvoiceOut.negativeBases(ctx, myOptions); + const locatedFields = []; + negativeBases.forEach(element => { + locatedFields.push(Object.keys(element).map(key => { + return {newName: $t(key), value: element[key]}; + }).filter(item => item !== null) + .reduce((result, item) => { + result[item.newName] = item.value; + return result; + }, {})); + }); + const content = toCSV(locatedFields); + + return [ + content, + 'text/csv', + `attachment; filename="negative-bases-${new Date(args.from).toLocaleDateString()}-${new Date(args.to).toLocaleDateString()}.csv"` + ]; + }; +}; diff --git a/modules/invoiceIn/back/methods/invoice-in/specs/negativeBases.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/negativeBases.spec.js similarity index 71% rename from modules/invoiceIn/back/methods/invoice-in/specs/negativeBases.spec.js rename to modules/invoiceOut/back/methods/invoiceOut/specs/negativeBases.spec.js index a5c6e3102..1164e894b 100644 --- a/modules/invoiceIn/back/methods/invoice-in/specs/negativeBases.spec.js +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/negativeBases.spec.js @@ -1,19 +1,18 @@ const models = require('vn-loopback/server/server').models; -describe('invoiceIn negativeBases()', () => { +describe('invoiceOut negativeBases()', () => { it('should return all negative bases in a date range', async() => { - const tx = await models.InvoiceIn.beginTransaction({}); + const tx = await models.InvoiceOut.beginTransaction({}); const options = {transaction: tx}; const ctx = { args: { from: new Date().setMonth(new Date().getMonth() - 12), - to: new Date(), - filter: {} + to: new Date() } }; try { - const result = await models.InvoiceIn.negativeBases(ctx, options); + const result = await models.InvoiceOut.negativeBases(ctx, options); expect(result.length).toBeGreaterThan(0); @@ -26,7 +25,7 @@ describe('invoiceIn negativeBases()', () => { it('should throw an error if a date range is not in args', async() => { let error; - const tx = await models.InvoiceIn.beginTransaction({}); + const tx = await models.InvoiceOut.beginTransaction({}); const options = {transaction: tx}; const ctx = { args: { @@ -35,7 +34,7 @@ describe('invoiceIn negativeBases()', () => { }; try { - await models.InvoiceIn.negativeBases(ctx, options); + await models.InvoiceOut.negativeBases(ctx, options); await tx.rollback(); } catch (e) { error = e; diff --git a/modules/invoiceOut/back/models/invoice-out.js b/modules/invoiceOut/back/models/invoice-out.js index 6205abe7b..5fcef7744 100644 --- a/modules/invoiceOut/back/models/invoice-out.js +++ b/modules/invoiceOut/back/models/invoice-out.js @@ -17,4 +17,6 @@ module.exports = Self => { require('../methods/invoiceOut/invoiceCsvEmail')(Self); require('../methods/invoiceOut/invoiceOutPdf')(Self); require('../methods/invoiceOut/getInvoiceDate')(Self); + require('../methods/invoiceOut/negativeBases')(Self); + require('../methods/invoiceOut/negativeBasesCsv')(Self); }; diff --git a/modules/invoiceOut/front/index.js b/modules/invoiceOut/front/index.js index f7cebc0d0..723e3be5a 100644 --- a/modules/invoiceOut/front/index.js +++ b/modules/invoiceOut/front/index.js @@ -10,3 +10,4 @@ import './descriptor-popover'; import './descriptor-menu'; import './index/manual'; import './global-invoicing'; +import './negative-bases'; diff --git a/modules/invoiceIn/front/negative-bases/index.html b/modules/invoiceOut/front/negative-bases/index.html similarity index 96% rename from modules/invoiceIn/front/negative-bases/index.html rename to modules/invoiceOut/front/negative-bases/index.html index 5da8e7aad..26f67c7d4 100644 --- a/modules/invoiceIn/front/negative-bases/index.html +++ b/modules/invoiceOut/front/negative-bases/index.html @@ -1,6 +1,6 @@ @@ -43,7 +43,7 @@ Country - Id Client + Client id Client @@ -55,7 +55,7 @@ Base - Id Ticket + Ticket id Active diff --git a/modules/invoiceIn/front/negative-bases/index.js b/modules/invoiceOut/front/negative-bases/index.js similarity index 79% rename from modules/invoiceIn/front/negative-bases/index.js rename to modules/invoiceOut/front/negative-bases/index.js index 0f6f04692..1a838507c 100644 --- a/modules/invoiceIn/front/negative-bases/index.js +++ b/modules/invoiceOut/front/negative-bases/index.js @@ -58,18 +58,7 @@ export default class Controller extends Section { } downloadCSV() { - const data = []; - this.$.model._orgData.forEach(element => { - data.push(Object.keys(element).map(key => { - return {newName: this.$t(key), value: element[key]}; - }).filter(item => item !== null) - .reduce((result, item) => { - result[item.newName] = item.value; - return result; - }, {})); - }); - this.vnReport.show('InvoiceIns/negativeBasesCsv', { - negativeBases: data, + this.vnReport.show('InvoiceOuts/negativeBasesCsv', { from: this.params.from, to: this.params.to }); diff --git a/modules/invoiceOut/front/negative-bases/locale/es.yml b/modules/invoiceOut/front/negative-bases/locale/es.yml new file mode 100644 index 000000000..dd3432592 --- /dev/null +++ b/modules/invoiceOut/front/negative-bases/locale/es.yml @@ -0,0 +1,2 @@ +Has To Invoice: Facturar +Download as CSV: Descargar como CSV diff --git a/modules/invoiceIn/front/negative-bases/style.scss b/modules/invoiceOut/front/negative-bases/style.scss similarity index 100% rename from modules/invoiceIn/front/negative-bases/style.scss rename to modules/invoiceOut/front/negative-bases/style.scss diff --git a/modules/invoiceOut/front/routes.json b/modules/invoiceOut/front/routes.json index c396a5334..7965a7e99 100644 --- a/modules/invoiceOut/front/routes.json +++ b/modules/invoiceOut/front/routes.json @@ -7,8 +7,8 @@ "menus": { "main": [ {"state": "invoiceOut.index", "icon": "icon-invoice-out"}, - {"state": "invoiceOut.global-invoicing", "icon": "contact_support"} - + {"state": "invoiceOut.global-invoicing", "icon": "contact_support"}, + { "state": "invoiceOut.negative-bases", "icon": "icon-ticket"} ] }, "routes": [ @@ -46,6 +46,15 @@ "state": "invoiceOut.card", "abstract": true, "component": "vn-invoice-out-card" - } + }, + { + "url": "/negative-bases", + "state": "invoiceOut.negative-bases", + "component": "vn-negative-bases", + "description": "Negative bases", + "acl": [ + "administrative" + ] + }, ] } From af1ad7e08c7ca51bc65c017f1e5c973f44bcb199 Mon Sep 17 00:00:00 2001 From: alexandre Date: Fri, 21 Apr 2023 09:47:34 +0200 Subject: [PATCH 2/2] fixed e2e --- .../05_negative_bases.spec.js | 8 ++++---- modules/invoiceOut/front/routes.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) rename e2e/paths/{09-invoice-in => 09-invoice-out}/05_negative_bases.spec.js (70%) diff --git a/e2e/paths/09-invoice-in/05_negative_bases.spec.js b/e2e/paths/09-invoice-out/05_negative_bases.spec.js similarity index 70% rename from e2e/paths/09-invoice-in/05_negative_bases.spec.js rename to e2e/paths/09-invoice-out/05_negative_bases.spec.js index 4c9fe651f..43ced2115 100644 --- a/e2e/paths/09-invoice-in/05_negative_bases.spec.js +++ b/e2e/paths/09-invoice-out/05_negative_bases.spec.js @@ -1,6 +1,6 @@ import getBrowser from '../../helpers/puppeteer'; -describe('InvoiceIn negative bases path', () => { +describe('InvoiceOut negative bases path', () => { let browser; let page; const httpRequests = []; @@ -9,11 +9,11 @@ describe('InvoiceIn negative bases path', () => { browser = await getBrowser(); page = browser.page; page.on('request', req => { - if (req.url().includes(`InvoiceIns/negativeBases`)) + if (req.url().includes(`InvoiceOuts/negativeBases`)) httpRequests.push(req.url()); }); - await page.loginAndModule('administrative', 'invoiceIn'); - await page.accessToSection('invoiceIn.negative-bases'); + await page.loginAndModule('administrative', 'invoiceOut'); + await page.accessToSection('invoiceOut.negative-bases'); }); afterAll(async() => { diff --git a/modules/invoiceOut/front/routes.json b/modules/invoiceOut/front/routes.json index 7965a7e99..f7f589b01 100644 --- a/modules/invoiceOut/front/routes.json +++ b/modules/invoiceOut/front/routes.json @@ -55,6 +55,6 @@ "acl": [ "administrative" ] - }, + } ] }