1368-ticket_sale_refactor #327

Merged
joan merged 20 commits from 1368-ticket_sale_refactor into dev 2020-07-02 12:58:12 +00:00
7 changed files with 53 additions and 12 deletions
Showing only changes of commit 354123dc86 - Show all commits

View File

@ -401,7 +401,7 @@ export default {
createButton: `button[type=submit]`
},
ticketDescriptor: {
idLabelValue: 'vn-ticket-descriptor vn-label-value[label="Id"]',
id: 'vn-descriptor-content div.top > div',
stateLabelValue: 'vn-ticket-descriptor vn-label-value[label="State"]',
goBackToModuleIndexButton: 'vn-ticket-descriptor a[ui-sref="ticket.index"]',
moreMenu: 'vn-ticket-descriptor vn-icon-button[icon=more_vert]',
@ -453,10 +453,11 @@ export default {
newItemFromCatalogButton: 'vn-ticket-sale vn-float-button[icon="add"]',
newItemButton: 'vn-ticket-sale vn-card vn-icon-button[icon="add_circle"]',
moreMenu: 'vn-ticket-sale vn-button[label="More"]',
moreMenuCreateClaim: '.vn-drop-down.shown li[name="Add claim"]',
moreMenuReserve: '.vn-drop-down.shown li[name="Mark as reserved"]',
moreMenuUnmarkReseved: '.vn-drop-down.shown li[name="Unmark as reserved"]',
moreMenuUpdateDiscount: '.vn-drop-down.shown li[name="Update discount"]',
moreMenuCreateClaim: 'vn-item[name="claim"]',
moreMenuReserve: 'vn-item[name="reserve"]',
moreMenuUnmarkReseved: 'vn-item[name="unreserve"]',
moreMenuUpdateDiscount: 'vn-item[name="discount"]',
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',
firstSaleId: 'vn-ticket-sale vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(4) > span',
@ -487,15 +488,16 @@ export default {
secondSaleIdInput: 'vn-ticket-sale vn-table vn-tbody > vn-tr:nth-child(2) > vn-td:nth-child(4) > vn-autocomplete',
secondSaleIdAutocomplete: 'vn-ticket-sale vn-table vn-tbody > vn-tr:nth-child(2) > vn-td:nth-child(4) > vn-autocomplete',
secondSaleQuantity: 'vn-ticket-sale vn-table vn-tr:nth-child(2) vn-input-number',
secondSaleQuantityCell: 'vn-ticket-sale > div > vn-card > vn-table > div > vn-tbody > vn-tr:nth-child(2) > vn-td-editable:nth-child(5)',
secondSaleConceptCell: 'vn-ticket-sale vn-tbody > :nth-child(2) > :nth-child(6)',
secondSaleConceptInput: 'vn-ticket-sale vn-tbody > :nth-child(2) > vn-td-editable.ng-isolate-scope.selected vn-textfield',
totalImport: 'vn-ticket-sale > vn-vertical > vn-card > vn-vertical > vn-horizontal > vn-one > p:nth-child(3) > strong',
totalImport: 'vn-ticket-sale vn-one.taxes > p:nth-child(3) > strong',
selectAllSalesCheckbox: 'vn-ticket-sale vn-thead vn-check',
secondSaleCheckbox: 'vn-ticket-sale vn-tr:nth-child(2) vn-check[ng-model="sale.checked"]',
thirdSaleCheckbox: 'vn-ticket-sale vn-tr:nth-child(3) vn-check[ng-model="sale.checked"]',
deleteSaleButton: 'vn-ticket-sale vn-tool-bar > vn-button[icon="delete"]',
transferSaleButton: 'vn-ticket-sale vn-tool-bar > vn-button[icon="call_split"]',
moveToTicketInput: '.vn-popover.shown vn-textfield[ng-model="$ctrl.transfer.ticketId"]',
moveToTicketInput: 'form vn-input-number[ng-model="$ctrl.transfer.ticketId"] input',
moveToTicketButton: '.vn-popover.shown vn-icon[icon="arrow_forward_ios"]',
moveToNewTicketButton: '.vn-popover.shown vn-button[label="New ticket"]',
acceptDeleteLineButton: '.vn-confirm.shown button[response=accept]',

View File

@ -0,0 +1,31 @@
module.exports = Self => {
Self.remoteMethod('canCreateTicket', {
description: 'Checks if the client is active',
accessType: 'READ',
accepts: [
{
arg: 'id',
type: 'string',
required: true,
description: 'The user id',
http: {source: 'path'}
}],
returns: {
type: 'boolean',
root: true
},
http: {
path: `/:id/canCreateTicket`,
verb: 'GET'
}
});
Self.canCreateTicket = async id => {
const client = await Self.app.models.Client.findById(id);
const canCreateTicket = client && client.isActive;
if (!canCreateTicket)
return false;
return true;
};
};

View File

@ -44,7 +44,7 @@ module.exports = Self => {
return role.name === 'employee';
});
if (!roleNames.length || isEmployee > -1 ) return false;
if (!roleNames.length || isEmployee > -1) return false;
return true;
};

View File

@ -11,6 +11,7 @@ module.exports = Self => {
require('../methods/client/createWithUser')(Self);
require('../methods/client/listWorkers')(Self);
require('../methods/client/hasCustomerRole')(Self);
require('../methods/client/canCreateTicket')(Self);
require('../methods/client/isValidClient')(Self);
require('../methods/client/addressesPropagateRe')(Self);
require('../methods/client/getDebt')(Self);

View File

@ -82,7 +82,8 @@ module.exports = Self => {
agencyMode = await models.AgencyMode.findById(agencyModeId);
if (address.client().type().code === 'normal' && (!agencyMode || agencyMode.code != 'refund')) {
if (!address.client().isActive)
const canCreateTicket = await models.Client.canCreateTicket(clientId);
if (!canCreateTicket)
throw new UserError(`You can't create a ticket for a inactive client`);
}

View File

@ -55,8 +55,14 @@ module.exports = Self => {
where: {ticketFk: id}
}, options);
if (!ticketId)
if (!ticketId) {
const ticket = await models.Ticket.findById(id);
const canCreateTicket = await models.Client.canCreateTicket(ticket.clientFk);
if (!canCreateTicket)
throw new UserError(`You can't create a ticket for a inactive client`);
ticketId = await cloneTicket(originalTicket, options);
}
const map = new Map();
for (const sale of originalSales)

View File

@ -417,13 +417,13 @@
Add claim
</vn-item>
<vn-item translate
name="reserved"
name="reserve"
ng-click="$ctrl.markAsReserved()"
ng-if="$ctrl.isEditable">
Mark as reserved
</vn-item>
<vn-item translate
name="unreserved"
name="unreserve"
ng-click="$ctrl.unmarkAsReserved()"
ng-if="$ctrl.isEditable && $ctrl.hasReserves()">
Unmark as reserved