3427-ticket_line-abono #827

Merged
carlosjr merged 6 commits from 3427-ticket_line-abono into dev 2021-12-24 09:14:37 +00:00
10 changed files with 56 additions and 27 deletions
Showing only changes of commit 5c899d28c3 - Show all commits

View File

@ -1,2 +1,2 @@
INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId)
VALUES ('Sale','payment','WRITE','ALLOW','ROLE','employee');
VALUES ('Sale','payBack','WRITE','ALLOW','ROLE','employee');

View File

@ -558,7 +558,7 @@ export default {
moreMenuUnmarkReseved: 'vn-item[name="unreserve"]',
moreMenuUpdateDiscount: 'vn-item[name="discount"]',
moreMenuRecalculatePrice: 'vn-item[name="calculatePrice"]',
moreMenuPayment: 'vn-item[name="payment"]',
moreMenuPayBack: 'vn-item[name="payBack"]',
moreMenuUpdateDiscountInput: 'vn-input-number[ng-model="$ctrl.edit.discount"] input',
transferQuantityInput: '.vn-popover.shown vn-table > div > vn-tbody > vn-tr > vn-td-editable > span > text',
transferQuantityCell: '.vn-popover.shown vn-table > div > vn-tbody > vn-tr > vn-td-editable',

View File

@ -206,7 +206,16 @@ describe('Ticket Edit sale path', () => {
expect(message.text).toContain('Data saved!');
});
it('should select the third sale and create a pay back', async() => {
await page.waitToClick(selectors.ticketSales.firstSaleCheckbox);
await page.waitToClick(selectors.ticketSales.moreMenu);
await page.waitToClick(selectors.ticketSales.moreMenuPayBack);
await page.waitForState('ticket.card.sale');
});
it('should select the third sale and create a claim of it', async() => {
await page.accessToSearchResult('16');
await page.accessToSection('ticket.card.sale');
await page.waitToClick(selectors.ticketSales.thirdSaleCheckbox);
await page.waitToClick(selectors.ticketSales.moreMenu);
await page.waitToClick(selectors.ticketSales.moreMenuCreateClaim);

View File

@ -1,5 +1,5 @@
module.exports = Self => {
Self.remoteMethodCtx('payment', {
Self.remoteMethodCtx('payBack', {
description: 'Create ticket with the selected lines changing the sign to the quantites',
accessType: 'WRITE',
accepts: [{
@ -19,12 +19,12 @@ module.exports = Self => {
root: true
},
http: {
path: `/payment`,
path: `/payBack`,
verb: 'post'
}
});
Self.payment = async(ctx, sales, ticketId, options) => {
Self.payBack = async(ctx, sales, ticketId, options) => {
const myOptions = {};
let tx;
@ -58,7 +58,6 @@ module.exports = Self => {
await Self.rawSql(query, salesIds, myOptions);
const [newTicket] = await Self.rawSql('SELECT @newTicket id', null, myOptions);
ticketId = newTicket.id;
console.log(ticketId);
/*
const message = $t('Deleted sales from ticket', {
ticketId: ticketId,

View File

@ -0,0 +1,26 @@
const models = require('vn-loopback/server/server').models;
describe('sale payBack()', () => {
it('should create ticket with the selected lines changing the sign to the quantites', async() => {
const tx = await models.Sale.beginTransaction({});
const ticketId = 11;
const sales = [
{id: 7, ticketFk: 11},
{id: 8, ticketFk: 11}
];
try {
const options = {transaction: tx};
const ctx = {req: {accessToken: {userId: 9}}};
const response = await models.Sale.payBack(ctx, sales, ticketId, options);
const [newTicketId] = await models.Sale.rawSql('SELECT MAX(t.id) id FROM vn.ticket t;', null, options);
expect(response).toEqual(newTicketId.id);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});

View File

@ -6,7 +6,7 @@ module.exports = Self => {
require('../methods/sale/updateQuantity')(Self);
require('../methods/sale/updateConcept')(Self);
require('../methods/sale/recalculatePrice')(Self);
require('../methods/sale/payment')(Self);
require('../methods/sale/payBack')(Self);
require('../methods/sale/canEdit')(Self);
Self.validatesPresenceOf('concept', {

View File

@ -491,8 +491,8 @@
Unmark as reserved
</vn-item>
<vn-item translate
name="payment"
ng-click="$ctrl.createPayment()">
Payment
name="payBack"
ng-click="$ctrl.createPayBack()">
Pay Back
</vn-item>
</vn-menu>

View File

@ -460,12 +460,12 @@ class Controller extends Section {
});
}
createPayment() {
createPayBack() {
const sales = this.selectedValidSales();
if (!sales) return;
const params = {sales: sales, ticketId: this.ticket.id};
const query = `Sales/payment`;
const query = `Sales/payBack`;
this.resetChanges();
this.$http.post(query, params).then(res => {
this.$state.go('ticket.card.sale', {id: res.data});

View File

@ -2,7 +2,7 @@ import './index.js';
import watcher from 'core/mocks/watcher';
import crudModel from 'core/mocks/crud-model';
describe('Ticket', () => {
fdescribe('Ticket', () => {
describe('Component vnTicketSale', () => {
let controller;
let $scope;
@ -701,24 +701,19 @@ describe('Ticket', () => {
});
});
describe('createPayment()', () => {
describe('createPayBack()', () => {
it('should make an HTTP POST query and then call to the $state go() method', () => {
jest.spyOn(controller, 'resetChanges').mockReturnThis();
jest.spyOn(controller.$state, 'go').mockReturnThis();
jest.spyOn(controller, 'selectedValidSales').mockReturnValue(controller.sales);
jest.spyOn(controller, 'resetChanges');
jest.spyOn(controller.$state, 'go');
const ticketId = 13;
const expectedResponse = {id: ticketId};
const params = {
sales: controller.sales,
ticketId: 13
};
$httpBackend.expect('POST', `Sales/payment`, params).respond(expectedResponse);
controller.createPayment();
const expectedId = 9999;
$httpBackend.expect('POST', `Sales/payBack`).respond(200, expectedId);
controller.createPayBack();
$httpBackend.flush();
expect(controller.resetChanges).toHaveBeenCalledWith();
expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.sale', {id: ticketId});
expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.sale', {id: expectedId});
});
});

View File

@ -36,4 +36,4 @@ Warehouse: Almacen
Agency: Agencia
Shipped: F. envio
Packaging: Encajado
Payment: Abono
Pay Back: Abono