refs #6915 test_master24_8 #2067

Merged
alexm merged 561 commits from test_master24_8 into master 2024-02-22 07:31:34 +00:00
3 changed files with 18 additions and 2 deletions
Showing only changes of commit e33861a80d - Show all commits

View File

@ -1,4 +1,3 @@
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
const buildFilter = require('vn-loopback/util/filter').buildFilter; const buildFilter = require('vn-loopback/util/filter').buildFilter;
const mergeFilters = require('vn-loopback/util/filter').mergeFilters; const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
@ -80,6 +79,11 @@ module.exports = Self => {
type: 'boolean', type: 'boolean',
description: 'Whether the invoice is booked or not', description: 'Whether the invoice is booked or not',
}, },
{
arg: 'correctedFk',
type: 'number',
description: 'The corrected invoice',
}
], ],
returns: { returns: {
type: ['object'], type: ['object'],
@ -93,6 +97,7 @@ module.exports = Self => {
Self.filter = async(ctx, filter, options) => { Self.filter = async(ctx, filter, options) => {
const conn = Self.dataSource.connector; const conn = Self.dataSource.connector;
const models = Self.app.models;
const args = ctx.args; const args = ctx.args;
const myOptions = {}; const myOptions = {};
@ -105,6 +110,14 @@ module.exports = Self => {
dateTo.setHours(23, 59, 0, 0); dateTo.setHours(23, 59, 0, 0);
} }
let correctings;
if (args.correctedFk) {
correctings = await models.InvoiceInCorrection.find({
fields: ['correctingFk'],
where: {correctedFk: args.correctedFk}
});
}
const where = buildFilter(ctx.args, (param, value) => { const where = buildFilter(ctx.args, (param, value) => {
switch (param) { switch (param) {
case 'search': case 'search':
@ -128,6 +141,8 @@ module.exports = Self => {
return {[`ii.${param}`]: value}; return {[`ii.${param}`]: value};
case 'awbCode': case 'awbCode':
return {'sub.code': value}; return {'sub.code': value};
case 'correctedFk':
return {'ii.id': {inq: correctings.map(x => x.correctingFk)}};
} }
}); });
@ -186,6 +201,7 @@ module.exports = Self => {
const itemsIndex = stmts.push(stmt) - 1; const itemsIndex = stmts.push(stmt) - 1;
const sql = ParameterizedSQL.join(stmts, ';'); const sql = ParameterizedSQL.join(stmts, ';');
console.log(sql);
const result = await conn.executeStmt(sql, myOptions); const result = await conn.executeStmt(sql, myOptions);
return itemsIndex === 0 ? result : result[itemsIndex]; return itemsIndex === 0 ? result : result[itemsIndex];

View File

@ -28,7 +28,7 @@
"model": "InvoiceCorrectionType", "model": "InvoiceCorrectionType",
"foreignKey": "invoiceCorrectionTypeFk" "foreignKey": "invoiceCorrectionTypeFk"
}, },
"siiTypeInvoiceOutFk": { "siiTypeInvoiceOut": {
"type": "belongsTo", "type": "belongsTo",
"model": "SiiTypeInvoiceOut", "model": "SiiTypeInvoiceOut",
"foreignKey": "siiTypeInvoiceOutFk" "foreignKey": "siiTypeInvoiceOutFk"