Merge pull request 'test -> dev' (!1481) from test-to-dev into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #1481
Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
Alexandre Riera 2023-04-25 09:36:03 +00:00
commit f2bef8dcf6
19 changed files with 135 additions and 116 deletions

View File

@ -0,0 +1,3 @@
UPDATE `salix`.`ACL`
SET model = 'InvoiceOut'
WHERE property IN ('negativeBases', 'negativeBasesCsv');

View File

@ -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() => {

View File

@ -156,6 +156,18 @@
"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",
"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",
"Added observation": "Added observation",
"Comment added to client": "Comment added to client"
}

View File

@ -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"
}

View File

@ -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"`
];
};
};

View File

@ -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);
};

View File

@ -15,4 +15,3 @@ import './create';
import './log';
import './serial';
import './serial-search-panel';
import './negative-bases';

View File

@ -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

View File

@ -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",

View File

@ -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];
};

View File

@ -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"`
];
};
};

View File

@ -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;

View File

@ -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);
};

View File

@ -10,3 +10,4 @@ import './descriptor-popover';
import './descriptor-menu';
import './index/manual';
import './global-invoicing';
import './negative-bases';

View File

@ -1,6 +1,6 @@
<vn-crud-model
vn-id="model"
url="InvoiceIns/negativeBases"
url="InvoiceOuts/negativeBases"
auto-load="true"
params="$ctrl.params"
limit="20">
@ -43,7 +43,7 @@
<span translate>Country</span>
</th>
<th field="clientId">
<span translate>Id Client</span>
<span translate>Client id</span>
</th>
<th field="clientSocialName">
<span translate>Client</span>
@ -55,7 +55,7 @@
<span translate>Base</span>
</th>
<th field="ticketFk">
<span translate>Id Ticket</span>
<span translate>Ticket id</span>
</th>
<th field="isActive">
<span translate>Active</span>

View File

@ -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
});

View File

@ -0,0 +1,2 @@
Has To Invoice: Facturar
Download as CSV: Descargar como CSV

View File

@ -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"
]
}
]
}