1684 - Log transfer old values
gitea/salix/1684-ticket_transfer_salesLog Something is wrong with the build of this commit Details

This commit is contained in:
Joan Sanchez 2020-02-10 14:32:52 +01:00
parent cdef356e8f
commit e1942875af
4 changed files with 41 additions and 40 deletions

View File

@ -62,11 +62,14 @@ module.exports = Self => {
for (const sale of originalSales)
map.set(sale.id, sale);
for (const sale of sales) {
const originalSale = map.get(sale.id);
let originalSaleQuantity = originalSale.quantity;
const originalSaleData = { // <-- Loopback modifies original instance on save
itemFk: originalSale.itemFk,
quantity: originalSale.quantity,
concept: originalSale.concept,
ticketFk: originalSale.ticketFk
};
if (sale.quantity == originalSale.quantity) {
await models.Sale.updateAll({
@ -77,39 +80,47 @@ module.exports = Self => {
ticketId, originalSale, sale, options);
}
let logTicketOrigin = {
// Log to original ticket
await models.TicketLog.create({
originFk: id,
userFk: userId,
action: 'update',
changedModel: 'Ticket',
changedModelId: ticketId,
oldInstance: {item: sale.itemFk,
quantity: 0,
concept: sale.concept,
ticket: ticketId},
newInstance: {item: sale.itemFk,
changedModelId: id,
oldInstance: {
item: originalSaleData.itemFk,
quantity: originalSaleData.quantity,
concept: originalSaleData.concept,
ticket: originalSaleData.ticketFk
},
newInstance: {
item: sale.itemFk,
quantity: sale.quantity,
concept: sale.concept,
ticket: ticketId}
};
await models.TicketLog.create(logTicketOrigin, options);
ticket: ticketId
}
}, options);
let logTicketDestination = {
// Log to destination ticket
await models.TicketLog.create({
originFk: ticketId,
userFk: userId,
action: 'update',
changedModel: 'Ticket',
changedModelId: ticketId,
oldInstance: {item: sale.itemFk,
quantity: originalSaleQuantity,
oldInstance: {
item: originalSaleData.itemFk,
quantity: originalSaleData.quantity,
concept: originalSaleData.concept,
ticket: originalSaleData.ticketFk
},
newInstance: {
item: sale.itemFk,
quantity: sale.quantity,
concept: sale.concept,
ticket: id},
newInstance: {item: sale.itemFk,
quantity: originalSaleQuantity - sale.quantity,
concept: sale.concept,
ticket: id}
};
await models.TicketLog.create(logTicketDestination, options);
ticket: ticketId
}
}, options);
}
const isTicketEmpty = await models.Ticket.isEmpty(id, options);

View File

@ -324,14 +324,12 @@
</tbody>
</table>
<vn-horizontal class="vn-py-md">
<vn-textfield
vn-one
<vn-input-number vn-none
label="Transfer to ticket"
ng-model="$ctrl.transfer.ticketId"
type="number">
</vn-textfield>
<vn-icon-button
vn-none
</vn-input-number>
<vn-icon-button vn-none
icon="arrow_forward_ios"
ng-click="$ctrl.transferSales($ctrl.transfer.ticketId)">
</vn-icon-button>

View File

@ -14,18 +14,18 @@
<vn-table model="model">
<vn-thead>
<vn-tr>
<vn-th class="firstColumn" field="creationDate">Date</vn-th>
<vn-th field="creationDate">Date</vn-th>
<vn-th field="userFk" class="expendable" shrink>Author</vn-th>
<vn-th field="changedModel" class="expendable" shrink>Model</vn-th>
<vn-th field="action" class="expendable" shrink>Action</vn-th>
<vn-th field="changedModelValue" class="expendable" shrink>Name</vn-th>
<vn-th field="changedModelValue" class="expendable">Name</vn-th>
<vn-th expand>Before</vn-th>
<vn-th expand>After</vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr ng-repeat="log in $ctrl.logs">
<vn-td class="firstColumn">
<vn-td expand>
{{::log.creationDate | date:'dd/MM/yyyy HH:mm'}}
<div class="changes">
<div>
@ -63,7 +63,7 @@
<vn-td translate class="expendable">
{{::$ctrl.actionsText[log.action]}}
</vn-td>
<vn-td class="expendable">
<vn-td class="expendable" expand>
{{::log.changedModelValue}}
</vn-td>
<vn-td expand class="before">

View File

@ -14,14 +14,6 @@ vn-log {
color: $color-font;
}
.after, .before {
max-width: 250px;
}
vn-table .firstColumn {
min-width: 150px
}
@media screen and (max-width: 1570px) {
vn-table .expendable {
display: none;