Merge pull request 'refs #5115 transfer_sales' (!1344) from 5115-transfer_sales into dev
gitea/salix/pipeline/head Build queued... Details

Reviewed-on: #1344
Reviewed-by: Joan Sanchez <joan@verdnatura.es>
This commit is contained in:
Joan Sanchez 2023-03-02 06:31:20 +00:00
commit 32b3284e40
2 changed files with 1 additions and 30 deletions

View File

@ -80,34 +80,6 @@ describe('sale transferSales()', () => {
expect(error.message).toEqual(`Can't transfer claimed sales`); expect(error.message).toEqual(`Can't transfer claimed sales`);
}); });
it('should be able to transfer claimed sales if the role is claimManager', async() => {
const tx = await models.Ticket.beginTransaction({});
let error;
try {
const options = {transaction: tx};
const claimManagerId = 72;
const myActiveCtx = {
accessToken: {userId: claimManagerId},
};
const myCtx = {req: myActiveCtx};
const ticketId = 11;
const receiverTicketId = null;
const sales = await models.Ticket.getSales(ticketId, options);
await models.Ticket.transferSales(myCtx, ticketId, receiverTicketId, sales, options);
await tx.rollback();
} catch (e) {
await tx.rollback();
error = e;
}
expect(error).toBeUndefined();
});
it('should transfer the sales from a ticket to a new one', async() => { it('should transfer the sales from a ticket to a new one', async() => {
const tx = await models.Ticket.beginTransaction({}); const tx = await models.Ticket.beginTransaction({});

View File

@ -77,9 +77,8 @@ module.exports = Self => {
const saleIds = sales.map(sale => sale.id); const saleIds = sales.map(sale => sale.id);
const isClaimManager = await models.Account.hasRole(userId, 'claimManager');
const hasClaimedSales = await models.ClaimBeginning.findOne({where: {saleFk: {inq: saleIds}}}); const hasClaimedSales = await models.ClaimBeginning.findOne({where: {saleFk: {inq: saleIds}}});
if (hasClaimedSales && !isClaimManager) if (hasClaimedSales)
throw new UserError(`Can't transfer claimed sales`); throw new UserError(`Can't transfer claimed sales`);
for (const sale of sales) { for (const sale of sales) {