Merge branch '1684-ticket_transfer_salesLog' of verdnatura/salix into dev
gitea/salix/dev There was a failure building this commit
Details
gitea/salix/dev There was a failure building this commit
Details
This commit is contained in:
commit
420f059211
|
@ -62,11 +62,14 @@ module.exports = Self => {
|
||||||
for (const sale of originalSales)
|
for (const sale of originalSales)
|
||||||
map.set(sale.id, sale);
|
map.set(sale.id, sale);
|
||||||
|
|
||||||
|
|
||||||
for (const sale of sales) {
|
for (const sale of sales) {
|
||||||
const originalSale = map.get(sale.id);
|
const originalSale = map.get(sale.id);
|
||||||
|
const originalSaleData = { // <-- Loopback modifies original instance on save
|
||||||
let originalSaleQuantity = originalSale.quantity;
|
itemFk: originalSale.itemFk,
|
||||||
|
quantity: originalSale.quantity,
|
||||||
|
concept: originalSale.concept,
|
||||||
|
ticketFk: originalSale.ticketFk
|
||||||
|
};
|
||||||
|
|
||||||
if (sale.quantity == originalSale.quantity) {
|
if (sale.quantity == originalSale.quantity) {
|
||||||
await models.Sale.updateAll({
|
await models.Sale.updateAll({
|
||||||
|
@ -77,39 +80,47 @@ module.exports = Self => {
|
||||||
ticketId, originalSale, sale, options);
|
ticketId, originalSale, sale, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
let logTicketOrigin = {
|
// Log to original ticket
|
||||||
|
await models.TicketLog.create({
|
||||||
originFk: id,
|
originFk: id,
|
||||||
userFk: userId,
|
userFk: userId,
|
||||||
action: 'update',
|
action: 'update',
|
||||||
changedModel: 'Ticket',
|
changedModel: 'Ticket',
|
||||||
changedModelId: ticketId,
|
changedModelId: id,
|
||||||
oldInstance: {item: sale.itemFk,
|
oldInstance: {
|
||||||
quantity: 0,
|
item: originalSaleData.itemFk,
|
||||||
concept: sale.concept,
|
quantity: originalSaleData.quantity,
|
||||||
ticket: ticketId},
|
concept: originalSaleData.concept,
|
||||||
newInstance: {item: sale.itemFk,
|
ticket: originalSaleData.ticketFk
|
||||||
|
},
|
||||||
|
newInstance: {
|
||||||
|
item: sale.itemFk,
|
||||||
quantity: sale.quantity,
|
quantity: sale.quantity,
|
||||||
concept: sale.concept,
|
concept: sale.concept,
|
||||||
ticket: ticketId}
|
ticket: ticketId
|
||||||
};
|
}
|
||||||
await models.TicketLog.create(logTicketOrigin, options);
|
}, options);
|
||||||
|
|
||||||
let logTicketDestination = {
|
// Log to destination ticket
|
||||||
|
await models.TicketLog.create({
|
||||||
originFk: ticketId,
|
originFk: ticketId,
|
||||||
userFk: userId,
|
userFk: userId,
|
||||||
action: 'update',
|
action: 'update',
|
||||||
changedModel: 'Ticket',
|
changedModel: 'Ticket',
|
||||||
changedModelId: ticketId,
|
changedModelId: ticketId,
|
||||||
oldInstance: {item: sale.itemFk,
|
oldInstance: {
|
||||||
quantity: originalSaleQuantity,
|
item: originalSaleData.itemFk,
|
||||||
|
quantity: originalSaleData.quantity,
|
||||||
|
concept: originalSaleData.concept,
|
||||||
|
ticket: originalSaleData.ticketFk
|
||||||
|
},
|
||||||
|
newInstance: {
|
||||||
|
item: sale.itemFk,
|
||||||
|
quantity: sale.quantity,
|
||||||
concept: sale.concept,
|
concept: sale.concept,
|
||||||
ticket: id},
|
ticket: ticketId
|
||||||
newInstance: {item: sale.itemFk,
|
}
|
||||||
quantity: originalSaleQuantity - sale.quantity,
|
}, options);
|
||||||
concept: sale.concept,
|
|
||||||
ticket: id}
|
|
||||||
};
|
|
||||||
await models.TicketLog.create(logTicketDestination, options);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const isTicketEmpty = await models.Ticket.isEmpty(id, options);
|
const isTicketEmpty = await models.Ticket.isEmpty(id, options);
|
||||||
|
@ -146,9 +157,9 @@ module.exports = Self => {
|
||||||
|
|
||||||
// Update original sale
|
// Update original sale
|
||||||
const rest = originalSale.quantity - sale.quantity;
|
const rest = originalSale.quantity - sale.quantity;
|
||||||
const updatedSale = await models.Sale.updateAll({
|
const originalInstance = await models.Sale.findById(sale.id, options);
|
||||||
id: sale.id
|
await originalInstance.updateAttribute('quantity', rest, options);
|
||||||
}, {quantity: rest}, options);
|
|
||||||
// Clone sale with new quantity
|
// Clone sale with new quantity
|
||||||
const newSale = originalSale;
|
const newSale = originalSale;
|
||||||
newSale.id = undefined;
|
newSale.id = undefined;
|
||||||
|
@ -169,6 +180,6 @@ module.exports = Self => {
|
||||||
|
|
||||||
await models.SaleComponent.create(newComponents, options);
|
await models.SaleComponent.create(newComponents, options);
|
||||||
|
|
||||||
return updatedSale;
|
return originalInstance;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -323,19 +323,19 @@
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<vn-horizontal class="vn-py-md">
|
<form name="form">
|
||||||
<vn-textfield
|
<vn-horizontal class="vn-py-md">
|
||||||
vn-one
|
<vn-input-number vn-one
|
||||||
label="Transfer to ticket"
|
label="Transfer to ticket"
|
||||||
ng-model="$ctrl.transfer.ticketId"
|
ng-model="$ctrl.transfer.ticketId"
|
||||||
type="number">
|
type="number">
|
||||||
</vn-textfield>
|
</vn-input-number>
|
||||||
<vn-icon-button
|
<vn-icon-button vn-none
|
||||||
vn-none
|
icon="arrow_forward_ios"
|
||||||
icon="arrow_forward_ios"
|
ng-click="$ctrl.transferSales($ctrl.transfer.ticketId)">
|
||||||
ng-click="$ctrl.transferSales($ctrl.transfer.ticketId)">
|
</vn-icon-button>
|
||||||
</vn-icon-button>
|
</vn-horizontal>
|
||||||
</vn-horizontal>
|
</form>
|
||||||
<vn-horizontal class="vn-py-md">
|
<vn-horizontal class="vn-py-md">
|
||||||
<vn-button
|
<vn-button
|
||||||
label="New ticket"
|
label="New ticket"
|
||||||
|
|
|
@ -14,18 +14,18 @@
|
||||||
<vn-table model="model">
|
<vn-table model="model">
|
||||||
<vn-thead>
|
<vn-thead>
|
||||||
<vn-tr>
|
<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="userFk" class="expendable" shrink>Author</vn-th>
|
||||||
<vn-th field="changedModel" class="expendable" shrink>Model</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="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>Before</vn-th>
|
||||||
<vn-th expand>After</vn-th>
|
<vn-th expand>After</vn-th>
|
||||||
</vn-tr>
|
</vn-tr>
|
||||||
</vn-thead>
|
</vn-thead>
|
||||||
<vn-tbody>
|
<vn-tbody>
|
||||||
<vn-tr ng-repeat="log in $ctrl.logs">
|
<vn-tr ng-repeat="log in $ctrl.logs">
|
||||||
<vn-td class="firstColumn">
|
<vn-td expand>
|
||||||
{{::log.creationDate | date:'dd/MM/yyyy HH:mm'}}
|
{{::log.creationDate | date:'dd/MM/yyyy HH:mm'}}
|
||||||
<div class="changes">
|
<div class="changes">
|
||||||
<div>
|
<div>
|
||||||
|
@ -63,7 +63,7 @@
|
||||||
<vn-td translate class="expendable">
|
<vn-td translate class="expendable">
|
||||||
{{::$ctrl.actionsText[log.action]}}
|
{{::$ctrl.actionsText[log.action]}}
|
||||||
</vn-td>
|
</vn-td>
|
||||||
<vn-td class="expendable">
|
<vn-td class="expendable" expand>
|
||||||
{{::log.changedModelValue}}
|
{{::log.changedModelValue}}
|
||||||
</vn-td>
|
</vn-td>
|
||||||
<vn-td expand class="before">
|
<vn-td expand class="before">
|
||||||
|
|
|
@ -14,14 +14,6 @@ vn-log {
|
||||||
color: $color-font;
|
color: $color-font;
|
||||||
}
|
}
|
||||||
|
|
||||||
.after, .before {
|
|
||||||
max-width: 250px;
|
|
||||||
}
|
|
||||||
|
|
||||||
vn-table .firstColumn {
|
|
||||||
min-width: 150px
|
|
||||||
}
|
|
||||||
|
|
||||||
@media screen and (max-width: 1570px) {
|
@media screen and (max-width: 1570px) {
|
||||||
vn-table .expendable {
|
vn-table .expendable {
|
||||||
display: none;
|
display: none;
|
||||||
|
|
Loading…
Reference in New Issue