#6403 - mrwIntegration #2005

Merged
pablone merged 15 commits from 6403-mrwIntegration into master 2024-02-23 08:54:44 +00:00
6 changed files with 56 additions and 8 deletions
Showing only changes of commit 8182809d8a - Show all commits

View File

@ -22,7 +22,7 @@ module.exports = Self => {
const {url} = await Self.app.models.Url.findOne({ const {url} = await Self.app.models.Url.findOne({
where: { where: {
appName, appName,
enviroment: process.env.NODE_ENV || 'development' environment: process.env.NODE_ENV || 'development'
} }
}); });
return url; return url;

View File

@ -1,11 +1,7 @@
const models = require('vn-loopback/server/server').models; const models = require('vn-loopback/server/server').models;
describe('sale usesMana()', () => { describe('sale usesMana()', () => {
const ctx = { const ctx = {req: { accessToken: {userId: 18}}};
req: {
accessToken: {userId: 18}
}
};
it('should return that the worker uses mana', async() => { it('should return that the worker uses mana', async() => {
const tx = await models.Sale.beginTransaction({}); const tx = await models.Sale.beginTransaction({});
@ -45,4 +41,27 @@ describe('sale usesMana()', () => {
throw e; throw e;
} }
}); });
it('should return that the worker does not use mana because it is excluded', async() => {
const tx = await models.Sale.beginTransaction({});
const buyerId = 35;
const franceDepartmentId = 133;
const buyerCtx = {req: {accessToken: {userId: buyerId}}};
try {
const options = {transaction: tx}
await models.WorkerManaExcluded.create({workerFk: buyerId}, options);
await models.Business.updateAll({workerFk: buyerId}, {departmentFk: franceDepartmentId}, options);
const usesMana = await models.Sale.usesMana(buyerCtx, options);
expect(usesMana).toBe(false);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
}); });

View File

@ -21,6 +21,9 @@ module.exports = Self => {
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
const isManaExcluded = await models.WorkerManaExcluded.findById(userId, null, myOptions);
if (isManaExcluded) return false;
const salesDepartment = await models.Department.findOne({where: {code: 'VT'}, fields: 'id'}, myOptions); const salesDepartment = await models.Department.findOne({where: {code: 'VT'}, fields: 'id'}, myOptions);
const departments = await models.Department.getLeaves(ctx, salesDepartment.id, null, myOptions); const departments = await models.Department.getLeaves(ctx, salesDepartment.id, null, myOptions);
const workerDepartment = await models.WorkerDepartment.findById(userId, null, myOptions); const workerDepartment = await models.WorkerDepartment.findById(userId, null, myOptions);

View File

@ -137,7 +137,8 @@ module.exports = Self => {
tb.type, tb.type,
tb.businessFk, tb.businessFk,
tb.permissionRate, tb.permissionRate,
d.isTeleworking d.isTeleworking,
d.hasToRefill
FROM tmp.timeBusinessCalculate tb FROM tmp.timeBusinessCalculate tb
JOIN account.user u ON u.id = tb.userFk JOIN account.user u ON u.id = tb.userFk
JOIN department d ON d.id = tb.departmentFk JOIN department d ON d.id = tb.departmentFk
@ -174,7 +175,7 @@ module.exports = Self => {
myOptions.transaction = tx; myOptions.transaction = tx;
try { try {
workerFk = day.workerFk; workerFk = day.workerFk;
if (day.timeWorkDecimal > 0 && day.timeWorkedDecimal == null if (day.hasToRefill && day.timeWorkDecimal > 0 && day.timeWorkedDecimal == null
&& (day.permissionRate == null ? true : day.permissionRate)) { && (day.permissionRate == null ? true : day.permissionRate)) {
if (day.timeTable == null) { if (day.timeTable == null) {
const timed = new Date(day.dated); const timed = new Date(day.dated);

View File

@ -86,6 +86,9 @@
"WorkerMana": { "WorkerMana": {
"dataSource": "vn" "dataSource": "vn"
}, },
"WorkerManaExcluded": {
"dataSource": "vn"
},
"WorkerMistake": { "WorkerMistake": {
"dataSource": "vn" "dataSource": "vn"
}, },

View File

@ -0,0 +1,22 @@
{
"name": "WorkerManaExcluded",
"base": "VnModel",
"options": {
"mysql": {
"table": "workerManaExcluded"
}
},
"properties": {
"workerFk": {
"id": true,
"type": "number"
}
},
"relations": {
"worker": {
"type": "belongsTo",
"model": "Worker",
"foreignKey": "workerFk"
}
}
}