pull request changes
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Vicent Llopis 2022-03-08 13:42:44 +01:00
parent 6b51b7ddd7
commit 97f2341ae0
11 changed files with 28 additions and 35 deletions

View File

@ -1,20 +1,22 @@
module.exports = Self => {
Self.remoteMethod('createInvoiceIn', {
description: 'create a invoce in from one or more agency terms',
description: 'Creates an invoiceIn from one or more agency terms',
accessType: 'WRITE',
accepts: [{
arg: 'rows',
type: ['object'],
required: true,
description: `the rows from which the invoice in will be created`,
description: `The rows from which the invoiceIn will be created`,
},
{
arg: 'dms',
type: ['object'],
required: true,
description: 'the dms file'
description: 'The dms file attached'
}],
returns: {
type: 'object',
root: true
},
http: {
path: `/createInvoiceIn`,
@ -49,7 +51,7 @@ module.exports = Self => {
booked: firstRow.created,
operated: firstRow.created,
bookEntried: firstRow.created,
gestdoc_id: firstDms.id
dmsFk: firstDms.id,
}, myOptions);
const expence = await models.AgencyTermConfig.findOne(null, myOptions);
@ -81,7 +83,7 @@ module.exports = Self => {
transactionTypeSageFk: transactionTypeSage.value
}, myOptions);
// await Self.rawSql(`CALL invoiceInDueDay_calculate(?)`, [newInvoiceIn.id], myOptions);
await Self.rawSql(`CALL invoiceInDueDay_calculate(?)`, [newInvoiceIn.id], myOptions);
for (let agencyTerm of rows) {
const route = await models.Route.findById(agencyTerm.routeFk, null, myOptions);
@ -91,6 +93,8 @@ module.exports = Self => {
}
if (tx) await tx.commit();
return newInvoiceIn;
} catch (e) {
if (tx) await tx.rollback();
throw e;

View File

@ -1,5 +1,4 @@
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
module.exports = Self => {
Self.remoteMethodCtx('filter', {
@ -30,9 +29,8 @@ module.exports = Self => {
if (typeof options == 'object')
Object.assign(myOptions, options);
let stmts = [];
let stmt;
stmt = new ParameterizedSQL(
const stmts = [];
const stmt = new ParameterizedSQL(
`SELECT *
FROM (
SELECT r.id routeFk,
@ -65,9 +63,9 @@ module.exports = Self => {
stmt.merge(conn.makeSuffix(filter));
let agencyTerm = stmts.push(stmt) - 1;
let sql = ParameterizedSQL.join(stmts, ';');
let result = await conn.executeStmt(sql, myOptions);
const agencyTerm = stmts.push(stmt) - 1;
const sql = ParameterizedSQL.join(stmts, ';');
const result = await conn.executeStmt(sql, myOptions);
const models = Self.app.models;
for (let agencyTerm of result)

View File

@ -1,5 +1,6 @@
const models = require('vn-loopback/server/server').models;
// Include test when the database export is done
xdescribe('AgencyTerm createInvoiceIn()', () => {
const rows = [
{
@ -15,7 +16,7 @@ xdescribe('AgencyTerm createInvoiceIn()', () => {
}
];
it('should make a invoice in', async() => {
it('should make an invoiceIn', async() => {
const tx = await models.AgencyTerm.beginTransaction({});
const options = {transaction: tx};
@ -28,14 +29,12 @@ xdescribe('AgencyTerm createInvoiceIn()', () => {
const oldInvoiceInDueDay = await models.InvoiceInDueDay.findById(invoiceInDueDayId, null, options);
const oldInvoiceInTax = await models.InvoiceInTax.findById(invoiceInTaxId, null, options);
// await models.AgencyTerm.createInvoiceIn(rows, dms, options);
await models.AgencyTerm.createInvoiceIn(rows, dms, options);
const [newInvoiceIn] = await models.InvoiceIn.rawSql('SELECT MAX(id) id FROM invoiceIn', null, options);
const [newInvoiceInDueDay] = await models.InvoiceInDueDay.rawSql('SELECT MAX(id) id FROM invoiceInDueDay', null, options);
const [newInvoiceInTax] = await models.InvoiceInTax.rawSql('SELECT MAX(id) id FROM invoiceInTax', null, options);
conso;
expect(newInvoiceIn.id).toBeGreaterThan(oldInvoiceIn.id);
expect(newInvoiceInDueDay.id).toBeGreaterThan(oldInvoiceInDueDay.id);
expect(newInvoiceInTax.id).toBeGreaterThan(oldInvoiceInTax.id);

View File

@ -3,7 +3,7 @@ const models = require('vn-loopback/server/server').models;
describe('AgencyTerm filter()', () => {
const authUserId = 9;
it('should all return the tickets matching the filter', async() => {
it('should return all the tickets matching the filter', async() => {
const tx = await models.AgencyTerm.beginTransaction({});
try {

View File

@ -62,10 +62,10 @@ describe('AgencyTerm', () => {
describe('setDefaultParams()', () => {
it('should perform a GET query and define the dms property on controller', () => {
const params2 = {filter: {
const params = {filter: {
where: {code: 'invoiceIn'}
}};
let serializedParams = $httpParamSerializer(params2);
const serializedParams = $httpParamSerializer(params);
$httpBackend.expect('GET', `DmsTypes/findOne?${serializedParams}`).respond({id: 1, code: 'invoiceIn'});
controller.params = {supplierName: 'Plants SL'};
controller.setDefaultParams();

View File

@ -41,26 +41,20 @@ class Controller extends Section {
exprBuilder(param, value) {
switch (param) {
case 'agencyFk':
return {'a.agencyModeName': value};
case 'supplierFk':
return {'a.supplierName': value};
case 'routeFk':
return {'a.routeFk': value};
case 'created':
return {'a.created': value};
case 'agencyFk':
return {'a.agencyModeName': value};
case 'agencyAgreement':
return {'a.agencyAgreement': value};
case 'packages':
return {'a.packages': value};
case 'm3':
return {'a.m3': value};
case 'kmTotal':
return {'a.kmTotal': value};
case 'price':
return {'a.price': value};
case 'invoiceInFk':
return {'a.invoiceInFk': value};
case 'supplierFk':
return {'a.supplierName': value};
return {[`a.${param}`]: value};
}
}

View File

@ -45,7 +45,7 @@ describe('AgencyTerm', () => {
});
describe('preview()', () => {
it('should show the dialog summary', () => {
it('should show the summary dialog', () => {
controller.$.summary = {show: () => {}};
jest.spyOn(controller.$.summary, 'show');
@ -63,7 +63,7 @@ describe('AgencyTerm', () => {
});
describe('createInvoiceIn()', () => {
it('should throw an error if are checked more than one autonomous', () => {
it('should throw an error if more than one autonomous are checked', () => {
jest.spyOn(controller.vnApp, 'showError');
const data = controller.$.model.data;
data[0].checked = true;
@ -74,7 +74,7 @@ describe('AgencyTerm', () => {
expect(controller.vnApp.showError).toHaveBeenCalled();
});
it('should call the function go() on $state to go to the file managment', () => {
it('should call the function go() on $state to go to the file management', () => {
jest.spyOn(controller.$state, 'go');
const data = controller.$.model.data;
data[0].checked = true;

View File

@ -1,5 +1,3 @@
picture: Foto
Buy requests: Peticiones de compra
Agency route: Agencia ruta
Agency Agreement: Agencia acuerdo
Autonomous: Autónomos