pull request changes
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
6b51b7ddd7
commit
97f2341ae0
|
@ -1,20 +1,22 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethod('createInvoiceIn', {
|
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',
|
accessType: 'WRITE',
|
||||||
accepts: [{
|
accepts: [{
|
||||||
arg: 'rows',
|
arg: 'rows',
|
||||||
type: ['object'],
|
type: ['object'],
|
||||||
required: true,
|
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',
|
arg: 'dms',
|
||||||
type: ['object'],
|
type: ['object'],
|
||||||
required: true,
|
required: true,
|
||||||
description: 'the dms file'
|
description: 'The dms file attached'
|
||||||
}],
|
}],
|
||||||
returns: {
|
returns: {
|
||||||
|
type: 'object',
|
||||||
|
root: true
|
||||||
},
|
},
|
||||||
http: {
|
http: {
|
||||||
path: `/createInvoiceIn`,
|
path: `/createInvoiceIn`,
|
||||||
|
@ -49,7 +51,7 @@ module.exports = Self => {
|
||||||
booked: firstRow.created,
|
booked: firstRow.created,
|
||||||
operated: firstRow.created,
|
operated: firstRow.created,
|
||||||
bookEntried: firstRow.created,
|
bookEntried: firstRow.created,
|
||||||
gestdoc_id: firstDms.id
|
dmsFk: firstDms.id,
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
const expence = await models.AgencyTermConfig.findOne(null, myOptions);
|
const expence = await models.AgencyTermConfig.findOne(null, myOptions);
|
||||||
|
@ -81,7 +83,7 @@ module.exports = Self => {
|
||||||
transactionTypeSageFk: transactionTypeSage.value
|
transactionTypeSageFk: transactionTypeSage.value
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
// await Self.rawSql(`CALL invoiceInDueDay_calculate(?)`, [newInvoiceIn.id], myOptions);
|
await Self.rawSql(`CALL invoiceInDueDay_calculate(?)`, [newInvoiceIn.id], myOptions);
|
||||||
|
|
||||||
for (let agencyTerm of rows) {
|
for (let agencyTerm of rows) {
|
||||||
const route = await models.Route.findById(agencyTerm.routeFk, null, myOptions);
|
const route = await models.Route.findById(agencyTerm.routeFk, null, myOptions);
|
||||||
|
@ -91,6 +93,8 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
|
return newInvoiceIn;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
throw e;
|
throw e;
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||||
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
|
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('filter', {
|
Self.remoteMethodCtx('filter', {
|
||||||
|
@ -30,9 +29,8 @@ module.exports = Self => {
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
let stmts = [];
|
const stmts = [];
|
||||||
let stmt;
|
const stmt = new ParameterizedSQL(
|
||||||
stmt = new ParameterizedSQL(
|
|
||||||
`SELECT *
|
`SELECT *
|
||||||
FROM (
|
FROM (
|
||||||
SELECT r.id routeFk,
|
SELECT r.id routeFk,
|
||||||
|
@ -65,9 +63,9 @@ module.exports = Self => {
|
||||||
|
|
||||||
stmt.merge(conn.makeSuffix(filter));
|
stmt.merge(conn.makeSuffix(filter));
|
||||||
|
|
||||||
let agencyTerm = stmts.push(stmt) - 1;
|
const agencyTerm = stmts.push(stmt) - 1;
|
||||||
let sql = ParameterizedSQL.join(stmts, ';');
|
const sql = ParameterizedSQL.join(stmts, ';');
|
||||||
let result = await conn.executeStmt(sql, myOptions);
|
const result = await conn.executeStmt(sql, myOptions);
|
||||||
|
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
for (let agencyTerm of result)
|
for (let agencyTerm of result)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
|
// Include test when the database export is done
|
||||||
xdescribe('AgencyTerm createInvoiceIn()', () => {
|
xdescribe('AgencyTerm createInvoiceIn()', () => {
|
||||||
const rows = [
|
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 tx = await models.AgencyTerm.beginTransaction({});
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
@ -28,14 +29,12 @@ xdescribe('AgencyTerm createInvoiceIn()', () => {
|
||||||
const oldInvoiceInDueDay = await models.InvoiceInDueDay.findById(invoiceInDueDayId, null, options);
|
const oldInvoiceInDueDay = await models.InvoiceInDueDay.findById(invoiceInDueDayId, null, options);
|
||||||
const oldInvoiceInTax = await models.InvoiceInTax.findById(invoiceInTaxId, 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 [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 [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);
|
const [newInvoiceInTax] = await models.InvoiceInTax.rawSql('SELECT MAX(id) id FROM invoiceInTax', null, options);
|
||||||
|
|
||||||
conso;
|
|
||||||
|
|
||||||
expect(newInvoiceIn.id).toBeGreaterThan(oldInvoiceIn.id);
|
expect(newInvoiceIn.id).toBeGreaterThan(oldInvoiceIn.id);
|
||||||
expect(newInvoiceInDueDay.id).toBeGreaterThan(oldInvoiceInDueDay.id);
|
expect(newInvoiceInDueDay.id).toBeGreaterThan(oldInvoiceInDueDay.id);
|
||||||
expect(newInvoiceInTax.id).toBeGreaterThan(oldInvoiceInTax.id);
|
expect(newInvoiceInTax.id).toBeGreaterThan(oldInvoiceInTax.id);
|
||||||
|
|
|
@ -3,7 +3,7 @@ const models = require('vn-loopback/server/server').models;
|
||||||
describe('AgencyTerm filter()', () => {
|
describe('AgencyTerm filter()', () => {
|
||||||
const authUserId = 9;
|
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({});
|
const tx = await models.AgencyTerm.beginTransaction({});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -62,10 +62,10 @@ describe('AgencyTerm', () => {
|
||||||
|
|
||||||
describe('setDefaultParams()', () => {
|
describe('setDefaultParams()', () => {
|
||||||
it('should perform a GET query and define the dms property on controller', () => {
|
it('should perform a GET query and define the dms property on controller', () => {
|
||||||
const params2 = {filter: {
|
const params = {filter: {
|
||||||
where: {code: 'invoiceIn'}
|
where: {code: 'invoiceIn'}
|
||||||
}};
|
}};
|
||||||
let serializedParams = $httpParamSerializer(params2);
|
const serializedParams = $httpParamSerializer(params);
|
||||||
$httpBackend.expect('GET', `DmsTypes/findOne?${serializedParams}`).respond({id: 1, code: 'invoiceIn'});
|
$httpBackend.expect('GET', `DmsTypes/findOne?${serializedParams}`).respond({id: 1, code: 'invoiceIn'});
|
||||||
controller.params = {supplierName: 'Plants SL'};
|
controller.params = {supplierName: 'Plants SL'};
|
||||||
controller.setDefaultParams();
|
controller.setDefaultParams();
|
||||||
|
|
|
@ -41,26 +41,20 @@ class Controller extends Section {
|
||||||
|
|
||||||
exprBuilder(param, value) {
|
exprBuilder(param, value) {
|
||||||
switch (param) {
|
switch (param) {
|
||||||
|
case 'agencyFk':
|
||||||
|
return {'a.agencyModeName': value};
|
||||||
|
case 'supplierFk':
|
||||||
|
return {'a.supplierName': value};
|
||||||
case 'routeFk':
|
case 'routeFk':
|
||||||
return {'a.routeFk': value};
|
return {'a.routeFk': value};
|
||||||
case 'created':
|
case 'created':
|
||||||
return {'a.created': value};
|
|
||||||
case 'agencyFk':
|
|
||||||
return {'a.agencyModeName': value};
|
|
||||||
case 'agencyAgreement':
|
case 'agencyAgreement':
|
||||||
return {'a.agencyAgreement': value};
|
|
||||||
case 'packages':
|
case 'packages':
|
||||||
return {'a.packages': value};
|
|
||||||
case 'm3':
|
case 'm3':
|
||||||
return {'a.m3': value};
|
|
||||||
case 'kmTotal':
|
case 'kmTotal':
|
||||||
return {'a.kmTotal': value};
|
|
||||||
case 'price':
|
case 'price':
|
||||||
return {'a.price': value};
|
|
||||||
case 'invoiceInFk':
|
case 'invoiceInFk':
|
||||||
return {'a.invoiceInFk': value};
|
return {[`a.${param}`]: value};
|
||||||
case 'supplierFk':
|
|
||||||
return {'a.supplierName': value};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ describe('AgencyTerm', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('preview()', () => {
|
describe('preview()', () => {
|
||||||
it('should show the dialog summary', () => {
|
it('should show the summary dialog', () => {
|
||||||
controller.$.summary = {show: () => {}};
|
controller.$.summary = {show: () => {}};
|
||||||
jest.spyOn(controller.$.summary, 'show');
|
jest.spyOn(controller.$.summary, 'show');
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ describe('AgencyTerm', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('createInvoiceIn()', () => {
|
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');
|
jest.spyOn(controller.vnApp, 'showError');
|
||||||
const data = controller.$.model.data;
|
const data = controller.$.model.data;
|
||||||
data[0].checked = true;
|
data[0].checked = true;
|
||||||
|
@ -74,7 +74,7 @@ describe('AgencyTerm', () => {
|
||||||
expect(controller.vnApp.showError).toHaveBeenCalled();
|
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');
|
jest.spyOn(controller.$state, 'go');
|
||||||
const data = controller.$.model.data;
|
const data = controller.$.model.data;
|
||||||
data[0].checked = true;
|
data[0].checked = true;
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
picture: Foto
|
|
||||||
Buy requests: Peticiones de compra
|
|
||||||
Agency route: Agencia ruta
|
Agency route: Agencia ruta
|
||||||
Agency Agreement: Agencia acuerdo
|
Agency Agreement: Agencia acuerdo
|
||||||
Autonomous: Autónomos
|
Autonomous: Autónomos
|
||||||
|
|
Loading…
Reference in New Issue