Merge pull request 'feat: refs #7235 add serialType parameter to getInvoiceDate and implement corresponding tests' (!3306) from 7235-InvoiceOut into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #3306 Reviewed-by: Alex Moreno <alexm@verdnatura.es> Reviewed-by: Carlos Andrés <carlosap@verdnatura.es>
This commit is contained in:
commit
6c2d7641f5
|
@ -29,14 +29,14 @@ module.exports = Self => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
let tx;
|
let tx;
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
if (!myOptions.transaction) {
|
if (!myOptions.transaction) {
|
||||||
tx = await Self.beginTransaction({});
|
tx = await Self.beginTransaction({});
|
||||||
myOptions.transaction = tx;
|
myOptions.transaction = tx;
|
||||||
};
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const user = await models.VnUser.findOne({
|
const user = await models.VnUser.findOne({
|
||||||
|
|
|
@ -7,7 +7,12 @@ module.exports = Self => {
|
||||||
arg: 'companyFk',
|
arg: 'companyFk',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
required: true
|
required: true
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
arg: 'serialType',
|
||||||
|
type: 'string',
|
||||||
|
required: true
|
||||||
|
},
|
||||||
],
|
],
|
||||||
returns: {
|
returns: {
|
||||||
type: ['object'],
|
type: ['object'],
|
||||||
|
@ -19,16 +24,16 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.getInvoiceDate = async companyFk => {
|
Self.getInvoiceDate = async(companyFk, serialType) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const [invoiceDate] = await models.InvoiceOut.rawSql(
|
const [invoiceDate] = await models.InvoiceOut.rawSql(
|
||||||
`SELECT MAX(io.issued) issued
|
`SELECT MAX(io.issued) issued
|
||||||
FROM invoiceOut io
|
FROM invoiceOut io
|
||||||
JOIN invoiceOutSerial ios ON ios.code = io.serial
|
JOIN invoiceOutSerial ios ON ios.code = io.serial
|
||||||
WHERE ios.type = 'global'
|
WHERE ios.type = ?
|
||||||
AND io.issued
|
AND io.issued
|
||||||
AND io.companyFk = ?`,
|
AND io.companyFk = ?`,
|
||||||
[companyFk]
|
[serialType, companyFk]
|
||||||
);
|
);
|
||||||
return invoiceDate;
|
return invoiceDate;
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
const moment = require('moment');
|
||||||
|
|
||||||
|
describe('getInvoiceDate()', () => {
|
||||||
|
const companyFk = 442;
|
||||||
|
let tx;
|
||||||
|
let options;
|
||||||
|
|
||||||
|
beforeEach(async() => {
|
||||||
|
tx = await models.InvoiceOut.beginTransaction({});
|
||||||
|
options = {transaction: tx};
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async() => {
|
||||||
|
await tx.rollback();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return a correct date for serialType "global"', async() => {
|
||||||
|
const serialType = 'global';
|
||||||
|
const result = await models.InvoiceOut.getInvoiceDate(companyFk, serialType, options);
|
||||||
|
|
||||||
|
expect(moment(result.issued).format('YYYY-MM-DD')).toEqual('2000-12-01');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return null for serialType "multiple"', async() => {
|
||||||
|
const serialType = 'multiple';
|
||||||
|
const result = await models.InvoiceOut.getInvoiceDate(companyFk, serialType, options);
|
||||||
|
|
||||||
|
expect(result.issued).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return correct date for serialType "quick"', async() => {
|
||||||
|
const serialType = 'quick';
|
||||||
|
const result = await models.InvoiceOut.getInvoiceDate(companyFk, serialType, options);
|
||||||
|
|
||||||
|
expect(moment(result.issued).format('YYYY-MM-DD')).toEqual('2001-01-01');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue