Skip to content

Commit

Permalink
Merge #5267
Browse files Browse the repository at this point in the history
5267: fix(stock-movements): filter by "today" by default r=lomamech a=jniles

Filters the stock movements registry by "today" by default.  It also unifies the filters for inline movements.

Closes #5258.

Co-authored-by: Jonathan Niles <jonathanwniles@gmail.com>
  • Loading branch information
bors[bot] and jniles authored Jan 6, 2021
2 parents 68bb316 + f69fffd commit 666ad34
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
27 changes: 21 additions & 6 deletions client/src/js/services/StockService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ angular.module('bhima.services')
.service('StockService', StockService);

StockService.$inject = [
'PrototypeApiService', 'StockFilterer', 'HttpCacheService',
'PrototypeApiService', 'StockFilterer', 'HttpCacheService', 'util', 'PeriodService',
];

function StockService(Api, StockFilterer, HttpCache) {
function StockService(Api, StockFilterer, HttpCache, util, Periods) {
// API for stock lots
const stocks = new Api('/stock/lots');

Expand Down Expand Up @@ -85,22 +85,37 @@ function StockService(Api, StockFilterer, HttpCache) {
const StockLotFilters = new StockFilterer('stock-lot-filters');
const StockAssignFilters = new StockFilterer('stock-assign-filters');
const StockRequisitionFilters = new StockFilterer('stock-requisition-filters');
const StockMovementFilters = new StockFilterer('stock-movement-filters');
const StockInlineMovementFilters = new StockFilterer('stock-inline-movement-filters');
const StockMovementFilters = new StockFilterer('stock-inline-movement-filters');
const StockInventoryFilters = new StockFilterer('stock-inventory-filters');
const StockDepotFilters = new StockFilterer('stock-depot-filters');

// creating an object of filter to avoid method duplication
const stockFilter = {
lot : StockLotFilters,
stockAssign : StockAssignFilters,
movement : StockMovementFilters,
inlineMovement : StockInlineMovementFilters,
movements : StockMovementFilters,
inventory : StockInventoryFilters,
depot : StockDepotFilters,
requisition : StockRequisitionFilters,
};

function assignDefaultPeriodFilters(filterService) {
// get the keys of filters already assigned - on initial load this will be empty
const assignedKeys = Object.keys(filterService._filters.formatHTTP());

// assign default period filter
const periodDefined = util.arrayIncludes(assignedKeys, [
'period', 'custom_period_start', 'custom_period_end',
]);

if (!periodDefined) {
filterService._filters.assignFilters(Periods.defaultFilters());
}
}

// assign default period filter to inlineStockMovements
assignDefaultPeriodFilters(stockFilter.movements);

function assignNoEmptyLotsDefaultFilter(service) {
// add in the default key for the stock lots filter
const assignedKeys = Object.keys(service._filters.formatHTTP());
Expand Down
2 changes: 1 addition & 1 deletion client/src/modules/stock/movements/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function StockMovementsController(
) {
const vm = this;
const cacheKey = 'movements-grid';
const stockMovementsFilters = Stock.filter.inlineMovement;
const stockMovementsFilters = Stock.filter.movements;

// grid columns
const columns = getGridColumns();
Expand Down
14 changes: 0 additions & 14 deletions client/src/modules/stock/stock.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ function StockModalService(Modal) {
service.openSearchLots = openSearchLots;
service.openSearchStockAssign = openSearchStockAssign;
service.openSearchMovements = openSearchMovements;
service.openSearchInlineMovements = openSearchInlineMovements;
service.openSearchInventories = openSearchInventories;
service.openSearchDepots = openSearchDepots;
service.openFindPatient = openFindPatient;
Expand Down Expand Up @@ -135,19 +134,6 @@ function StockModalService(Modal) {
return instance.result;
}

/** search stock inline movement */
function openSearchInlineMovements(request) {
const params = angular.extend(modalParameters, {
templateUrl : 'modules/stock/inline-movements/modals/search.modal.html',
controller : 'SearchInlineMovementsModalController',
controllerAs : '$ctrl',
resolve : { data : () => request },
});

const instance = Modal.open(params);
return instance.result;
}

/** search depots */
function openSearchDepots(request) {
const params = angular.extend(modalParameters, {
Expand Down

0 comments on commit 666ad34

Please sign in to comment.