Skip to content

Commit

Permalink
Fix editing shipments (updating packing list)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcameron committed Apr 25, 2022
1 parent 64025bd commit 7caaa66
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 63 deletions.
10 changes: 9 additions & 1 deletion client/src/js/components/bhChangeDepot.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ angular.module('bhima.directives')
<i class="fa fa-archive"></i> <span translate>DEPOT.CHANGE</span>
</a>`,
controller : bhChangeDepotController,
bindings : { onSelect : '&' },
bindings : {
onSelect : '&',
skipInitialLoad : '<?',
},
});

bhChangeDepotController.$inject = [
Expand All @@ -18,6 +21,11 @@ function bhChangeDepotController(Depots, AppCache, Notify) {
const cache = new AppCache('StockCache');

$ctrl.$onInit = () => {

if ($ctrl?.skipInitialLoad) {
return;
}

if (cache.depotUuid) {
loadDepot(cache.depotUuid);
} else {
Expand Down
17 changes: 14 additions & 3 deletions client/src/modules/shipment/create-shipment.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
</ol>

<div class="toolbar">
<div class="toolbar-item">
<div ng-if="!CreateShipCtrl.$loading" class="toolbar-item">
<bh-dropdown-menu>
<bh-dropdown-menu-item>
<a href>
<bh-change-depot on-select="CreateShipCtrl.onChangeDepot(depot)"></bh-change-depot>
<bh-change-depot
skip-initial-load="!CreateShipCtrl.isCreateState"
on-select="CreateShipCtrl.onChangeDepot(depot)">
</bh-change-depot>
</a>
</bh-dropdown-menu-item>
</bh-dropdown-menu>
Expand All @@ -27,7 +30,15 @@
<div class="flex-content">
<div class="container-fluid">

<form name="ShipmentForm" bh-submit="CreateShipCtrl.submit(ShipmentForm)" novalidate>
<div class="row" ng-if="CreateShipCtrl.$loading">
<i class="fa fa-circle-o-notch fa-spin"></i> <span translate>FORM.INFO.LOADING</span>
</div>

<form
name="ShipmentForm"
ng-if="!CreateShipCtrl.$loading"
bh-submit="CreateShipCtrl.submit(ShipmentForm)"
novalidate>

<!-- date and note -->
<div class="row">
Expand Down
46 changes: 30 additions & 16 deletions client/src/modules/shipment/create-shipment.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,7 @@ function CreateShipmentController(

vm.onSelectDestinationDepot = depot => {
vm.shipment.destination_depot_uuid = depot.uuid;

// define the exit type as depot for allowing
// to block expired items in the validation
$timeout(() => {
vm.stockForm.setExitType('depot');
vm.stockForm.setDepotDistribution(depot);
}, 0);
vm.stockForm.setDepotDistribution(depot);
};

vm.validateItems = () => {
Expand Down Expand Up @@ -182,11 +176,16 @@ function CreateShipmentController(
vm.depot = depot;
vm.stockForm.setDepot(depot);

// set the shipment origin
vm.shipment.origin_depot_uuid = vm.depot.uuid;

// Delete the old destination depot
delete vm.shipment.destination_depot_uuid;
// When the user changes the origin depot, only delete/clear the
// destination_depot_uuid if
// - We are creating a shipment, OR
// - We are editing a shipment and the new origin depot is the same
// as the previous destination depot
if (vm.isCreateState || (vm.shipment.destination_depot.uuid === depot.uuid)) {
delete vm.shipment.destination_depot_uuid;
}

// trick an exit type which is required
vm.stockForm.setExitType('loss');
Expand Down Expand Up @@ -222,9 +221,10 @@ function CreateShipmentController(
}

function startup() {
vm.loading = true;
vm.$loading = true;
vm.hasError = false;
vm.stockForm.setup();
vm.stockForm.setExitType('depot');
vm.validateItems();

// load the shipment for update
Expand Down Expand Up @@ -351,17 +351,31 @@ function CreateShipmentController(
}

function loadShipment() {
if (!existingShipmentUuid) { return; }

if (!existingShipmentUuid) {
vm.$loading = false;
return;
}
Shipment.readAll(existingShipmentUuid)
.then(shipment => {
vm.shipment = shipment;
vm.shipment.anticipated_delivery_date = new Date(vm.shipment.anticipated_delivery_date);
return Depot.read(vm.shipment.origin_depot_uuid);
})
.then(depot => onChangeDepot(depot))
.then(() => vm.stockForm.setLotsFromShipmentList(vm.shipment.lots, 'lot_uuid'))
.catch(Notify.handleError);
.then(originDepot => {
vm.depot = originDepot;
vm.stockForm.setDepot(originDepot);
return Depot.read(vm.shipment.destination_depot_uuid);
})
.then(destDepot => {
delete vm.messages;
vm.stockForm.setExitType('depot');
vm.stockForm.setDepotDistribution(destDepot);
vm.stockForm.setLotsFromShipmentList(vm.shipment.lots, 'lot_uuid');
})
.catch(Notify.handleError)
.finally(() => {
vm.$loading = false;
});
}

function fetchAffectedAssets() {
Expand Down
37 changes: 0 additions & 37 deletions client/src/modules/shipment/shipment.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,6 @@ function ShipmentService(Api, $httpParamSerializer, Languages) {
8 : 'SHIPMENT.STATUS.LOST',
};

service.exportTo = (renderer, filter) => {
const filterOpts = filter.formatHTTP();
const defaultOpts = {
renderer,
lang : Languages.key,
};
const options = angular.merge(defaultOpts, filterOpts);
return $httpParamSerializer(options);
};

service.downloadExcel = (filter, gridColumns) => {
const filterOpts = filter.formatHTTP();
const defaultOpts = {
renderer : 'xlsx',
lang : Languages.key,
renameKeys : true,
displayNames : gridColumns.getDisplayNames(),
};
const options = angular.merge(defaultOpts, filterOpts);
return $httpParamSerializer(options);
};

service.readAll = (uuid, parameters) => {
return service.$http.get(`/shipments/${uuid}/full`, { params : parameters })
.then(service.util.unwrapHttpResponse);
Expand Down Expand Up @@ -86,20 +64,5 @@ function ShipmentService(Api, $httpParamSerializer, Languages) {
return $httpParamSerializer(options);
};

service.readAll = (uuid, parameters) => {
return service.$http.get(`/shipments/${uuid}/full`, { params : parameters })
.then(service.util.unwrapHttpResponse);
};

service.updateLocation = (uuid, params) => {
return service.$http.post(`/shipments/${uuid}/tracking-log`, { params })
.then(service.util.unwrapHttpResponse);
};

service.setReadyForShipment = (uuid) => {
return service.$http.put(`/shipments/${uuid}/ready-for-shipment`)
.then(service.util.unwrapHttpResponse);
};

return service;
}
12 changes: 6 additions & 6 deletions server/controllers/asset_management/shipment/shipment.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,9 @@ function find(params) {
ss.id AS status_id,
dm.text AS reference,
dm2.text AS stock_reference,
BUID(d.uuid) AS origin_depot_uuid,
BUID(sh.origin_depot_uuid) AS origin_depot_uuid,
d.text AS origin_depot,
BUID(d2.uuid) AS destination_depot_uuid,
BUID(sh.destination_depot_uuid) AS destination_depot_uuid,
d2.text AS destination_depot,
sh.name, sh.description, sh.note,
sh.created_at AS date, sh.date_sent, sh.date_delivered,
Expand Down Expand Up @@ -550,9 +550,9 @@ async function lookup(identifier) {
dm.text AS reference,
dm2.text AS stock_reference,
d.text AS origin_depot,
BUID(d.uuid) AS origin_depot_uuid,
BUID(sh.origin_depot_uuid) AS origin_depot_uuid,
d2.text AS destination_depot,
BUID(d2.uuid) AS destination_depot_uuid,
BUID(sh.destination_depot_uuid) AS destination_depot_uuid,
sh.name, sh.description, sh.note,
sh.created_at AS date, sh.date_sent, sh.date_delivered,
sh.anticipated_delivery_date, sh.date_ready_for_shipment,
Expand Down Expand Up @@ -590,9 +590,9 @@ async function lookupSingle(identifier) {
dm.text AS reference,
dm2.text AS stock_reference,
d.text AS origin_depot,
BUID(d.uuid) AS origin_depot_uuid,
BUID(sh.origin_depot_uuid) AS origin_depot_uuid,
d2.text AS destination_depot,
BUID(d2.uuid) AS destination_depot_uuid,
BUID(sh.destination_depot_uuid) AS destination_depot_uuid,
sh.name, sh.description, sh.note,
sh.created_at AS date, sh.date_sent, sh.date_delivered,
sh.anticipated_delivery_date, sh.date_ready_for_shipment,
Expand Down

0 comments on commit 7caaa66

Please sign in to comment.