{
- const jasmine = require('gulp-jasmine');
-
- const options = {
- verbose: false,
- includeStackTrace: false,
- errorOnFail: false,
- timeout: 5000,
- config: {}
- };
-
- if (argv.ci) {
- const reporters = require('jasmine-reporters');
- options.reporter = new reporters.JUnitXmlReporter();
- }
-
- let backSpecFiles = [
- 'back/**/*.spec.js',
- 'loopback/**/*.spec.js',
- 'modules/*/back/**/*.spec.js'
- ];
-
- gulp.src(backSpecFiles)
- .pipe(jasmine(options))
- .on('end', resolve)
- .on('error', reject)
- .resume();
- });
- } catch (e) {
- err = e;
- }
- await app.disconnect();
- await container.rm();
- done();
- if (err)
- throw err;
-}
-launchBackTest.description = `
- Runs the backend tests once using a random container, can receive --ci arg to save reports on a xml file`;
-
-// Backend tests
-
-function backTest(done) {
- const nodemon = require('gulp-nodemon');
-
- nodemon({
- exec: ['node --tls-min-v1.0 ./node_modules/gulp/bin/gulp.js'],
- args: ['launchBackTest'],
- watch: backSources,
- done: done
- });
-}
-backTest.description = `Watches for changes in modules to execute backTest task`;
-
-// End to end tests
-function e2eSingleRun() {
- require('@babel/register')({presets: ['@babel/env']});
- require('core-js/stable');
- require('regenerator-runtime/runtime');
-
- const jasmine = require('gulp-jasmine');
- const SpecReporter = require('jasmine-spec-reporter').SpecReporter;
-
- if (argv.show || argv.s)
- process.env.E2E_SHOW = true;
-
- const specFiles = [
- `${__dirname}/e2e/paths/01*/*[sS]pec.js`,
- `${__dirname}/e2e/paths/02*/*[sS]pec.js`,
- `${__dirname}/e2e/paths/03*/*[sS]pec.js`,
- `${__dirname}/e2e/paths/04*/*[sS]pec.js`,
- `${__dirname}/e2e/paths/05*/*[sS]pec.js`,
- `${__dirname}/e2e/paths/06*/*[sS]pec.js`,
- `${__dirname}/e2e/paths/07*/*[sS]pec.js`,
- `${__dirname}/e2e/paths/08*/*[sS]pec.js`,
- `${__dirname}/e2e/paths/09*/*[sS]pec.js`,
- `${__dirname}/e2e/paths/10*/*[sS]pec.js`,
- `${__dirname}/e2e/paths/11*/*[sS]pec.js`,
- `${__dirname}/e2e/paths/12*/*[sS]pec.js`,
- `${__dirname}/e2e/paths/13*/*[sS]pec.js`,
- `${__dirname}/e2e/paths/**/*[sS]pec.js`
- ];
-
- return gulp.src(specFiles).pipe(jasmine({
- errorOnFail: false,
- timeout: 30000,
- config: {
- random: false,
- // TODO: Waiting for this option to be implemented
- // https://github.com/jasmine/jasmine/issues/1533
- stopSpecOnExpectationFailure: false
- },
- reporter: [
- new SpecReporter({
- spec: {
- displayStacktrace: 'none',
- displaySuccessful: true,
- displayFailedSpec: true,
- displaySpecDuration: true,
- },
- summary: {
- displayStacktrace: 'raw',
- displayPending: false
- },
- colors: {
- enabled: true,
- successful: 'brightGreen',
- failed: 'brightRed'
- },
- // stacktrace: {
- // filter: stacktrace => {
- // const lines = stacktrace.split('\n');
- // const filtered = [];
- // for (let i = 1; i < lines.length; i++) {
- // if (/e2e\/paths/.test(lines[i]))
- // filtered.push(lines[i]);
- // }
- // return filtered.join('\n');
- // }
- // }
- })
- ]
- }));
-}
-
-e2e = gulp.series(docker, async function isBackendReady() {
- const attempts = await backendStatus();
- log(`Backend ready after ${attempts} attempt(s)`);
-
- return attempts;
-}, e2eSingleRun);
-e2e.description = `Restarts database and runs the e2e tests`;
-
-async function backendStatus() {
- const milliseconds = 250;
- return new Promise(resolve => {
- let timer;
- let attempts = 1;
- timer = setInterval(async() => {
- try {
- const url = `${e2eConfig.url}/api/Applications/status`;
- const {body} = await got.get(url);
-
- if (body == 'true') {
- clearInterval(timer);
- resolve(attempts);
- } else
- attempts++;
- } catch (error) {
- if (error || attempts > 100) // 250ms * 100 => 25s timeout
- throw new Error('Could not connect to backend');
- }
- }, milliseconds);
- });
-}
-backendStatus.description = `Performs a simple requests to check the backend status`;
-
function install() {
const install = require('gulp-install');
const print = require('gulp-print');
@@ -431,9 +248,6 @@ module.exports = {
back,
backOnly,
backWatch,
- backTest,
- launchBackTest,
- e2e,
i,
install,
build,
@@ -444,6 +258,5 @@ module.exports = {
locales,
localesRoutes,
watch,
- docker,
- backendStatus,
+ docker
};
diff --git a/jest.front.config.js b/jest.front.config.js
index dbea13950e..a03c61d114 100644
--- a/jest.front.config.js
+++ b/jest.front.config.js
@@ -47,5 +47,6 @@ module.exports = {
'^.+\\.js?$': 'babel-jest',
'^.+\\.html$': 'html-loader-jest'
},
+ reporters: ['default', 'jest-junit']
};
diff --git a/loopback/common/models/field-acl.json b/loopback/common/models/field-acl.json
index 25ed949b97..a3f74aca27 100644
--- a/loopback/common/models/field-acl.json
+++ b/loopback/common/models/field-acl.json
@@ -9,19 +9,19 @@
"properties": {
"id": {
"id": true,
- "type": "Number"
+ "type": "number"
},
"model": {
- "type": "String"
+ "type": "string"
},
"property":{
- "type": "String"
+ "type": "string"
},
"actionType":{
- "type": "String"
+ "type": "string"
},
"role":{
- "type": "String"
+ "type": "string"
}
}
}
diff --git a/modules/account/back/models/samba-config.json b/modules/account/back/models/samba-config.json
index 1bde4cdb6e..732c9b071c 100644
--- a/modules/account/back/models/samba-config.json
+++ b/modules/account/back/models/samba-config.json
@@ -29,7 +29,7 @@
"type": "string"
},
"verifyCert": {
- "type": "Boolean"
+ "type": "boolean"
}
}
}
diff --git a/modules/account/back/models/sip-config.json b/modules/account/back/models/sip-config.json
index 088f182246..6c5ba3db38 100644
--- a/modules/account/back/models/sip-config.json
+++ b/modules/account/back/models/sip-config.json
@@ -11,7 +11,7 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true
}
}
diff --git a/modules/account/back/models/sip.json b/modules/account/back/models/sip.json
index 7a7cb8605d..21671f4bfc 100644
--- a/modules/account/back/models/sip.json
+++ b/modules/account/back/models/sip.json
@@ -8,7 +8,7 @@
},
"properties": {
"userFk": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "The user id",
"mysql": {
@@ -16,7 +16,7 @@
}
},
"extension": {
- "type": "String",
+ "type": "string",
"required": true
}
},
diff --git a/modules/account/front/role/summary/index.js b/modules/account/front/role/summary/index.js
index 0a08fe8b24..4f321fa98f 100644
--- a/modules/account/front/role/summary/index.js
+++ b/modules/account/front/role/summary/index.js
@@ -6,7 +6,6 @@ class Controller extends Component {
this._role = value;
this.$.summary = null;
if (!value) return;
-
this.$http.get(`Roles/${value.id}`)
.then(res => this.$.summary = res.data);
}
diff --git a/modules/claim/back/models/claim-beginning.json b/modules/claim/back/models/claim-beginning.json
index abdae440a7..afa21f817b 100644
--- a/modules/claim/back/models/claim-beginning.json
+++ b/modules/claim/back/models/claim-beginning.json
@@ -13,12 +13,12 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "Identifier"
},
"quantity": {
- "type": "Number",
+ "type": "number",
"required": true
}
},
diff --git a/modules/claim/back/models/claim-destination.json b/modules/claim/back/models/claim-destination.json
index 8782fb815c..60f9488991 100644
--- a/modules/claim/back/models/claim-destination.json
+++ b/modules/claim/back/models/claim-destination.json
@@ -8,12 +8,12 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "Identifier"
},
"description": {
- "type": "String",
+ "type": "string",
"required": true
}
},
diff --git a/modules/claim/back/models/claim-development.json b/modules/claim/back/models/claim-development.json
index 2e8eb2f019..02061fab7b 100644
--- a/modules/claim/back/models/claim-development.json
+++ b/modules/claim/back/models/claim-development.json
@@ -12,7 +12,7 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "Identifier"
},
diff --git a/modules/claim/back/models/claim-dms.json b/modules/claim/back/models/claim-dms.json
index 9ef9648864..a215b6bb75 100644
--- a/modules/claim/back/models/claim-dms.json
+++ b/modules/claim/back/models/claim-dms.json
@@ -17,7 +17,7 @@
],
"properties": {
"dmsFk": {
- "type": "Number",
+ "type": "number",
"id": true,
"required": true
}
diff --git a/modules/claim/back/models/claim-end.json b/modules/claim/back/models/claim-end.json
index d908c252b2..12d79f71b2 100644
--- a/modules/claim/back/models/claim-end.json
+++ b/modules/claim/back/models/claim-end.json
@@ -12,7 +12,7 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "Identifier"
}
diff --git a/modules/claim/back/models/claim-log.json b/modules/claim/back/models/claim-log.json
index 28b3f88ecd..519cfe1ea8 100644
--- a/modules/claim/back/models/claim-log.json
+++ b/modules/claim/back/models/claim-log.json
@@ -9,40 +9,40 @@
"properties": {
"id": {
"id": true,
- "type": "Number",
+ "type": "number",
"forceId": false
},
"originFk": {
- "type": "Number",
+ "type": "number",
"required": true
},
"userFk": {
- "type": "Number"
+ "type": "number"
},
"action": {
- "type": "String",
+ "type": "string",
"required": true
},
"changedModel": {
- "type": "String"
+ "type": "string"
},
"oldInstance": {
- "type": "Object"
+ "type": "object"
},
"newInstance": {
- "type": "Object"
+ "type": "object"
},
"creationDate": {
- "type": "Date"
+ "type": "date"
},
"changedModelId": {
- "type": "Number"
+ "type": "number"
},
"changedModelValue": {
- "type": "String"
+ "type": "string"
},
"description": {
- "type": "String"
+ "type": "string"
}
},
"relations": {
diff --git a/modules/claim/back/models/claim-ratio.json b/modules/claim/back/models/claim-ratio.json
index 196db72f6c..605da98c66 100644
--- a/modules/claim/back/models/claim-ratio.json
+++ b/modules/claim/back/models/claim-ratio.json
@@ -9,23 +9,23 @@
"validateUpsert": true,
"properties": {
"clientFk": {
- "type": "Number",
+ "type": "number",
"id": true
},
"yearSale": {
- "type": "Number"
+ "type": "number"
},
"claimAmount": {
- "type": "Number"
+ "type": "number"
},
"claimingRate": {
- "type": "Number"
+ "type": "number"
},
"priceIncreasing": {
- "type": "Number"
+ "type": "number"
},
"packingRate": {
- "type": "Number"
+ "type": "number"
}
},
"relations": {
diff --git a/modules/claim/back/models/claim-reason.json b/modules/claim/back/models/claim-reason.json
index 562acc14ef..8d51b8079a 100644
--- a/modules/claim/back/models/claim-reason.json
+++ b/modules/claim/back/models/claim-reason.json
@@ -8,12 +8,12 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "Identifier"
},
"description": {
- "type": "String"
+ "type": "string"
}
},
"acls": [
diff --git a/modules/claim/back/models/claim-redelivery.json b/modules/claim/back/models/claim-redelivery.json
index 8611a3a44f..d153c7a8ee 100644
--- a/modules/claim/back/models/claim-redelivery.json
+++ b/modules/claim/back/models/claim-redelivery.json
@@ -8,12 +8,12 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "Identifier"
},
"description": {
- "type": "String",
+ "type": "string",
"required": true
}
},
diff --git a/modules/claim/back/models/claim-responsible.json b/modules/claim/back/models/claim-responsible.json
index 6bd06605b9..bdc5df0eca 100644
--- a/modules/claim/back/models/claim-responsible.json
+++ b/modules/claim/back/models/claim-responsible.json
@@ -8,16 +8,16 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "Identifier"
},
"description": {
- "type": "String",
+ "type": "string",
"required": true
},
"responsability": {
- "type": "Number",
+ "type": "number",
"required": true
}
},
diff --git a/modules/claim/back/models/claim-result.json b/modules/claim/back/models/claim-result.json
index 468f271de8..2c96306962 100644
--- a/modules/claim/back/models/claim-result.json
+++ b/modules/claim/back/models/claim-result.json
@@ -8,12 +8,12 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "Identifier"
},
"description": {
- "type": "String"
+ "type": "string"
}
},
"acls": [
diff --git a/modules/claim/back/models/claim.json b/modules/claim/back/models/claim.json
index 431290812a..a3490ccf47 100644
--- a/modules/claim/back/models/claim.json
+++ b/modules/claim/back/models/claim.json
@@ -12,7 +12,7 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "Identifier"
},
diff --git a/modules/client/back/methods/client/sendSms.js b/modules/client/back/methods/client/sendSms.js
index cc11d17be8..9d6a12416e 100644
--- a/modules/client/back/methods/client/sendSms.js
+++ b/modules/client/back/methods/client/sendSms.js
@@ -39,7 +39,7 @@ module.exports = Self => {
const userId = ctx.req.accessToken.userId;
- const sms = await models.Sms.send(ctx, id, destination, message);
+ const sms = await models.Sms.send(ctx, destination, message);
const logRecord = {
originFk: id,
userFk: userId,
diff --git a/modules/client/back/methods/client/specs/updatePortfolio.spec.js b/modules/client/back/methods/client/specs/updatePortfolio.spec.js
index 4830156fc4..f56555c08c 100644
--- a/modules/client/back/methods/client/specs/updatePortfolio.spec.js
+++ b/modules/client/back/methods/client/specs/updatePortfolio.spec.js
@@ -12,11 +12,13 @@ describe('Client updatePortfolio', () => {
const expectedResult = 841.63;
- await models.Client.rawSql(`UPDATE vn.client SET salesPersonFk = ${salesPersonId} WHERE id = ${clientId}; `);
+ const clientQuery = `UPDATE vn.client SET salesPersonFk = ${salesPersonId} WHERE id = ${clientId}; `;
+ await models.Client.rawSql(clientQuery);
await models.Client.updatePortfolio();
- let [salesPerson] = await models.Client.rawSql(`SELECT portfolioWeight FROM bs.salesPerson WHERE workerFk = ${salesPersonId}; `, null, options);
+ const portfolioQuery = `SELECT portfolioWeight FROM bs.salesPerson WHERE workerFk = ${salesPersonId}; `;
+ const [salesPerson] = await models.Client.rawSql(portfolioQuery, null, options);
expect(salesPerson.portfolioWeight).toEqual(expectedResult);
@@ -26,8 +28,9 @@ describe('Client updatePortfolio', () => {
throw e;
}
});
- // task 3817
- xit('should keep the same portfolioWeight when a salesperson is unassigned of a client', async() => {
+
+ it('should keep the same portfolioWeight when a salesperson is unassigned of a client', async() => {
+ pending('task 3817');
const salesPersonId = 19;
const tx = await models.Client.beginTransaction({});
@@ -40,7 +43,8 @@ describe('Client updatePortfolio', () => {
await models.Client.updatePortfolio();
- let [salesPerson] = await models.Client.rawSql(`SELECT portfolioWeight FROM bs.salesPerson WHERE workerFk = ${salesPersonId}; `, null, options);
+ const portfolioQuery = `SELECT portfolioWeight FROM bs.salesPerson WHERE workerFk = ${salesPersonId}; `;
+ const [salesPerson] = await models.Client.rawSql(portfolioQuery, null, options);
expect(salesPerson.portfolioWeight).toEqual(expectedResult);
diff --git a/modules/client/back/methods/sms/send.js b/modules/client/back/methods/sms/send.js
index 08daf83a1f..94b2b6c276 100644
--- a/modules/client/back/methods/sms/send.js
+++ b/modules/client/back/methods/sms/send.js
@@ -6,10 +6,6 @@ module.exports = Self => {
description: 'Sends SMS to a destination phone',
accessType: 'WRITE',
accepts: [
- {
- arg: 'destinationFk',
- type: 'integer'
- },
{
arg: 'destination',
type: 'string',
@@ -31,7 +27,7 @@ module.exports = Self => {
}
});
- Self.send = async(ctx, destinationFk, destination, message) => {
+ Self.send = async(ctx, destination, message) => {
const userId = ctx.req.accessToken.userId;
const smsConfig = await Self.app.models.SmsConfig.findOne();
@@ -68,7 +64,6 @@ module.exports = Self => {
const newSms = {
senderFk: userId,
- destinationFk: destinationFk || null,
destination: destination,
message: message,
status: error
diff --git a/modules/client/back/methods/sms/send.spec.js b/modules/client/back/methods/sms/send.spec.js
index 7ca78b2149..8eee85bd62 100644
--- a/modules/client/back/methods/sms/send.spec.js
+++ b/modules/client/back/methods/sms/send.spec.js
@@ -3,7 +3,7 @@ const app = require('vn-loopback/server/server');
describe('sms send()', () => {
it('should not return status error', async() => {
const ctx = {req: {accessToken: {userId: 1}}};
- const result = await app.models.Sms.send(ctx, 1105, '123456789', 'My SMS Body');
+ const result = await app.models.Sms.send(ctx, '123456789', 'My SMS Body');
expect(result.status).toBeUndefined();
});
diff --git a/modules/client/back/model-config.json b/modules/client/back/model-config.json
index b6bf715b1b..4feb3b1688 100644
--- a/modules/client/back/model-config.json
+++ b/modules/client/back/model-config.json
@@ -14,6 +14,9 @@
"Client": {
"dataSource": "vn"
},
+ "ClientConfig": {
+ "dataSource": "vn"
+ },
"ClientContact": {
"dataSource": "vn"
},
diff --git a/modules/client/back/models/address-observation.json b/modules/client/back/models/address-observation.json
index 3096c8e5d6..2fdb8bc0f7 100644
--- a/modules/client/back/models/address-observation.json
+++ b/modules/client/back/models/address-observation.json
@@ -8,7 +8,7 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "Identifier"
},
diff --git a/modules/client/back/models/address.json b/modules/client/back/models/address.json
index dd533cb32f..0dcbbf7fe1 100644
--- a/modules/client/back/models/address.json
+++ b/modules/client/back/models/address.json
@@ -14,7 +14,7 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "Identifier"
},
@@ -43,10 +43,10 @@
"type": "boolean"
},
"longitude": {
- "type": "Number"
+ "type": "number"
},
"latitude": {
- "type": "Number"
+ "type": "number"
},
"isEqualizated": {
"type": "boolean"
diff --git a/modules/client/back/models/client-config.json b/modules/client/back/models/client-config.json
new file mode 100644
index 0000000000..90d47333dd
--- /dev/null
+++ b/modules/client/back/models/client-config.json
@@ -0,0 +1,22 @@
+{
+ "name": "ClientConfig",
+ "base": "VnModel",
+ "options": {
+ "mysql": {
+ "table": "clientConfig"
+ }
+ },
+ "properties": {
+ "id": {
+ "type": "number",
+ "id": true,
+ "description": "Identifier"
+ },
+ "riskTolerance": {
+ "type": "number"
+ },
+ "maxCreditRows": {
+ "type": "number"
+ }
+ }
+}
\ No newline at end of file
diff --git a/modules/client/back/models/client-contact.json b/modules/client/back/models/client-contact.json
index ea916c0726..514ebbf5e8 100644
--- a/modules/client/back/models/client-contact.json
+++ b/modules/client/back/models/client-contact.json
@@ -3,34 +3,34 @@
"description": "Client phone contacts",
"base": "Loggable",
"log": {
- "model": "ClientLog",
- "relation": "client",
- "showField": "name"
+ "model": "ClientLog",
+ "relation": "client",
+ "showField": "name"
},
"options": {
- "mysql": {
- "table": "clientContact"
- }
+ "mysql": {
+ "table": "clientContact"
+ }
},
"validateUpsert": true,
"properties": {
- "id": {
- "type": "Number",
- "id": true,
- "description": "Identifier"
- },
- "name": {
- "type": "string"
- },
- "phone": {
- "type": "string"
- }
+ "id": {
+ "type": "number",
+ "id": true,
+ "description": "Identifier"
+ },
+ "name": {
+ "type": "string"
+ },
+ "phone": {
+ "type": "string"
+ }
},
"relations": {
- "client": {
- "type": "belongsTo",
- "model": "Client",
- "foreignKey": "clientFk"
- }
+ "client": {
+ "type": "belongsTo",
+ "model": "Client",
+ "foreignKey": "clientFk"
+ }
}
- }
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/modules/client/back/models/client-credit-limit.json b/modules/client/back/models/client-credit-limit.json
index 5263fb94bd..740f0cf534 100644
--- a/modules/client/back/models/client-credit-limit.json
+++ b/modules/client/back/models/client-credit-limit.json
@@ -1,26 +1,26 @@
{
- "name": "ClientCreditLimit",
- "base": "VnModel",
- "options": {
- "mysql": {
- "table": "clientCreditLimit"
- }
- },
- "properties": {
- "id": {
- "type": "Number",
- "id": true,
- "description": "Identifier"
+ "name": "ClientCreditLimit",
+ "base": "VnModel",
+ "options": {
+ "mysql": {
+ "table": "clientCreditLimit"
+ }
},
- "maxAmount": {
- "type": "Number"
+ "properties": {
+ "id": {
+ "type": "number",
+ "id": true,
+ "description": "Identifier"
+ },
+ "maxAmount": {
+ "type": "number"
+ }
+ },
+ "relations": {
+ "role": {
+ "type": "belongsTo",
+ "model": "Role",
+ "foreignKey": "roleFk"
+ }
}
- },
- "relations": {
- "role": {
- "type": "belongsTo",
- "model": "Role",
- "foreignKey": "roleFk"
- }
- }
}
\ No newline at end of file
diff --git a/modules/client/back/models/client-credit.js b/modules/client/back/models/client-credit.js
new file mode 100644
index 0000000000..01fe8214aa
--- /dev/null
+++ b/modules/client/back/models/client-credit.js
@@ -0,0 +1,23 @@
+module.exports = Self => {
+ Self.observe('after save', async ctx => {
+ const instance = ctx.instance;
+ const models = Self.app.models;
+
+ const clientConfig = await models.ClientConfig.findOne();
+ const maxCreditRows = clientConfig.maxCreditRows;
+
+ const clientCredit = await models.ClientCredit.find({
+ where: {clientFk: instance.clientFk},
+ order: 'created DESC',
+ limit: maxCreditRows
+ }, ctx.options);
+
+ const lastCredit = clientCredit[maxCreditRows - 1];
+ if (lastCredit) {
+ await models.ClientCredit.destroyAll({
+ clientFk: instance.clientFk,
+ created: {lt: lastCredit.created}
+ }, ctx.options);
+ }
+ });
+};
diff --git a/modules/client/back/models/client-credit.json b/modules/client/back/models/client-credit.json
index 2b71fbe2d6..b92639b80c 100644
--- a/modules/client/back/models/client-credit.json
+++ b/modules/client/back/models/client-credit.json
@@ -1,36 +1,36 @@
{
- "name": "ClientCredit",
- "description": "Log of credit changes",
- "base": "VnModel",
- "options": {
- "mysql": {
- "table": "clientCredit"
- }
- },
- "validateUpsert": true,
- "properties": {
- "id": {
- "type": "Number",
- "id": true,
- "description": "Identifier"
+ "name": "ClientCredit",
+ "description": "Log of credit changes",
+ "base": "VnModel",
+ "options": {
+ "mysql": {
+ "table": "clientCredit"
+ }
},
- "amount": {
- "type": "Number"
+ "validateUpsert": true,
+ "properties": {
+ "id": {
+ "type": "number",
+ "id": true,
+ "description": "Identifier"
+ },
+ "amount": {
+ "type": "number"
+ },
+ "created": {
+ "type": "date"
+ }
},
- "created": {
- "type": "date"
+ "relations": {
+ "client": {
+ "type": "belongsTo",
+ "model": "Client",
+ "foreignKey": "clientFk"
+ },
+ "worker": {
+ "type": "belongsTo",
+ "model": "Worker",
+ "foreignKey": "workerFk"
+ }
}
- },
- "relations": {
- "client": {
- "type": "belongsTo",
- "model": "Client",
- "foreignKey": "clientFk"
- },
- "worker": {
- "type": "belongsTo",
- "model": "Worker",
- "foreignKey": "workerFk"
- }
- }
}
\ No newline at end of file
diff --git a/modules/client/back/models/client-dms.json b/modules/client/back/models/client-dms.json
index 28ad219175..88b4349dfa 100644
--- a/modules/client/back/models/client-dms.json
+++ b/modules/client/back/models/client-dms.json
@@ -13,12 +13,12 @@
},
"properties": {
"dmsFk": {
- "type": "Number",
+ "type": "number",
"id": true,
"required": true
},
"clientFk": {
- "type": "Number",
+ "type": "number",
"required": true
}
},
diff --git a/modules/client/back/models/client-log.json b/modules/client/back/models/client-log.json
index 50c892e853..9c0933c0c1 100644
--- a/modules/client/back/models/client-log.json
+++ b/modules/client/back/models/client-log.json
@@ -9,40 +9,40 @@
"properties": {
"id": {
"id": true,
- "type": "Number",
+ "type": "number",
"forceId": false
},
"originFk": {
- "type": "Number",
+ "type": "number",
"required": true
},
"userFk": {
- "type": "Number"
+ "type": "number"
},
"action": {
- "type": "String",
+ "type": "string",
"required": true
},
"changedModel": {
- "type": "String"
+ "type": "string"
},
"oldInstance": {
- "type": "Object"
+ "type": "object"
},
"newInstance": {
- "type": "Object"
+ "type": "object"
},
"creationDate": {
- "type": "Date"
+ "type": "date"
},
"changedModelId": {
- "type": "Number"
+ "type": "number"
},
"changedModelValue": {
- "type": "String"
+ "type": "string"
},
"description": {
- "type": "String"
+ "type": "string"
}
},
"relations": {
diff --git a/modules/client/back/models/client-observation.json b/modules/client/back/models/client-observation.json
index a9c7b483a5..d3059377db 100644
--- a/modules/client/back/models/client-observation.json
+++ b/modules/client/back/models/client-observation.json
@@ -13,12 +13,12 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "Identifier"
},
"clientFk": {
- "type": "Number"
+ "type": "number"
},
"text": {
"type": "string",
diff --git a/modules/client/back/models/client-risk.json b/modules/client/back/models/client-risk.json
index f76483fca4..eac36affbb 100644
--- a/modules/client/back/models/client-risk.json
+++ b/modules/client/back/models/client-risk.json
@@ -2,22 +2,22 @@
"name": "ClientRisk",
"base": "VnModel",
"options": {
- "mysql": {
- "table": "clientRisk"
- }
+ "mysql": {
+ "table": "clientRisk"
+ }
},
"properties": {
- "clientFk": {
- "type": "Number",
- "id": true
- },
- "companyFk": {
- "type": "Number",
- "id": true
- },
- "amount": {
- "type": "Number"
- }
+ "clientFk": {
+ "type": "number",
+ "id": true
+ },
+ "companyFk": {
+ "type": "number",
+ "id": true
+ },
+ "amount": {
+ "type": "number"
+ }
},
"relations": {
"client": {
@@ -31,4 +31,4 @@
"foreignKey": "companyFk"
}
}
- }
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/modules/client/back/models/client-sample.json b/modules/client/back/models/client-sample.json
index 812da8be8e..920758217c 100644
--- a/modules/client/back/models/client-sample.json
+++ b/modules/client/back/models/client-sample.json
@@ -14,7 +14,7 @@
"properties": {
"id": {
"id": true,
- "type": "Number",
+ "type": "number",
"description": "Identifier"
},
"created": {
diff --git a/modules/client/back/models/client-type.json b/modules/client/back/models/client-type.json
index a91cc38b6c..eeae845eb8 100644
--- a/modules/client/back/models/client-type.json
+++ b/modules/client/back/models/client-type.json
@@ -8,17 +8,17 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true
},
"code": {
- "type": "String"
+ "type": "string"
},
"type": {
- "type": "String"
+ "type": "string"
},
"isCreatedAsServed": {
- "type": "Number"
+ "type": "number"
}
}
}
\ No newline at end of file
diff --git a/modules/client/back/models/client-unpaid.json b/modules/client/back/models/client-unpaid.json
index a3d1a684c2..0fc3a91950 100644
--- a/modules/client/back/models/client-unpaid.json
+++ b/modules/client/back/models/client-unpaid.json
@@ -2,21 +2,21 @@
"name": "ClientUnpaid",
"base": "VnModel",
"options": {
- "mysql": {
- "table": "clientUnpaid"
- }
+ "mysql": {
+ "table": "clientUnpaid"
+ }
},
"properties": {
- "clientFk": {
- "type": "number",
- "id": true
- },
- "dated": {
- "type": "date"
- },
- "amount": {
- "type": "Number"
- }
+ "clientFk": {
+ "type": "number",
+ "id": true
+ },
+ "dated": {
+ "type": "date"
+ },
+ "amount": {
+ "type": "number"
+ }
},
"relations": {
"client": {
diff --git a/modules/client/back/models/client.json b/modules/client/back/models/client.json
index 6404cfba0b..b9951e8bbc 100644
--- a/modules/client/back/models/client.json
+++ b/modules/client/back/models/client.json
@@ -12,7 +12,7 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "Identifier"
},
@@ -55,16 +55,16 @@
"type": "boolean"
},
"credit": {
- "type": "Number"
+ "type": "number"
},
"creditInsurance": {
- "type": "Number"
+ "type": "number"
},
"iban": {
"type": "string"
},
"dueDay": {
- "type": "Number"
+ "type": "number"
},
"isEqualizated": {
"type": "boolean",
@@ -105,7 +105,7 @@
"type": "boolean"
},
"quality": {
- "type": "Number"
+ "type": "number"
},
"isVies": {
"type": "boolean"
@@ -117,7 +117,7 @@
"type": "string"
},
"created": {
- "type": "Date"
+ "type": "date"
},
"sageTaxTypeFk": {
"type": "number",
diff --git a/modules/client/back/models/contact-channel.json b/modules/client/back/models/contact-channel.json
index 3a5de2140a..75151b9f92 100644
--- a/modules/client/back/models/contact-channel.json
+++ b/modules/client/back/models/contact-channel.json
@@ -1,20 +1,20 @@
{
- "name": "ContactChannel",
- "base": "VnModel",
- "options": {
- "mysql": {
- "table": "contactChannel"
- }
- },
- "properties": {
- "id": {
- "type": "Number",
- "id": true,
- "description": "Identifier"
+ "name": "ContactChannel",
+ "base": "VnModel",
+ "options": {
+ "mysql": {
+ "table": "contactChannel"
+ }
},
- "name": {
- "type": "string",
- "required": true
+ "properties": {
+ "id": {
+ "type": "number",
+ "id": true,
+ "description": "Identifier"
+ },
+ "name": {
+ "type": "string",
+ "required": true
+ }
}
- }
}
\ No newline at end of file
diff --git a/modules/client/back/models/credit-classification.json b/modules/client/back/models/credit-classification.json
index 2e636af63c..543f8359e1 100644
--- a/modules/client/back/models/credit-classification.json
+++ b/modules/client/back/models/credit-classification.json
@@ -1,42 +1,42 @@
{
- "name": "CreditClassification",
- "description": "Clasified clients",
- "base": "VnModel",
- "options": {
- "mysql": {
- "table": "creditClassification"
- }
- },
- "properties": {
- "id": {
- "id": true,
- "type": "Number",
- "description": "Identifier"
+ "name": "CreditClassification",
+ "description": "Clasified clients",
+ "base": "VnModel",
+ "options": {
+ "mysql": {
+ "table": "creditClassification"
+ }
},
- "started": {
- "type": "date",
- "required": true,
- "mysql": {
- "columnName": "dateStart"
- }
+ "properties": {
+ "id": {
+ "id": true,
+ "type": "number",
+ "description": "Identifier"
+ },
+ "started": {
+ "type": "date",
+ "required": true,
+ "mysql": {
+ "columnName": "dateStart"
+ }
+ },
+ "finished": {
+ "type": "date",
+ "mysql": {
+ "columnName": "dateEnd"
+ }
+ }
},
- "finished": {
- "type": "date",
- "mysql": {
- "columnName": "dateEnd"
- }
+ "relations": {
+ "customer": {
+ "type": "belongsTo",
+ "model": "Client",
+ "foreignKey": "client"
+ },
+ "insurances": {
+ "type": "hasMany",
+ "model": "CreditInsurance",
+ "foreignKey": "creditClassification"
+ }
}
- },
- "relations": {
- "customer": {
- "type": "belongsTo",
- "model": "Client",
- "foreignKey": "client"
- },
- "insurances": {
- "type": "hasMany",
- "model": "CreditInsurance",
- "foreignKey": "creditClassification"
- }
- }
-}
+}
\ No newline at end of file
diff --git a/modules/client/back/models/credit-insurance.json b/modules/client/back/models/credit-insurance.json
index 6a9d04677a..db4154978f 100644
--- a/modules/client/back/models/credit-insurance.json
+++ b/modules/client/back/models/credit-insurance.json
@@ -10,11 +10,11 @@
"properties": {
"id": {
"id": true,
- "type": "Number",
+ "type": "number",
"description": "Identifier"
},
"credit": {
- "type": "Number"
+ "type": "number"
},
"created": {
"type": "date",
@@ -23,7 +23,7 @@
}
},
"grade": {
- "type": "Number"
+ "type": "number"
}
},
"relations": {
diff --git a/modules/client/back/models/customs-agent.json b/modules/client/back/models/customs-agent.json
index f72d7bf28b..3a2e0258fa 100644
--- a/modules/client/back/models/customs-agent.json
+++ b/modules/client/back/models/customs-agent.json
@@ -8,26 +8,26 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"description": "Identifier",
"id": true
},
"fiscalName": {
- "type": "String",
+ "type": "string",
"required": true
},
"street": {
- "type": "String"
+ "type": "string"
},
"nif": {
- "type": "String",
+ "type": "string",
"required": true
},
"phone": {
- "type": "String"
+ "type": "string"
},
"email": {
- "type": "String"
+ "type": "string"
}
}
}
\ No newline at end of file
diff --git a/modules/client/back/models/defaulter.json b/modules/client/back/models/defaulter.json
index 8293264359..ddff1d2143 100644
--- a/modules/client/back/models/defaulter.json
+++ b/modules/client/back/models/defaulter.json
@@ -9,19 +9,19 @@
},
"properties": {
"id": {
- "type": "Number"
+ "type": "number"
},
"created": {
- "type": "Date"
+ "type": "date"
},
"amount": {
- "type": "Number"
+ "type": "number"
},
"defaulterSinced": {
- "type": "Number"
+ "type": "number"
},
"hasChanged": {
- "type": "Number"
+ "type": "number"
}
},
"relations": {
diff --git a/modules/client/back/models/greuge-config.json b/modules/client/back/models/greuge-config.json
index b72348023f..1ba66668d8 100644
--- a/modules/client/back/models/greuge-config.json
+++ b/modules/client/back/models/greuge-config.json
@@ -8,7 +8,7 @@
},
"properties": {
"freightPickUpPrice": {
- "type": "Number"
+ "type": "number"
}
},
"acls": [{
diff --git a/modules/client/back/models/greuge-type.json b/modules/client/back/models/greuge-type.json
index 5c5b1870de..36b14e147c 100644
--- a/modules/client/back/models/greuge-type.json
+++ b/modules/client/back/models/greuge-type.json
@@ -9,14 +9,14 @@
"properties": {
"id": {
"id": true,
- "type": "Number",
+ "type": "number",
"description": "Identifier"
},
"name": {
- "type": "String"
+ "type": "string"
},
"code": {
- "type": "String"
+ "type": "string"
}
},
"acls": [
diff --git a/modules/client/back/models/greuge.json b/modules/client/back/models/greuge.json
index 2abc33f7ce..918ff0ca56 100644
--- a/modules/client/back/models/greuge.json
+++ b/modules/client/back/models/greuge.json
@@ -14,15 +14,15 @@
"properties": {
"id": {
"id": true,
- "type": "Number",
+ "type": "number",
"description": "Identifier"
},
"description": {
- "type": "String",
+ "type": "string",
"required": true
},
"amount": {
- "type": "Number",
+ "type": "number",
"required": true
},
"shipped": {
@@ -32,7 +32,7 @@
"type": "date"
},
"greugeTypeFk": {
- "type": "Number",
+ "type": "number",
"required": true
}
diff --git a/modules/client/back/models/incoterms.json b/modules/client/back/models/incoterms.json
index 915a5b59a0..fdf743c14c 100644
--- a/modules/client/back/models/incoterms.json
+++ b/modules/client/back/models/incoterms.json
@@ -8,12 +8,12 @@
},
"properties": {
"code": {
- "type": "String",
+ "type": "string",
"description": "Identifier",
"id": true
},
"name": {
- "type": "String"
+ "type": "string"
}
},
"acls": [
diff --git a/modules/client/back/models/mandate-type.json b/modules/client/back/models/mandate-type.json
index 8bd46ce194..ec189f089b 100644
--- a/modules/client/back/models/mandate-type.json
+++ b/modules/client/back/models/mandate-type.json
@@ -9,11 +9,11 @@
"properties": {
"id": {
"id": true,
- "type": "Number",
+ "type": "number",
"description": "Identifier"
},
"name": {
- "type": "String"
+ "type": "string"
}
}
}
\ No newline at end of file
diff --git a/modules/client/back/models/mandate.json b/modules/client/back/models/mandate.json
index a671c45f1f..914b23ce27 100644
--- a/modules/client/back/models/mandate.json
+++ b/modules/client/back/models/mandate.json
@@ -9,11 +9,11 @@
"properties": {
"id": {
"id": true,
- "type": "Number",
+ "type": "number",
"description": "Identifier"
},
"code": {
- "type": "String"
+ "type": "string"
},
"created": {
"type": "date"
diff --git a/modules/client/back/models/observation-type.json b/modules/client/back/models/observation-type.json
index 5a7bdcfdd1..474c5faac4 100644
--- a/modules/client/back/models/observation-type.json
+++ b/modules/client/back/models/observation-type.json
@@ -9,15 +9,15 @@
"properties": {
"id": {
"id": true,
- "type": "Number",
+ "type": "number",
"description": "Identifier"
},
"description": {
- "type": "String",
+ "type": "string",
"required": true
},
"code": {
- "type": "String",
+ "type": "string",
"required": true
}
},
diff --git a/modules/client/back/models/pay-method.json b/modules/client/back/models/pay-method.json
index 4080a09538..c83c21e2f7 100644
--- a/modules/client/back/models/pay-method.json
+++ b/modules/client/back/models/pay-method.json
@@ -8,7 +8,7 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "Identifier"
},
@@ -23,7 +23,7 @@
"type": "string"
},
"outstandingDebt": {
- "type": "Number"
+ "type": "number"
},
"isIbanRequiredForClients": {
"type": "boolean"
diff --git a/modules/client/back/models/recovery.json b/modules/client/back/models/recovery.json
index 5a26cd8422..de4183924d 100644
--- a/modules/client/back/models/recovery.json
+++ b/modules/client/back/models/recovery.json
@@ -2,40 +2,40 @@
"name": "Recovery",
"base": "Loggable",
"log": {
- "model": "ClientLog",
- "relation": "client"
+ "model": "ClientLog",
+ "relation": "client"
},
"options": {
- "mysql": {
- "table": "recovery"
- }
+ "mysql": {
+ "table": "recovery"
+ }
},
"properties": {
- "id": {
- "id": true,
- "type": "Number",
- "description": "Identifier"
- },
- "started": {
- "type": "date",
- "required": true
- },
- "finished": {
- "type": "date"
- },
- "amount": {
- "type": "Number",
- "required": true
- },
- "period": {
- "type": "Number"
- }
+ "id": {
+ "id": true,
+ "type": "number",
+ "description": "Identifier"
+ },
+ "started": {
+ "type": "date",
+ "required": true
+ },
+ "finished": {
+ "type": "date"
+ },
+ "amount": {
+ "type": "number",
+ "required": true
+ },
+ "period": {
+ "type": "number"
+ }
},
"relations": {
- "client": {
- "type": "belongsTo",
- "model": "Client",
- "foreignKey": "clientFk"
- }
+ "client": {
+ "type": "belongsTo",
+ "model": "Client",
+ "foreignKey": "clientFk"
+ }
}
- }
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/modules/client/back/models/sage-tax-type.json b/modules/client/back/models/sage-tax-type.json
index b60ef20cd5..97af7353c5 100644
--- a/modules/client/back/models/sage-tax-type.json
+++ b/modules/client/back/models/sage-tax-type.json
@@ -8,7 +8,7 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "Identifier",
"mysql": {
diff --git a/modules/client/back/models/sage-transaction-type.json b/modules/client/back/models/sage-transaction-type.json
index dbe8f3b39a..1903c650c0 100644
--- a/modules/client/back/models/sage-transaction-type.json
+++ b/modules/client/back/models/sage-transaction-type.json
@@ -8,7 +8,7 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "Identifier",
"mysql": {
diff --git a/modules/client/back/models/sms-config.json b/modules/client/back/models/sms-config.json
index f48c6198d6..ba78e4a8db 100644
--- a/modules/client/back/models/sms-config.json
+++ b/modules/client/back/models/sms-config.json
@@ -9,18 +9,18 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "Identifier"
},
"uri": {
- "type": "String"
+ "type": "string"
},
"apiKey": {
- "type": "String"
+ "type": "string"
},
"title": {
- "type": "String"
+ "type": "string"
}
}
}
diff --git a/modules/client/back/models/sms.json b/modules/client/back/models/sms.json
index e6e6ff64c4..29438fc67c 100644
--- a/modules/client/back/models/sms.json
+++ b/modules/client/back/models/sms.json
@@ -9,30 +9,30 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "Identifier"
},
"sender": {
- "type": "String",
+ "type": "string",
"required": true
},
"destination": {
- "type": "String",
+ "type": "string",
"required": true
},
"message": {
- "type": "String",
+ "type": "string",
"required": true
},
"statusCode": {
- "type": "Number"
+ "type": "number"
},
"status": {
- "type": "String"
+ "type": "string"
},
"created": {
- "type": "Date"
+ "type": "date"
}
},
"relations": {
diff --git a/modules/client/back/models/specs/address.spec.js b/modules/client/back/models/specs/address.spec.js
index 81af6ee283..f0b421d351 100644
--- a/modules/client/back/models/specs/address.spec.js
+++ b/modules/client/back/models/specs/address.spec.js
@@ -14,7 +14,7 @@ describe('loopback model address', () => {
}
};
- beforeEach(() => {
+ beforeAll(() => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
diff --git a/modules/client/back/models/specs/clientCredit.spec.js b/modules/client/back/models/specs/clientCredit.spec.js
new file mode 100644
index 0000000000..fcd86c979f
--- /dev/null
+++ b/modules/client/back/models/specs/clientCredit.spec.js
@@ -0,0 +1,53 @@
+const models = require('vn-loopback/server/server').models;
+
+describe('Client Credit', () => {
+ const instance = {id: 1101, name: 'Bruce Banner'};
+
+ describe('after save', () => {
+ it('should delete old rows of clientCredit', async() => {
+ const tx = await models.ClientCredit.beginTransaction({});
+ const clientConfig = await models.ClientConfig.findOne({
+ where: {id: 1}
+ });
+
+ let rowsBefore;
+ let rowsAfter;
+
+ try {
+ const options = {transaction: tx};
+ const salesAssistant = await models.Account.findOne({
+ where: {name: 'salesAssistant'}
+ }, options);
+
+ rowsBefore = await models.ClientCredit.find({
+ where: {clientFk: instance.id},
+ order: 'created DESC',
+ }, options);
+
+ await models.ClientCredit.create({
+ amount: 355,
+ clientFk: instance.id,
+ workerFk: salesAssistant.id
+ }, options);
+
+ rowsAfter = await models.ClientCredit.find({
+ where: {clientFk: instance.id},
+ order: 'created DESC',
+ }, options);
+
+ await tx.rollback();
+ } catch (e) {
+ await tx.rollback();
+ throw e;
+ }
+
+ const FirstRowsBefore = rowsBefore[0];
+ const FirstRowsAfter = rowsAfter[0];
+
+ expect(FirstRowsAfter.id).toBeGreaterThan(FirstRowsBefore.id);
+
+ expect(rowsBefore.length).toBeGreaterThanOrEqual(clientConfig.maxCreditRows);
+ expect(rowsAfter.length).toEqual(clientConfig.maxCreditRows);
+ });
+ });
+});
diff --git a/modules/client/back/models/tpv-error.json b/modules/client/back/models/tpv-error.json
index 61e2a71563..d62203f40a 100644
--- a/modules/client/back/models/tpv-error.json
+++ b/modules/client/back/models/tpv-error.json
@@ -8,7 +8,7 @@
},
"properties": {
"code": {
- "type": "String",
+ "type": "string",
"id": true,
"description": "Identifier"
},
diff --git a/modules/client/back/models/tpv-merchant.json b/modules/client/back/models/tpv-merchant.json
index db5c937d86..d4dba6cb11 100644
--- a/modules/client/back/models/tpv-merchant.json
+++ b/modules/client/back/models/tpv-merchant.json
@@ -8,7 +8,7 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "Identifier"
},
diff --git a/modules/client/back/models/tpv-response.json b/modules/client/back/models/tpv-response.json
index d3a382b5f0..674ba434c3 100644
--- a/modules/client/back/models/tpv-response.json
+++ b/modules/client/back/models/tpv-response.json
@@ -8,7 +8,7 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "Identifier"
},
diff --git a/modules/client/back/models/tpv-transaction.json b/modules/client/back/models/tpv-transaction.json
index 011616d98a..2d926cc407 100644
--- a/modules/client/back/models/tpv-transaction.json
+++ b/modules/client/back/models/tpv-transaction.json
@@ -8,33 +8,33 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "Identifier"
},
"merchantFk": {
- "type": "Number"
+ "type": "number"
},
"clientFk": {
- "type": "Number"
+ "type": "number"
},
"receiptFk": {
- "type": "Number"
+ "type": "number"
},
"amount": {
- "type": "Number"
+ "type": "number"
},
"response": {
- "type": "Number"
+ "type": "number"
},
"errorCode": {
- "type": "String"
+ "type": "string"
},
"status": {
- "type": "String"
+ "type": "string"
},
"created": {
- "type": "Date"
+ "type": "date"
}
},
"relations": {
diff --git a/modules/client/front/balance/create/index.js b/modules/client/front/balance/create/index.js
index 454e5e44d9..c6a6e7ff97 100644
--- a/modules/client/front/balance/create/index.js
+++ b/modules/client/front/balance/create/index.js
@@ -6,12 +6,7 @@ class Controller extends Dialog {
super($element, $, $transclude);
this.vnReport = vnReport;
-
- const tomorrow = new Date();
- tomorrow.setDate(tomorrow.getDate() + 1);
- this.receipt = {
- payed: tomorrow
- };
+ this.receipt = {};
}
set payed(value) {
@@ -72,6 +67,10 @@ class Controller extends Dialog {
`${accountingType && accountingType.receiptDescription}`;
}
this.maxAmount = accountingType && accountingType.maxAmount;
+
+ this.receipt.payed = new Date();
+ if (accountingType.daysInFuture)
+ this.receipt.payed.setDate(this.receipt.payed.getDate() + accountingType.daysInFuture);
}
}
diff --git a/modules/entry/back/methods/entry/latestBuysFilter.js b/modules/entry/back/methods/entry/latestBuysFilter.js
index 9693670c8f..6399faa522 100644
--- a/modules/entry/back/methods/entry/latestBuysFilter.js
+++ b/modules/entry/back/methods/entry/latestBuysFilter.js
@@ -98,9 +98,6 @@ module.exports = Self => {
Self.latestBuysFilter = async(ctx, filter, options) => {
const myOptions = {};
- if (filter && filter.modelParams)
- ctx.args = filter.modelParams;
-
if (typeof options == 'object')
Object.assign(myOptions, options);
diff --git a/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js b/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js
index edfdac9884..41971a64c0 100644
--- a/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js
+++ b/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js
@@ -1,5 +1,6 @@
const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
+const activeCtx = {accessToken: {userId: 9}};
describe('entry importBuysPreview()', () => {
const entryId = 1;
diff --git a/modules/entry/back/models/entry-log.json b/modules/entry/back/models/entry-log.json
index c63a55d9e0..6f8edaf25b 100644
--- a/modules/entry/back/models/entry-log.json
+++ b/modules/entry/back/models/entry-log.json
@@ -9,40 +9,40 @@
"properties": {
"id": {
"id": true,
- "type": "Number",
+ "type": "number",
"forceId": false
},
"originFk": {
- "type": "Number",
+ "type": "number",
"required": true
},
"userFk": {
- "type": "Number"
+ "type": "number"
},
"action": {
- "type": "String",
+ "type": "string",
"required": true
},
"changedModel": {
- "type": "String"
+ "type": "string"
},
"oldInstance": {
- "type": "Object"
+ "type": "object"
},
"newInstance": {
- "type": "Object"
+ "type": "object"
},
"creationDate": {
- "type": "Date"
+ "type": "date"
},
"changedModelId": {
- "type": "String"
+ "type": "string"
},
"changedModelValue": {
- "type": "String"
+ "type": "string"
},
"description": {
- "type": "String"
+ "type": "string"
}
},
"relations": {
diff --git a/modules/entry/back/models/entry-observation.json b/modules/entry/back/models/entry-observation.json
index 535735d839..0c63dd6632 100644
--- a/modules/entry/back/models/entry-observation.json
+++ b/modules/entry/back/models/entry-observation.json
@@ -13,11 +13,11 @@
"properties": {
"id": {
"id": true,
- "type": "Number",
+ "type": "number",
"description": "Identifier"
},
"description": {
- "type": "String",
+ "type": "string",
"required": true
}
},
diff --git a/modules/entry/front/latest-buys/index.html b/modules/entry/front/latest-buys/index.html
index a4d6f7e837..adeda5e56c 100644
--- a/modules/entry/front/latest-buys/index.html
+++ b/modules/entry/front/latest-buys/index.html
@@ -148,12 +148,12 @@
- {{::buy.packing | dashIfEmpty}}
+ {{::buy.packing | dashIfEmpty}}
|
- {{::buy.grouping | dashIfEmpty}}
+ {{::buy.grouping | dashIfEmpty}}
|
{{::buy.quantity}} |
diff --git a/modules/entry/front/latest-buys/index.js b/modules/entry/front/latest-buys/index.js
index 44c29cb11b..ec1109b818 100644
--- a/modules/entry/front/latest-buys/index.js
+++ b/modules/entry/front/latest-buys/index.js
@@ -159,8 +159,22 @@ export default class Controller extends Section {
lines: rowsToEdit
};
- if (this.checkedDummyCount && this.checkedDummyCount > 0)
- data.filter = this.$.model.userParams;
+ if (this.checkedDummyCount && this.checkedDummyCount > 0) {
+ const params = {};
+ if (this.$.model.userParams) {
+ const userParams = this.$.model.userParams;
+ for (let param in userParams) {
+ let newParam = this.exprBuilder(param, userParams[param]);
+ if (!newParam)
+ newParam = {[param]: userParams[param]};
+ Object.assign(params, newParam);
+ }
+ }
+ if (this.$.model.userFilter)
+ Object.assign(params, this.$.model.userFilter.where);
+
+ data.filter = params;
+ }
return this.$http.post('Buys/editLatestBuys', data)
.then(() => {
diff --git a/modules/invoiceIn/front/dueDay/index.html b/modules/invoiceIn/front/dueDay/index.html
index 579ef36098..1a1935e728 100644
--- a/modules/invoiceIn/front/dueDay/index.html
+++ b/modules/invoiceIn/front/dueDay/index.html
@@ -25,6 +25,9 @@
ng-model="invoiceInDueDay.bankFk"
url="Banks"
show-field="bank"
+ select-fields="['id','bank']"
+ order="id"
+ search-function="$ctrl.bankSearchFunc($search)"
rule>
{{id}}: {{bank}}
diff --git a/modules/invoiceIn/front/dueDay/index.js b/modules/invoiceIn/front/dueDay/index.js
index 22b697f7e2..3cc1c81e8a 100644
--- a/modules/invoiceIn/front/dueDay/index.js
+++ b/modules/invoiceIn/front/dueDay/index.js
@@ -17,6 +17,12 @@ class Controller extends Section {
this.card.reload();
});
}
+
+ bankSearchFunc($search) {
+ return /^\d+$/.test($search)
+ ? {id: $search}
+ : {bank: {like: '%' + $search + '%'}};
+ }
}
ngModule.vnComponent('vnInvoiceInDueDay', {
diff --git a/modules/invoiceIn/front/tax/index.html b/modules/invoiceIn/front/tax/index.html
index c495d44d2f..acc9cf4924 100644
--- a/modules/invoiceIn/front/tax/index.html
+++ b/modules/invoiceIn/front/tax/index.html
@@ -33,6 +33,13 @@
show-field="id"
rule>
{{id}}: {{name}}
+
+
+
+
-
\ No newline at end of file
+
+
+
+
+
+
+ {{$ctrl.$t('New expense')}}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/modules/invoiceIn/front/tax/index.js b/modules/invoiceIn/front/tax/index.js
index 53cfc55980..d05a77f29f 100644
--- a/modules/invoiceIn/front/tax/index.js
+++ b/modules/invoiceIn/front/tax/index.js
@@ -1,7 +1,12 @@
import ngModule from '../module';
import Section from 'salix/components/section';
+import UserError from 'core/lib/user-error';
class Controller extends Section {
+ constructor($element, $, vnWeekDays) {
+ super($element, $);
+ this.expense = {};
+ }
taxRate(invoiceInTax, taxRateSelection) {
const taxTypeSage = taxRateSelection && taxRateSelection.rate;
const taxableBase = invoiceInTax && invoiceInTax.taxableBase;
@@ -26,6 +31,27 @@ class Controller extends Section {
this.card.reload();
});
}
+
+ onResponse() {
+ try {
+ if (!this.expense.code)
+ throw new Error(`The code can't be empty`);
+ if (!this.expense.description)
+ throw new UserError(`The description can't be empty`);
+
+ const data = [{
+ id: this.expense.code,
+ isWithheld: this.expense.isWithheld,
+ name: this.expense.description
+ }];
+
+ this.$http.post(`Expenses`, data) .then(() => {
+ this.vnApp.showSuccess(this.$t('Expense saved!'));
+ });
+ } catch (e) {
+ this.vnApp.showError(this.$t(e.message));
+ }
+ }
}
ngModule.vnComponent('vnInvoiceInTax', {
diff --git a/modules/invoiceIn/front/tax/index.spec.js b/modules/invoiceIn/front/tax/index.spec.js
index 20d5d40d86..c62ada9ca8 100644
--- a/modules/invoiceIn/front/tax/index.spec.js
+++ b/modules/invoiceIn/front/tax/index.spec.js
@@ -1,16 +1,19 @@
import './index.js';
import watcher from 'core/mocks/watcher';
import crudModel from 'core/mocks/crud-model';
+const UserError = require('vn-loopback/util/user-error');
describe('InvoiceIn', () => {
describe('Component tax', () => {
let controller;
let $scope;
let vnApp;
+ let $httpBackend;
beforeEach(ngModule('invoiceIn'));
- beforeEach(inject(($componentController, $rootScope, _vnApp_) => {
+ beforeEach(inject(($componentController, $rootScope, _vnApp_, _$httpBackend_) => {
+ $httpBackend = _$httpBackend_;
vnApp = _vnApp_;
jest.spyOn(vnApp, 'showError');
$scope = $rootScope.$new();
@@ -19,6 +22,7 @@ describe('InvoiceIn', () => {
const $element = angular.element('');
controller = $componentController('vnInvoiceInTax', {$element, $scope});
+ controller.$.model = crudModel;
controller.invoiceIn = {id: 1};
}));
@@ -55,5 +59,56 @@ describe('InvoiceIn', () => {
expect(controller.card.reload).toHaveBeenCalledWith();
});
});
+
+ describe('onResponse()', () => {
+ it('should return success message', () => {
+ controller.expense = {
+ code: 7050000005,
+ isWithheld: 0,
+ description: 'Test'
+ };
+
+ const data = [{
+ id: controller.expense.code,
+ isWithheld: controller.expense.isWithheld,
+ name: controller.expense.description
+ }];
+
+ jest.spyOn(controller.vnApp, 'showSuccess');
+ $httpBackend.expect('POST', `Expenses`, data).respond();
+
+ controller.onResponse();
+ $httpBackend.flush();
+
+ expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Expense saved!');
+ });
+
+ it('should return an error if code is empty', () => {
+ controller.expense = {
+ code: null,
+ isWithheld: 0,
+ description: 'Test'
+ };
+
+ jest.spyOn(controller.vnApp, 'showError');
+ controller.onResponse();
+
+ expect(controller.vnApp.showError).toHaveBeenCalledWith(`The code can't be empty`);
+ });
+
+ it('should return an error if description is empty', () => {
+ controller.expense = {
+ code: 7050000005,
+ isWithheld: 0,
+ description: null
+ };
+
+ jest.spyOn(controller.vnApp, 'showError');
+ controller.onResponse();
+
+ expect(controller.vnApp.showError).toHaveBeenCalledWith(`The description can't be empty`);
+ });
+ });
});
});
+
diff --git a/modules/invoiceIn/front/tax/locale/es.yml b/modules/invoiceIn/front/tax/locale/es.yml
new file mode 100644
index 0000000000..3ff68ea402
--- /dev/null
+++ b/modules/invoiceIn/front/tax/locale/es.yml
@@ -0,0 +1,7 @@
+Create expense: Crear gasto
+New expense: Nuevo gasto
+It's a withholding: Es una retención
+The fields can't be empty: Los campos no pueden estar vacíos
+The code can't be empty: El código no puede estar vacío
+The description can't be empty: La descripción no puede estar vacía
+Expense saved!: Gasto guardado!
\ No newline at end of file
diff --git a/modules/invoiceOut/back/models/invoice-out.json b/modules/invoiceOut/back/models/invoice-out.json
index 45c4c27747..2bf5182e83 100644
--- a/modules/invoiceOut/back/models/invoice-out.json
+++ b/modules/invoiceOut/back/models/invoice-out.json
@@ -9,21 +9,21 @@
"properties": {
"id": {
"id": true,
- "type": "Number",
+ "type": "number",
"description": "Identifier"
},
"ref": {
- "type": "String",
+ "type": "string",
"required": true
},
"serial": {
- "type": "String"
+ "type": "string"
},
"issued": {
"type": "date"
},
"amount": {
- "type": "Number"
+ "type": "number"
},
"created": {
"type": "date"
@@ -35,7 +35,7 @@
"type": "date"
},
"hasPdf": {
- "type": "Boolean"
+ "type": "boolean"
}
},
"relations": {
diff --git a/modules/invoiceOut/back/models/tax-class.json b/modules/invoiceOut/back/models/tax-class.json
index fa56764667..a259b874a4 100644
--- a/modules/invoiceOut/back/models/tax-class.json
+++ b/modules/invoiceOut/back/models/tax-class.json
@@ -8,16 +8,16 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"description": "Identifier",
"id": true
},
"description": {
- "type": "String",
+ "type": "string",
"required": true
},
"code": {
- "type": "String",
+ "type": "string",
"required": true
}
},
diff --git a/modules/invoiceOut/back/models/tax-code.json b/modules/invoiceOut/back/models/tax-code.json
index dfd69139e0..b515ca3349 100644
--- a/modules/invoiceOut/back/models/tax-code.json
+++ b/modules/invoiceOut/back/models/tax-code.json
@@ -8,7 +8,7 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "Identifier"
},
@@ -16,7 +16,7 @@
"type": "date"
},
"code": {
- "type": "String"
+ "type": "string"
},
"rate": {
"type": "number"
@@ -25,10 +25,10 @@
"type": "number"
},
"type": {
- "type": "String"
+ "type": "string"
},
"isActive": {
- "type": "Boolean"
+ "type": "boolean"
}
},
"relations": {
diff --git a/modules/invoiceOut/back/models/tax-type.json b/modules/invoiceOut/back/models/tax-type.json
index 4e30446b07..46a73835d4 100644
--- a/modules/invoiceOut/back/models/tax-type.json
+++ b/modules/invoiceOut/back/models/tax-type.json
@@ -8,21 +8,21 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "Identifier"
},
"nickname": {
- "type": "String"
+ "type": "string"
},
"serial": {
- "type": "String"
+ "type": "string"
},
"TIPOOPE": {
- "type": "String"
+ "type": "string"
},
"description": {
- "type": "String"
+ "type": "string"
}
},
"relations": {
diff --git a/modules/invoiceOut/front/descriptor-menu/index.html b/modules/invoiceOut/front/descriptor-menu/index.html
index 859486ab17..ef4c9a62ed 100644
--- a/modules/invoiceOut/front/descriptor-menu/index.html
+++ b/modules/invoiceOut/front/descriptor-menu/index.html
@@ -76,6 +76,13 @@
translate>
Show CITES letter
+
+ Refund
+