Skip to content

Commit

Permalink
Fix several problems in create shipment form
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcameron committed Apr 15, 2022
1 parent 9aeef4a commit 0fbcb30
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 10 deletions.
2 changes: 2 additions & 0 deletions client/src/modules/shipment/create-shipment.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@
depot-uuid="CreateShipCtrl.shipment.destination_depot_uuid"
label="SHIPMENT.DESTINATION_DEPOT"
on-select-callback="CreateShipCtrl.onSelectDestinationDepot(depot)"
exception="CreateShipCtrl.depot"
required="true">
</bh-depot-select>

<!-- date -->
<bh-date-editor
label="SHIPMENT.ANTICIPATED_DELIVERY_DATE"
date-value="CreateShipCtrl.shipment.anticipated_delivery_date"
min-date="CreateShipCtrl.today"
allow-future-date="true"
on-change="CreateShipCtrl.setDate(date)"
required="true">
Expand Down
12 changes: 9 additions & 3 deletions client/src/modules/shipment/create-shipment.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function CreateShipmentController(
width : 150,
displayName : 'TABLE.COLUMNS.QUANTITY',
headerCellFilter : 'translate',
cellTemplate : 'modules/stock/exit/templates/quantity.tmpl.html',
cellTemplate : 'modules/shipment/templates/quantity.tmpl.html',
aggregationType : uiGridConstants.aggregationTypes.sum,
}, {
field : 'unit_type',
Expand Down Expand Up @@ -104,7 +104,7 @@ function CreateShipmentController(

vm.maxLength = util.maxLength;
vm.enterprise = Session.enterprise;
vm.maxDate = new Date();
vm.today = new Date();
vm.onChangeDepot = onChangeDepot;
vm.getOverview = getOverview;
vm.setReady = setReady;
Expand All @@ -127,6 +127,10 @@ function CreateShipmentController(
};

vm.configureItem = function configureItem(row, lot) {
if (lot.isAsset()) {
// Override default quantity for assets
lot.quantity = 1;
}
vm.stockForm.configureItem(row, lot);
vm.validateItems();
};
Expand Down Expand Up @@ -181,6 +185,9 @@ function CreateShipmentController(
// set the shipment origin
vm.shipment.origin_depot_uuid = vm.depot.uuid;

// Delete the old destination depot
delete vm.shipment.destination_depot_uuid;

// trick an exit type which is required
vm.stockForm.setExitType('loss');
vm.stockForm.setLossDistribution();
Expand Down Expand Up @@ -217,7 +224,6 @@ function CreateShipmentController(
function startup() {
vm.loading = true;
vm.hasError = false;

vm.stockForm.setup();
vm.validateItems();

Expand Down
12 changes: 12 additions & 0 deletions client/src/modules/shipment/templates/quantity.tmpl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class="ui-grid-cell-contents">
<input
name="quantity"
type="number"
min="0"
ng-max="{{ row.entity._quantity_available}}"
ng-disabled="!row.entity.lot_uuid"
class="form-control"
style="padding-left : 5px !important;text-align: right;"
ng-model="row.entity.quantity"
ng-change="grid.appScope.validateItems()" required>
</div>
2 changes: 1 addition & 1 deletion client/src/modules/stock/LotItem.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ function LotItemService(uuid, $translate) {
* Returns true if the lot is an asset.
*/
Lot.prototype.isAsset = function isAsset() {
return this.__is_asset === true;
return !!this.__is_asset;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion client/src/modules/stock/StockExitForm.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function StockExitFormService(
.then(stock => {

const rawStock = this.allowExpired ? stock
: stock.filter(lot => !lot.is_asset && !lot.is_expired);
: stock.filter(lot => lot.is_asset || !lot.is_expired);

const available = rawStock
.map(item => {
Expand Down
8 changes: 5 additions & 3 deletions server/controllers/asset_management/shipment/shipment.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ exports.listInTransitInventories = async (req, res, next) => {
DATEDIFF(l.expiration_date, CURRENT_DATE()) AS lifetime,
BUID(l.inventory_uuid) AS inventory_uuid,
BUID(sh.origin_depot_uuid) AS depot_uuid,
i.purchase_interval, i.delay,
i.purchase_interval, i.delay, i.is_asset,
iu.text AS unit_type,
ig.name AS group_name, ig.tracking_expiration, ig.tracking_consumption,
CONCAT('LT', LEFT(HEX(l.uuid), 8)) AS barcode
Expand Down Expand Up @@ -525,7 +525,8 @@ function findAffectedAssets(params) {
BUID(shi.uuid) AS uuid, BUID(sh.uuid) AS shipment_uuid,
BUID(shi.lot_uuid) AS lot_uuid, shi.quantity_sent,
l.label AS lot_label, i.code AS inventory_code,
i.text AS inventory_text, dm.text AS reference
i.text AS inventory_text, i.is_asset,
dm.text AS reference
FROM shipment sh
JOIN shipment_item shi ON shi.shipment_uuid = sh.uuid
JOIN lot l ON l.uuid = shi.lot_uuid
Expand Down Expand Up @@ -629,7 +630,8 @@ async function getPackingList(identifier) {
sh.anticipated_delivery_date,
sh.receiver, u.display_name AS created_by,
shi.quantity_sent, shi.quantity_delivered, shi.date_packed,
l.label AS lot_label, i.code AS inventory_code, i.text AS inventory_label,
l.label AS lot_label, i.code AS inventory_code,
i.text AS inventory_label, i.is_asset,
dm.text AS reference
FROM shipment sh
JOIN shipment_status ss ON ss.id = sh.status_id
Expand Down
5 changes: 3 additions & 2 deletions server/controllers/inventory/depots/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,10 @@ function getLotsInStockForDate(depotUuid, date) {
SELECT
BUID(inventory.uuid) AS inventory_uuid,
BUID(lot.uuid) AS lot_uuid,
balances.quantity,
balances.quantity,
inventory.code,
inventory.text,
inventory.is_asset,
BUID(inventory.group_uuid) AS group_uuid,
lot.expiration_date,
(lot.expiration_date < DATE(?)) AS is_expired,
Expand All @@ -131,7 +132,7 @@ function getLotsInStockForDate(depotUuid, date) {
inventory_group.tracking_consumption,
inventory_unit.text AS unit
FROM (
SELECT
SELECT
sm.lot_uuid,
SUM(IF(sm.is_exit, -1 * sm.quantity, sm.quantity)) AS quantity
FROM stock_movement AS sm
Expand Down

0 comments on commit 0fbcb30

Please sign in to comment.