Merge branch 'dev' into 6321_negative_tickets
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Javier Segarra 2025-02-04 23:42:47 +01:00
commit 55eb882754
7 changed files with 63 additions and 25 deletions

View File

@ -1945,9 +1945,9 @@ INSERT INTO `vn`.`claimEnd`(`id`, `saleFk`, `claimFk`, `workerFk`, `claimDestina
(1, 31, 4, 21, 2),
(2, 32, 3, 21, 3);
INSERT INTO `vn`.`claimConfig`(`id`, `maxResponsibility`, `monthsToRefund`, `minShipped`)
INSERT INTO `vn`.`claimConfig`(`id`, `maxResponsibility`, `monthsToRefund`, `minShipped`,`daysToClaim`)
VALUES
(1, 5, 4, '2016-10-01');
(1, 5, 4, '2016-10-01', 7);
INSERT INTO `vn`.`claimRatio`(`clientFk`, `yearSale`, `claimAmount`, `claimingRate`, `priceIncreasing`, `packingRate`)
VALUES

View File

@ -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';

View File

@ -4,7 +4,7 @@ const LoopBackContext = require('loopback-context');
describe('ClaimBeginning model()', () => {
const claimFk = 1;
const activeCtx = {
accessToken: {userId: 18},
accessToken: {userId: 72},
headers: {origin: 'localhost:5000'},
__: () => {}
};

View File

@ -3,22 +3,18 @@ const LoopBackContext = require('loopback-context');
describe('Claim createFromSales()', () => {
const ticketId = 23;
const newSale = [{
id: 31,
instance: 0,
quantity: 10
}];
const activeCtx = {
accessToken: {userId: 1},
headers: {origin: 'localhost:5000'},
__: () => {}
};
const ctx = {
req: activeCtx
};
const newSale = [{id: 31, instance: 0, quantity: 10}];
let activeCtx;
let ctx;
beforeEach(() => {
activeCtx = {
accessToken: {userId: 72},
headers: {origin: 'localhost:5000'},
__: () => {}
};
ctx = {req: activeCtx};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});

View File

@ -1,6 +1,7 @@
const UserError = require('vn-loopback/util/user-error');
const LoopBackContext = require('loopback-context');
const moment = require('moment');
module.exports = Self => {
require('../methods/claim-beginning/importToNewRefundTicket')(Self);
@ -13,10 +14,51 @@ module.exports = Self => {
const options = ctx.options;
const models = Self.app.models;
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 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) {
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)
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)
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 = {
where: {id: claimBeginning.claimFk},

View File

@ -30,7 +30,6 @@ module.exports = Self => {
SELECT
s.id AS saleFk,
t.id AS ticketFk,
t.landed,
s.concept,
s.itemFk,
s.quantity,
@ -41,11 +40,10 @@ module.exports = Self => {
INNER JOIN vn.sale s ON s.ticketFk = t.id
LEFT JOIN vn.claimBeginning cb ON cb.saleFk = s.id
WHERE (t.landed) >= TIMESTAMPADD(DAY, -7, ?)
AND t.id = ? AND cb.id IS NULL
ORDER BY t.landed DESC, t.id DESC`;
WHERE t.id = ?
AND cb.id IS NULL`;
const claimableSales = await Self.rawSql(query, [date, ticketFk], myOptions);
const claimableSales = await Self.rawSql(query, [ticketFk], myOptions);
return claimableSales;
};

View File

@ -1,6 +1,6 @@
{
"name": "salix-back",
"version": "25.06.0",
"version": "25.08.0",
"author": "Verdnatura Levante SL",
"description": "Salix backend",
"license": "GPL-3.0",