Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 2764-Ticket_sale_consignee
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
commit
2296727f8d
|
@ -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,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,
|
||||||
|
|
Loading…
Reference in New Issue