forked from Third-Culture-Software/bhima
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
5361: Add page for finding and merging duplicate lots r=jmcameron a=jmcameron Create a page where operators can find and merge potential duplicate lots. **Note** that this PR adds a new page under the Stock navigation menu: "Find Duplicate Lots". In order to use or test this, be sure to edit the user role permissions and enable the new page (under the Stock section). Closes Third-Culture-Software#5166 **Testing** - Use a production database such as IMCK - Start Bhima - In Adminstration > Role Management , enable user access to the "Find Duplicate Lots" page. - Go to Stock > Find Duplicate Lots - Note the number of duplicates found (see the grid footer) - Click on the Action menu of any row and click on "Find duplicate lots". (I'm not 100% happy about the wording here; I'm open to suggestions). - A modal will pop up. Note that form will show all lots that have matching lot labels AND inventory UUIDs. Only one lot is shown for all the lots that match it. - Select the lot to keep and the lot(s) to merge - Click on the [Merge] button - When you return to the main grid, notice the offending row is now gone (since there is only one of them) Co-authored-by: Jonathan Cameron <jmcameron@gmail.com>
- Loading branch information
Showing
14 changed files
with
283 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
client/src/modules/stock/lots-duplicates/lots-duplicates.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<div class="flex-header"> | ||
<div class="bhima-title"> | ||
<ol class="headercrumb"> | ||
<li class="static" translate>TREE.STOCK</li> | ||
<li class="title" translate>TREE.DUPLICATE_LOTS</li> | ||
</ol> | ||
|
||
<div class="toolbar"> | ||
<div class="toolbar-item"> | ||
<div uib-dropdown dropdown-append-to-body data-action="open-menu"> | ||
<a class="btn btn-default" uib-dropdown-toggle> | ||
<span class="fa fa-bars"></span> <span class="hidden-xs" translate>FORM.LABELS.MENU</span> <span class="caret"></span> | ||
</a> | ||
|
||
<ul uib-dropdown-menu role="menu" class="dropdown-menu-right"> | ||
<li role="menuitem"> | ||
<a href data-method="configure" ng-click="DupeLotsCtrl.openColumnConfigModal()"> | ||
<i class="fa fa-columns"></i> <span translate>FORM.LABELS.COLUMNS</span> | ||
</a> | ||
</li> | ||
|
||
<li role="separator" class="divider"></li> | ||
<li role="menuitem"> | ||
<a href data-method="save-state" ng-click="DupeLotsCtrl.saveGridState()"> | ||
<i class="fa fa-save"></i> <span translate>FORM.BUTTONS.SAVE_GRID_CONFIGURATION</span> | ||
</a> | ||
</li> | ||
|
||
<li role="menuitem"> | ||
<a href data-method="clear-state" ng-click="DupeLotsCtrl.clearGridState()"> | ||
<i class="fa fa-close"></i> <span translate>FORM.BUTTONS.CLEAR_GRID_CONFIGURATION</span> | ||
</a> | ||
</li> | ||
|
||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="flex-content"> | ||
<div class="container-fluid"> | ||
<div | ||
id="duplicate-lots-grid" | ||
class="grid-full-height-with-filters" | ||
ui-grid="DupeLotsCtrl.gridOptions" | ||
ui-grid-resize-columns | ||
ui-grid-auto-resize | ||
ui-grid-save-state> | ||
<bh-grid-loading-indicator | ||
loading-state="DupeLotsCtrl.loading" | ||
empty-state="DupeLotsCtrl.gridOptions.data.length === 0" | ||
error-state="DupeLotsCtrl.hasError"> | ||
</bh-grid-loading-indicator> | ||
</div> | ||
</div> | ||
</div> |
158 changes: 158 additions & 0 deletions
158
client/src/modules/stock/lots-duplicates/lots-duplicates.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
angular.module('bhima.controllers') | ||
.controller('DuplicateLotsController', DuplicateLotsController); | ||
|
||
DuplicateLotsController.$inject = [ | ||
'LotService', 'NotifyService', 'StockModalService', 'SessionService', | ||
'GridColumnService', 'GridStateService', '$state', | ||
]; | ||
|
||
/** | ||
* Stock Lots Duplicates | ||
* This module is a stock lots page for finding and merging duplicate lots | ||
*/ | ||
function DuplicateLotsController( | ||
Lots, Notify, Modal, Session, | ||
Columns, GridState, $state, | ||
) { | ||
const vm = this; | ||
const cacheKey = 'duplicate-lots-grid'; | ||
vm.enterprise = Session.enterprise; | ||
|
||
const columns = [ | ||
{ | ||
field : 'label', | ||
displayName : 'TABLE.COLUMNS.LABEL', | ||
headerTooltip : 'TABLE.COLUMNS.LABEL', | ||
headerCellFilter : 'translate', | ||
|
||
}, { | ||
field : 'inventory_text', | ||
displayName : 'TABLE.COLUMNS.INVENTORY', | ||
headerTooltip : 'TABLE.COLUMNS.INVENTORY', | ||
headerCellFilter : 'translate', | ||
width : '20%', | ||
}, { | ||
field : 'quantity', | ||
displayName : 'TABLE.COLUMNS.QUANTITY', | ||
headerTooltip : 'TABLE.COLUMNS.QUANTITY', | ||
headerCellFilter : 'translate', | ||
cellClass : 'text-right', | ||
type : 'number', | ||
}, { | ||
field : 'initial_quantity', | ||
displayName : 'STOCK.INITIAL_QUANTITY', | ||
headerTooltip : 'STOCK.INITIAL_QUANTITY', | ||
headerCellFilter : 'translate', | ||
cellClass : 'text-right', | ||
type : 'number', | ||
}, { | ||
field : 'unit_cost', | ||
displayName : 'TABLE.COLUMNS.UNIT_PRICE', | ||
headerTooltip : 'TABLE.COLUMNS.UNIT_PRICE', | ||
headerCellFilter : 'translate', | ||
cellFilter : `currency:${vm.enterprise.currency_id}`, | ||
cellClass : 'text-right', | ||
type : 'number', | ||
}, { | ||
field : 'entry_date', | ||
displayName : 'STOCK.ENTRY_DATE', | ||
headerTooltip : 'STOCK.ENTRY_DATE', | ||
headerCellFilter : 'translate', | ||
cellFilter : 'date', | ||
cellClass : 'text-right', | ||
}, { | ||
field : 'expiration_date', | ||
displayName : 'STOCK.EXPIRATION_DATE', | ||
headerTooltip : 'STOCK.EXPIRATION_DATE', | ||
headerCellFilter : 'translate', | ||
cellFilter : 'date:"mediumDate"', | ||
cellClass : 'text-right', | ||
}, { | ||
field : 'num_duplicates', | ||
displayName : 'TABLE.COLUMNS.NUM_DUPLICATE_LOTS', | ||
headerTooltip : 'TABLE.COLUMNS.NUM_DUPLICATE_LOTS', | ||
headerCellFilter : 'translate', | ||
cellClass : 'text-right', | ||
type : 'number', | ||
}, { | ||
field : 'action', | ||
displayName : '', | ||
enableFiltering : false, | ||
enableSorting : false, | ||
cellTemplate : 'modules/stock/lots-duplicates/templates/action.cell.html', | ||
}, | ||
]; | ||
|
||
const footerTemplate = ` | ||
<div class="ui-grid-cell-contents"> | ||
<b>{{ grid.appScope.gridOptions.data.length }}</b> | ||
<span translate>FORM.INFO.FOUND</span> | ||
</div> | ||
`; | ||
|
||
vm.gridOptions = { | ||
appScopeProvider : vm, | ||
enableColumnMenus : false, | ||
columnDefs : columns, | ||
showGridFooter : true, | ||
gridFooterTemplate : footerTemplate, | ||
fastWatch : true, | ||
flatEntityAccess : true, | ||
}; | ||
|
||
const gridColumns = new Columns(vm.gridOptions, cacheKey); | ||
const state = new GridState(vm.gridOptions, cacheKey); | ||
|
||
vm.saveGridState = state.saveGridState; | ||
|
||
function clearGridState() { | ||
state.clearGridState(); | ||
$state.reload(); | ||
} | ||
|
||
// expose view logic | ||
vm.openColumnConfigModal = openColumnConfigModal; | ||
vm.clearGridState = clearGridState; | ||
|
||
// This function opens a modal through column service to let the user toggle | ||
// the visibility of the inventories registry's columns. | ||
function openColumnConfigModal() { | ||
gridColumns.openConfigurationModal(); | ||
} | ||
|
||
// load stock lots in the grid | ||
function load() { | ||
vm.hasError = false; | ||
vm.loading = true; | ||
|
||
Lots.dupes({ find_dupes : true }) | ||
.then((rows) => { | ||
vm.gridOptions.data = rows; | ||
}) | ||
.catch((err) => { | ||
vm.hasError = true; | ||
Notify.handleError(err); | ||
}) | ||
.finally(() => { | ||
vm.loading = false; | ||
}); | ||
} | ||
|
||
// lot duplicates modal | ||
vm.openDuplicatesModal = (uuid, depotUuid) => { | ||
// NOTE: depotUuid is undefined (for now) | ||
Modal.openDuplicateLotsModal({ uuid, depotUuid }) | ||
.then((res) => { | ||
if (res === 'success') { | ||
// Reload the duplicate lots since some lots were merged | ||
load(); | ||
} | ||
}); | ||
}; | ||
|
||
function startup() { | ||
load(); | ||
} | ||
|
||
startup(); | ||
} |
15 changes: 15 additions & 0 deletions
15
client/src/modules/stock/lots-duplicates/templates/action.cell.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<div class="ui-grid-cell-contents text-right" uib-dropdown dropdown-append-to-body uib-dropdown-toggle ng-if="!row.groupHeader"> | ||
<a href> | ||
<span data-method="action" translate>FORM.BUTTONS.ACTIONS</span> | ||
<span class="caret"></span> | ||
</a> | ||
|
||
<ul class="dropdown-menu-right" bh-dropdown-menu-auto-dropup uib-dropdown-menu> | ||
<li class="bh-dropdown-header">{{row.entity.label}} - {{row.entity.inventory_text}}</li> | ||
<li> | ||
<a data-method="find-duplicates" ng-click="grid.appScope.openDuplicatesModal(row.entity.uuid, row.entity.depot_uuid)" href> | ||
<i class="fa fa-search"></i> <span translate>LOTS.MERGE_DUPLICATE_LOTS</span> | ||
</a> | ||
</li> | ||
</ul> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters