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)
|
||||
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);
|
||||
|
@ -146,9 +157,9 @@ module.exports = Self => {
|
|||
|
||||
// Update original sale
|
||||
const rest = originalSale.quantity - sale.quantity;
|
||||
const updatedSale = await models.Sale.updateAll({
|
||||
id: sale.id
|
||||
}, {quantity: rest}, options);
|
||||
const originalInstance = await models.Sale.findById(sale.id, options);
|
||||
await originalInstance.updateAttribute('quantity', rest, options);
|
||||
|
||||
// Clone sale with new quantity
|
||||
const newSale = originalSale;
|
||||
newSale.id = undefined;
|
||||
|
@ -169,6 +180,6 @@ module.exports = Self => {
|
|||
|
||||
await models.SaleComponent.create(newComponents, options);
|
||||
|
||||
return updatedSale;
|
||||
return originalInstance;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -323,19 +323,19 @@
|
|||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<form name="form">
|
||||
<vn-horizontal class="vn-py-md">
|
||||
<vn-textfield
|
||||
vn-one
|
||||
<vn-input-number vn-one
|
||||
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>
|
||||
</vn-horizontal>
|
||||
</form>
|
||||
<vn-horizontal class="vn-py-md">
|
||||
<vn-button
|
||||
label="New ticket"
|
||||
|
|
|
@ -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">
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue