Merge branch 'dev' into 6321_negative_tickets
gitea/salix/pipeline/pr-dev This commit looks good
Details
gitea/salix/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
commit
55eb882754
|
@ -1945,9 +1945,9 @@ INSERT INTO `vn`.`claimEnd`(`id`, `saleFk`, `claimFk`, `workerFk`, `claimDestina
|
||||||
(1, 31, 4, 21, 2),
|
(1, 31, 4, 21, 2),
|
||||||
(2, 32, 3, 21, 3);
|
(2, 32, 3, 21, 3);
|
||||||
|
|
||||||
INSERT INTO `vn`.`claimConfig`(`id`, `maxResponsibility`, `monthsToRefund`, `minShipped`)
|
INSERT INTO `vn`.`claimConfig`(`id`, `maxResponsibility`, `monthsToRefund`, `minShipped`,`daysToClaim`)
|
||||||
VALUES
|
VALUES
|
||||||
(1, 5, 4, '2016-10-01');
|
(1, 5, 4, '2016-10-01', 7);
|
||||||
|
|
||||||
INSERT INTO `vn`.`claimRatio`(`clientFk`, `yearSale`, `claimAmount`, `claimingRate`, `priceIncreasing`, `packingRate`)
|
INSERT INTO `vn`.`claimRatio`(`clientFk`, `yearSale`, `claimAmount`, `claimingRate`, `priceIncreasing`, `packingRate`)
|
||||||
VALUES
|
VALUES
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
-- Place your SQL code here
|
||||||
|
ALTER TABLE vn.claimConfig ADD IF NOT EXISTS daysToClaim int(11) NOT NULL DEFAULT 7 COMMENT 'Dias para reclamar';
|
|
@ -4,7 +4,7 @@ const LoopBackContext = require('loopback-context');
|
||||||
describe('ClaimBeginning model()', () => {
|
describe('ClaimBeginning model()', () => {
|
||||||
const claimFk = 1;
|
const claimFk = 1;
|
||||||
const activeCtx = {
|
const activeCtx = {
|
||||||
accessToken: {userId: 18},
|
accessToken: {userId: 72},
|
||||||
headers: {origin: 'localhost:5000'},
|
headers: {origin: 'localhost:5000'},
|
||||||
__: () => {}
|
__: () => {}
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,22 +3,18 @@ const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('Claim createFromSales()', () => {
|
describe('Claim createFromSales()', () => {
|
||||||
const ticketId = 23;
|
const ticketId = 23;
|
||||||
const newSale = [{
|
const newSale = [{id: 31, instance: 0, quantity: 10}];
|
||||||
id: 31,
|
let activeCtx;
|
||||||
instance: 0,
|
let ctx;
|
||||||
quantity: 10
|
|
||||||
}];
|
|
||||||
const activeCtx = {
|
|
||||||
accessToken: {userId: 1},
|
|
||||||
headers: {origin: 'localhost:5000'},
|
|
||||||
__: () => {}
|
|
||||||
};
|
|
||||||
|
|
||||||
const ctx = {
|
|
||||||
req: activeCtx
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
activeCtx = {
|
||||||
|
accessToken: {userId: 72},
|
||||||
|
headers: {origin: 'localhost:5000'},
|
||||||
|
__: () => {}
|
||||||
|
};
|
||||||
|
ctx = {req: activeCtx};
|
||||||
|
|
||||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
active: activeCtx
|
active: activeCtx
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
const LoopBackContext = require('loopback-context');
|
const LoopBackContext = require('loopback-context');
|
||||||
|
const moment = require('moment');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
require('../methods/claim-beginning/importToNewRefundTicket')(Self);
|
require('../methods/claim-beginning/importToNewRefundTicket')(Self);
|
||||||
|
@ -13,10 +14,51 @@ module.exports = Self => {
|
||||||
const options = ctx.options;
|
const options = ctx.options;
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const saleFk = ctx?.currentInstance?.saleFk || ctx?.instance?.saleFk;
|
const saleFk = ctx?.currentInstance?.saleFk || ctx?.instance?.saleFk;
|
||||||
|
const claimFk = ctx?.instance?.claimFk || ctx?.currentInstance?.claimFk;
|
||||||
|
const myOptions = {};
|
||||||
|
const accessToken = ctx?.options?.accessToken || LoopBackContext.getCurrentContext().active.accessToken;
|
||||||
|
const ctxToken = {req: {accessToken}};
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
const sale = await models.Sale.findById(saleFk, {fields: ['ticketFk', 'quantity']}, options);
|
const sale = await models.Sale.findById(saleFk, {fields: ['ticketFk', 'quantity']}, options);
|
||||||
|
|
||||||
|
const canCreateClaimAfterDeadline = models.ACL.checkAccessAcl(
|
||||||
|
ctxToken,
|
||||||
|
'Claim',
|
||||||
|
'createAfterDeadline',
|
||||||
|
myOptions
|
||||||
|
);
|
||||||
|
|
||||||
|
const canUpdateClaim = models.ACL.checkAccessAcl(
|
||||||
|
ctxToken,
|
||||||
|
'Claim',
|
||||||
|
'updateClaim',
|
||||||
|
myOptions
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!canUpdateClaim && !canCreateClaimAfterDeadline)
|
||||||
|
throw new UserError(`You don't have permission to modify this claim`);
|
||||||
|
|
||||||
|
if (canUpdateClaim) {
|
||||||
|
const query = `
|
||||||
|
SELECT daysToClaim
|
||||||
|
FROM vn.claimConfig`;
|
||||||
|
const res = await Self.rawSql(query);
|
||||||
|
const daysToClaim = res[0]?.daysToClaim;
|
||||||
|
|
||||||
|
const claim = await models.Claim.findById(claimFk, {fields: ['created']}, options);
|
||||||
|
const claimDate = moment.utc(claim.created);
|
||||||
|
const currentDate = moment.utc();
|
||||||
|
const daysSinceSale = currentDate.diff(claimDate, 'days');
|
||||||
|
|
||||||
|
if (daysSinceSale > daysToClaim && !canCreateClaimAfterDeadline)
|
||||||
|
throw new UserError(`You can't modify this claim because the deadline has already passed`);
|
||||||
|
}
|
||||||
|
|
||||||
if (ctx.isNewInstance) {
|
if (ctx.isNewInstance) {
|
||||||
const claim = await models.Claim.findById(ctx.instance.claimFk, {fields: ['ticketFk']}, options);
|
const claim = await models.Claim.findById(claimFk, {fields: ['ticketFk']}, options);
|
||||||
if (sale.ticketFk != claim.ticketFk)
|
if (sale.ticketFk != claim.ticketFk)
|
||||||
throw new UserError(`Cannot create a new claimBeginning from a different ticket`);
|
throw new UserError(`Cannot create a new claimBeginning from a different ticket`);
|
||||||
}
|
}
|
||||||
|
@ -41,7 +83,7 @@ module.exports = Self => {
|
||||||
if (ctx.options && ctx.options.transaction)
|
if (ctx.options && ctx.options.transaction)
|
||||||
myOptions.transaction = ctx.options.transaction;
|
myOptions.transaction = ctx.options.transaction;
|
||||||
|
|
||||||
const claimBeginning = ctx.instance ?? await Self.findById(ctx.where.id);
|
const claimBeginning = ctx.instance ?? await Self.findById(ctx?.where?.id);
|
||||||
|
|
||||||
const filter = {
|
const filter = {
|
||||||
where: {id: claimBeginning.claimFk},
|
where: {id: claimBeginning.claimFk},
|
||||||
|
|
|
@ -30,7 +30,6 @@ module.exports = Self => {
|
||||||
SELECT
|
SELECT
|
||||||
s.id AS saleFk,
|
s.id AS saleFk,
|
||||||
t.id AS ticketFk,
|
t.id AS ticketFk,
|
||||||
t.landed,
|
|
||||||
s.concept,
|
s.concept,
|
||||||
s.itemFk,
|
s.itemFk,
|
||||||
s.quantity,
|
s.quantity,
|
||||||
|
@ -41,11 +40,10 @@ module.exports = Self => {
|
||||||
INNER JOIN vn.sale s ON s.ticketFk = t.id
|
INNER JOIN vn.sale s ON s.ticketFk = t.id
|
||||||
LEFT JOIN vn.claimBeginning cb ON cb.saleFk = s.id
|
LEFT JOIN vn.claimBeginning cb ON cb.saleFk = s.id
|
||||||
|
|
||||||
WHERE (t.landed) >= TIMESTAMPADD(DAY, -7, ?)
|
WHERE t.id = ?
|
||||||
AND t.id = ? AND cb.id IS NULL
|
AND cb.id IS NULL`;
|
||||||
ORDER BY t.landed DESC, t.id DESC`;
|
|
||||||
|
|
||||||
const claimableSales = await Self.rawSql(query, [date, ticketFk], myOptions);
|
const claimableSales = await Self.rawSql(query, [ticketFk], myOptions);
|
||||||
|
|
||||||
return claimableSales;
|
return claimableSales;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "salix-back",
|
"name": "salix-back",
|
||||||
"version": "25.06.0",
|
"version": "25.08.0",
|
||||||
"author": "Verdnatura Levante SL",
|
"author": "Verdnatura Levante SL",
|
||||||
"description": "Salix backend",
|
"description": "Salix backend",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
|
|
Loading…
Reference in New Issue