Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 2583-create_account_supplier
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
commit
29ca6c52af
|
@ -110,11 +110,10 @@ module.exports = Self => {
|
||||||
async function createDms(ctx, file, myOptions) {
|
async function createDms(ctx, file, myOptions) {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const myUserId = ctx.req.accessToken.userId;
|
const myUserId = ctx.req.accessToken.userId;
|
||||||
const myWorker = await models.Worker.findOne({where: {userFk: myUserId}}, myOptions);
|
|
||||||
const args = ctx.args;
|
const args = ctx.args;
|
||||||
|
|
||||||
const newDms = await Self.create({
|
const newDms = await Self.create({
|
||||||
workerFk: myWorker.id,
|
workerFk: myUserId,
|
||||||
dmsTypeFk: args.dmsTypeId,
|
dmsTypeFk: args.dmsTypeId,
|
||||||
companyFk: args.companyId,
|
companyFk: args.companyId,
|
||||||
warehouseFk: args.warehouseId,
|
warehouseFk: args.warehouseId,
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
||||||
VALUES
|
VALUES
|
||||||
('SupplierAccount', '*', '*', 'ALLOW', 'ROLE', 'administrative');
|
('SupplierAccount', '*', '*', 'ALLOW', 'ROLE', 'administrative'),
|
||||||
|
('Entry', '*', '*', 'ALLOW', 'ROLE', 'administrative');
|
||||||
|
|
|
@ -167,12 +167,12 @@
|
||||||
"You can't upload images on the test environment": "No puedes subir imágenes en el entorno de pruebas",
|
"You can't upload images on the test environment": "No puedes subir imágenes en el entorno de pruebas",
|
||||||
"The selected ticket is not suitable for this route": "El ticket seleccionado no es apto para esta ruta",
|
"The selected ticket is not suitable for this route": "El ticket seleccionado no es apto para esta ruta",
|
||||||
"Sorts whole route": "Reordena ruta entera",
|
"Sorts whole route": "Reordena ruta entera",
|
||||||
"Invalid account": "Cuenta inválida",
|
"New ticket request has been created with price": "Se ha creado una nueva petición de compra '{{description}}' para el día <strong>{{shipped}}</strong>, con una cantidad de <strong>{{quantity}}</strong> y un precio de <strong>{{price}} €</strong>",
|
||||||
"New ticket request has been created with price": "Se ha creado una nueva petición de compra *'{{description}}'* para el día *{{shipped}}*, con una cantidad de *{{quantity}}* y un precio de *{{price}} €*",
|
"New ticket request has been created": "Se ha creado una nueva petición de compra '{{description}}' para el día <strong>{{shipped}}</strong>, con una cantidad de <strong>{{quantity}}</strong>",
|
||||||
"New ticket request has been created": "Se ha creado una nueva petición de compra *'{{description}}'* para el día *{{shipped}}*, con una cantidad de *{{quantity}}*",
|
"Swift / BIC cannot be empty": "Swift / BIC no puede estar vacío",
|
||||||
|
"This BIC already exist.": "Este BIC ya existe.",
|
||||||
"That item doesn't exists": "Ese artículo no existe",
|
"That item doesn't exists": "Ese artículo no existe",
|
||||||
"There's a new urgent ticket": "Hay un nuevo ticket urgente: [{{title}}](https://cau.verdnatura.es/WorkOrder.do?woMode=viewWO&woID={{issueId}})",
|
"There's a new urgent ticket": "Hay un nuevo ticket urgente: [{{title}}](https://cau.verdnatura.es/WorkOrder.do?woMode=viewWO&woID={{issueId}})",
|
||||||
"Compensation account is empty": "La cuenta para compensar está vacia",
|
"Invalid account": "Cuenta inválida",
|
||||||
"Swift / BIC cannot be empty": "Swift / BIC cannot be empty",
|
"Compensation account is empty": "La cuenta para compensar está vacia"
|
||||||
"This BIC already exist.": "This BIC already exist."
|
|
||||||
}
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const app = require('vn-loopback/server/server');
|
||||||
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('Client createReceipt', () => {
|
describe('Client createReceipt', () => {
|
||||||
const clientFk = 108;
|
const clientFk = 108;
|
||||||
|
@ -6,18 +7,34 @@ describe('Client createReceipt', () => {
|
||||||
const companyFk = 442;
|
const companyFk = 442;
|
||||||
const amountPaid = 12.50;
|
const amountPaid = 12.50;
|
||||||
const description = 'Receipt description';
|
const description = 'Receipt description';
|
||||||
|
const activeCtx = {
|
||||||
|
accessToken: {userId: 5},
|
||||||
|
http: {
|
||||||
|
req: {
|
||||||
|
headers: {origin: 'http://localhost'}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const ctx = {req: activeCtx};
|
||||||
|
activeCtx.http.req.__ = value => {
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
|
active: activeCtx
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should create a new receipt', async() => {
|
it('should create a new receipt', async() => {
|
||||||
const bankFk = 1;
|
const bankFk = 1;
|
||||||
let ctx = {
|
ctx.args = {
|
||||||
args: {
|
clientFk: clientFk,
|
||||||
clientFk: clientFk,
|
payed: payed,
|
||||||
payed: payed,
|
companyFk: companyFk,
|
||||||
companyFk: companyFk,
|
bankFk: bankFk,
|
||||||
bankFk: bankFk,
|
amountPaid: amountPaid,
|
||||||
amountPaid: amountPaid,
|
description: description
|
||||||
description: description
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const receipt = await app.models.Client.createReceipt(ctx);
|
const receipt = await app.models.Client.createReceipt(ctx);
|
||||||
|
@ -40,15 +57,14 @@ describe('Client createReceipt', () => {
|
||||||
|
|
||||||
it('should throw Compensation account is empty', async() => {
|
it('should throw Compensation account is empty', async() => {
|
||||||
const bankFk = 3;
|
const bankFk = 3;
|
||||||
let ctx = {
|
|
||||||
args: {
|
ctx.args = {
|
||||||
clientFk: clientFk,
|
clientFk: clientFk,
|
||||||
payed: payed,
|
payed: payed,
|
||||||
companyFk: companyFk,
|
companyFk: companyFk,
|
||||||
bankFk: bankFk,
|
bankFk: bankFk,
|
||||||
amountPaid: amountPaid,
|
amountPaid: amountPaid,
|
||||||
description: description
|
description: description
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -64,16 +80,14 @@ describe('Client createReceipt', () => {
|
||||||
it('should throw Invalid account if compensationAccount does not belongs to a client nor a supplier', async() => {
|
it('should throw Invalid account if compensationAccount does not belongs to a client nor a supplier', async() => {
|
||||||
let error;
|
let error;
|
||||||
const bankFk = 3;
|
const bankFk = 3;
|
||||||
const ctx = {
|
ctx.args = {
|
||||||
args: {
|
clientFk: clientFk,
|
||||||
clientFk: clientFk,
|
payed: payed,
|
||||||
payed: payed,
|
companyFk: companyFk,
|
||||||
companyFk: companyFk,
|
bankFk: bankFk,
|
||||||
bankFk: bankFk,
|
amountPaid: amountPaid,
|
||||||
amountPaid: amountPaid,
|
description: description,
|
||||||
description: description,
|
compensationAccount: 'non existing account'
|
||||||
compensationAccount: 'non existing account'
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -88,16 +102,15 @@ describe('Client createReceipt', () => {
|
||||||
|
|
||||||
it('should create a new receipt with a compensation for a client', async() => {
|
it('should create a new receipt with a compensation for a client', async() => {
|
||||||
const bankFk = 3;
|
const bankFk = 3;
|
||||||
const ctx = {
|
|
||||||
args: {
|
ctx.args = {
|
||||||
clientFk: clientFk,
|
clientFk: clientFk,
|
||||||
payed: payed,
|
payed: payed,
|
||||||
companyFk: companyFk,
|
companyFk: companyFk,
|
||||||
bankFk: bankFk,
|
bankFk: bankFk,
|
||||||
amountPaid: amountPaid,
|
amountPaid: amountPaid,
|
||||||
description: description,
|
description: description,
|
||||||
compensationAccount: '4300000001'
|
compensationAccount: '4300000001'
|
||||||
}
|
|
||||||
};
|
};
|
||||||
const receipt = await app.models.Client.createReceipt(ctx);
|
const receipt = await app.models.Client.createReceipt(ctx);
|
||||||
const receiptCompensated = await app.models.Receipt.findOne({
|
const receiptCompensated = await app.models.Receipt.findOne({
|
||||||
|
@ -127,16 +140,16 @@ describe('Client createReceipt', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create a new receipt with a compensation for a supplier', async() => {
|
it('should create a new receipt with a compensation for a supplier', async() => {
|
||||||
const ctx = {
|
const bankFk = 3;
|
||||||
args: {
|
|
||||||
clientFk: clientFk,
|
ctx.args = {
|
||||||
payed: payed,
|
clientFk: clientFk,
|
||||||
companyFk: companyFk,
|
payed: payed,
|
||||||
bankFk: 3,
|
companyFk: companyFk,
|
||||||
amountPaid: amountPaid,
|
bankFk: bankFk,
|
||||||
description: description,
|
amountPaid: amountPaid,
|
||||||
compensationAccount: '4100000001'
|
description: description,
|
||||||
}
|
compensationAccount: '4100000001'
|
||||||
};
|
};
|
||||||
const receipt = await app.models.Client.createReceipt(ctx);
|
const receipt = await app.models.Client.createReceipt(ctx);
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
module.exports = function(Self) {
|
module.exports = function(Self) {
|
||||||
require('../methods/receipt/filter')(Self);
|
require('../methods/receipt/filter')(Self);
|
||||||
|
|
||||||
|
@ -23,13 +25,10 @@ module.exports = function(Self) {
|
||||||
|
|
||||||
Self.observe('before save', async function(ctx) {
|
Self.observe('before save', async function(ctx) {
|
||||||
if (ctx.isNewInstance) {
|
if (ctx.isNewInstance) {
|
||||||
let token = ctx.options.accessToken;
|
const loopBackContext = LoopBackContext.getCurrentContext();
|
||||||
let userId = token && token.userId;
|
ctx.instance.workerFk = loopBackContext.active.accessToken.userId;
|
||||||
|
|
||||||
ctx.instance.workerFk = userId;
|
|
||||||
|
|
||||||
await Self.app.models.Till.create({
|
await Self.app.models.Till.create({
|
||||||
workerFk: userId,
|
workerFk: ctx.instance.workerFk,
|
||||||
bankFk: ctx.instance.bankFk,
|
bankFk: ctx.instance.bankFk,
|
||||||
in: ctx.instance.amountPaid,
|
in: ctx.instance.amountPaid,
|
||||||
concept: ctx.instance.description,
|
concept: ctx.instance.description,
|
||||||
|
|
|
@ -31,19 +31,19 @@
|
||||||
"state": "entry.index",
|
"state": "entry.index",
|
||||||
"component": "vn-entry-index",
|
"component": "vn-entry-index",
|
||||||
"description": "Entries",
|
"description": "Entries",
|
||||||
"acl": ["buyer"]
|
"acl": ["buyer", "administrative"]
|
||||||
}, {
|
}, {
|
||||||
"url": "/latest-buys?q",
|
"url": "/latest-buys?q",
|
||||||
"state": "entry.latestBuys",
|
"state": "entry.latestBuys",
|
||||||
"component": "vn-entry-latest-buys",
|
"component": "vn-entry-latest-buys",
|
||||||
"description": "Latest buys",
|
"description": "Latest buys",
|
||||||
"acl": ["buyer"]
|
"acl": ["buyer", "administrative"]
|
||||||
}, {
|
}, {
|
||||||
"url": "/create?supplierFk&travelFk&companyFk",
|
"url": "/create?supplierFk&travelFk&companyFk",
|
||||||
"state": "entry.create",
|
"state": "entry.create",
|
||||||
"component": "vn-entry-create",
|
"component": "vn-entry-create",
|
||||||
"description": "New entry",
|
"description": "New entry",
|
||||||
"acl": ["buyer"]
|
"acl": ["buyer", "administrative"]
|
||||||
}, {
|
}, {
|
||||||
"url": "/:id",
|
"url": "/:id",
|
||||||
"state": "entry.card",
|
"state": "entry.card",
|
||||||
|
|
|
@ -19,7 +19,6 @@ class Controller extends Section {
|
||||||
}
|
}
|
||||||
|
|
||||||
onResponse(response) {
|
onResponse(response) {
|
||||||
console.log(response);
|
|
||||||
const data = this.$.model.data;
|
const data = this.$.model.data;
|
||||||
const supplierAccount = data[this.currentRowIndex];
|
const supplierAccount = data[this.currentRowIndex];
|
||||||
supplierAccount.bankEntityFk = response.id;
|
supplierAccount.bankEntityFk = response.id;
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethod('getAverageDays', {
|
||||||
|
description: 'Returns the average days duration and the two warehouses of the travel.',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: [{
|
||||||
|
arg: 'agencyModeFk',
|
||||||
|
type: 'number',
|
||||||
|
required: true
|
||||||
|
}],
|
||||||
|
returns: {
|
||||||
|
type: 'number',
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/getAverageDays`,
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.getAverageDays = async agencyModeFk => {
|
||||||
|
const query = `
|
||||||
|
SELECT t.id, t.warehouseInFk, t.warehouseOutFk,
|
||||||
|
(SELECT ROUND(AVG(DATEDIFF(t.landed, t.shipped )))
|
||||||
|
FROM travel t
|
||||||
|
WHERE t.agencyFk = ? LIMIT 50) AS dayDuration
|
||||||
|
FROM travel t
|
||||||
|
WHERE t.agencyFk = ? ORDER BY t.id DESC LIMIT 1;`;
|
||||||
|
|
||||||
|
const [avgDays] = await Self.rawSql(query, [agencyModeFk, agencyModeFk]);
|
||||||
|
return avgDays;
|
||||||
|
};
|
||||||
|
};
|
|
@ -8,6 +8,7 @@ module.exports = Self => {
|
||||||
require('../methods/travel/deleteThermograph')(Self);
|
require('../methods/travel/deleteThermograph')(Self);
|
||||||
require('../methods/travel/updateThermograph')(Self);
|
require('../methods/travel/updateThermograph')(Self);
|
||||||
require('../methods/travel/extraCommunityFilter')(Self);
|
require('../methods/travel/extraCommunityFilter')(Self);
|
||||||
|
require('../methods/travel/getAverageDays')(Self);
|
||||||
require('../methods/travel/cloneWithEntries')(Self);
|
require('../methods/travel/cloneWithEntries')(Self);
|
||||||
|
|
||||||
Self.rewriteDbError(function(err) {
|
Self.rewriteDbError(function(err) {
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
<vn-date-picker
|
<vn-date-picker
|
||||||
|
on-change="$ctrl.onShippedChange(value)"
|
||||||
label="Shipped"
|
label="Shipped"
|
||||||
ng-model="$ctrl.travel.shipped">
|
ng-model="$ctrl.travel.shipped">
|
||||||
</vn-date-picker>
|
</vn-date-picker>
|
||||||
|
|
|
@ -7,6 +7,31 @@ class Controller extends Section {
|
||||||
this.travel = JSON.parse(this.$params.q);
|
this.travel = JSON.parse(this.$params.q);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onShippedChange(value) {
|
||||||
|
let hasFilledProperties;
|
||||||
|
let hasAgencyMode;
|
||||||
|
if (this.travel) {
|
||||||
|
hasAgencyMode = Boolean(this.travel.agencyModeFk);
|
||||||
|
hasFilledProperties = this.travel.landed || this.travel.warehouseInFk || this.travel.warehouseOutFk;
|
||||||
|
}
|
||||||
|
if (!hasAgencyMode || hasFilledProperties)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const query = `travels/getAverageDays`;
|
||||||
|
const params = {
|
||||||
|
agencyModeFk: this.travel.agencyModeFk
|
||||||
|
};
|
||||||
|
this.$http.get(query, {params}).then(res => {
|
||||||
|
const landed = new Date(value);
|
||||||
|
const futureDate = landed.getDate() + res.data.dayDuration;
|
||||||
|
landed.setDate(futureDate);
|
||||||
|
|
||||||
|
this.travel.landed = landed;
|
||||||
|
this.travel.warehouseInFk = res.data.warehouseInFk;
|
||||||
|
this.travel.warehouseOutFk = res.data.warehouseOutFk;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
return this.$.watcher.submit().then(
|
return this.$.watcher.submit().then(
|
||||||
res => this.$state.go('travel.card.basicData', {id: res.data.id})
|
res => this.$state.go('travel.card.basicData', {id: res.data.id})
|
||||||
|
|
|
@ -5,10 +5,12 @@ describe('Travel Component vnTravelCreate', () => {
|
||||||
let $scope;
|
let $scope;
|
||||||
let $state;
|
let $state;
|
||||||
let controller;
|
let controller;
|
||||||
|
let $httpBackend;
|
||||||
|
|
||||||
beforeEach(ngModule('travel'));
|
beforeEach(ngModule('travel'));
|
||||||
|
|
||||||
beforeEach(inject(($componentController, $rootScope, _$state_) => {
|
beforeEach(inject(($componentController, $rootScope, _$state_, _$httpBackend_) => {
|
||||||
|
$httpBackend = _$httpBackend_;
|
||||||
$scope = $rootScope.$new();
|
$scope = $rootScope.$new();
|
||||||
$state = _$state_;
|
$state = _$state_;
|
||||||
$scope.watcher = watcher;
|
$scope.watcher = watcher;
|
||||||
|
@ -38,4 +40,34 @@ describe('Travel Component vnTravelCreate', () => {
|
||||||
expect(controller.travel).toEqual(json);
|
expect(controller.travel).toEqual(json);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('onShippedChange()', () => {
|
||||||
|
it(`should do nothing if there's no agencyModeFk in the travel.`, () => {
|
||||||
|
controller.travel = {};
|
||||||
|
controller.onShippedChange();
|
||||||
|
|
||||||
|
expect(controller.travel.landed).toBeUndefined();
|
||||||
|
expect(controller.travel.warehouseInFk).toBeUndefined();
|
||||||
|
expect(controller.travel.warehouseOutFk).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should fill the fields when it's selected a date and agency.`, () => {
|
||||||
|
controller.travel = {agencyModeFk: 1};
|
||||||
|
const tomorrow = new Date();
|
||||||
|
tomorrow.setDate(tomorrow.getDate() + 1);
|
||||||
|
const expectedResponse = {
|
||||||
|
dayDuration: 2,
|
||||||
|
warehouseInFk: 1,
|
||||||
|
warehouseOutFk: 2
|
||||||
|
};
|
||||||
|
|
||||||
|
const query = `travels/getAverageDays?agencyModeFk=${controller.travel.agencyModeFk}`;
|
||||||
|
$httpBackend.expectGET(query).respond(expectedResponse);
|
||||||
|
controller.onShippedChange(tomorrow);
|
||||||
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
expect(controller.travel.warehouseInFk).toEqual(expectedResponse.warehouseInFk);
|
||||||
|
expect(controller.travel.warehouseOutFk).toEqual(expectedResponse.warehouseOutFk);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue