Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OBPIH-5455 Add filter for GL account #3866

Merged
merged 15 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion grails-app/conf/UrlMappings.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class UrlMappings {

// Gl account options for filters on product list page
"/api/glAccountOptions"(parseRequest: true) {
controller = { "productApi" }
controller = { "glAccount" }
jmiranda marked this conversation as resolved.
Show resolved Hide resolved
action = [GET: "glAccountOptions"]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,4 @@ class ProductApiController extends BaseDomainApiController {

render([data: tags] as JSON)
}

def glAccountOptions = {
def glAccounts = GlAccount.list().collect {
[id: it.id, label: "${it.code} - ${it.name}"]
}

render([data: glAccounts] as JSON)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
* You must not remove this notice, or any other, from this software.
**/
package org.pih.warehouse.core

import grails.converters.JSON
import org.pih.warehouse.product.Product

class GlAccountController {

def GlAccountService glAccountService

def index = {
redirect(action: "list", params: params)
}
Expand Down Expand Up @@ -84,4 +88,9 @@ class GlAccountController {
redirect(action: "list")
}
}

def glAccountOptions = {
def glAccounts = glAccountService.getGlAccountsOptions()
render([data: glAccounts] as JSON)
}
}
19 changes: 19 additions & 0 deletions grails-app/services/org/pih/warehouse/core/GlAccountService.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright (c) 2012 Partners In Health. All rights reserved.
* The use and distribution terms for this software are covered by the
* Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
* which can be found in the file epl-v10.html at the root of this distribution.
* By using this software in any fashion, you are agreeing to be bound by
* the terms of this license.
* You must not remove this notice, or any other, from this software.
**/
package org.pih.warehouse.core

class GlAccountService {

def getGlAccountsOptions() {
return GlAccount.list().collect {
[id: it.id, label: "${it.code} - ${it.name}"]
}
}
}
6 changes: 6 additions & 0 deletions src/js/api/services/GlAccountApi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { GL_ACCOUNTS_OPTION } from 'api/urls';
import apiClient from 'utils/apiClient';

export default {
getGlAccountOptions: () => apiClient.get(GL_ACCOUNTS_OPTION),
};
3 changes: 3 additions & 0 deletions src/js/api/urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ export const STOCKLIST_CLEAR = id => `${STOCKLIST_API}/${id}/clear`;
export const STOCKLIST_CLONE = id => `${STOCKLIST_API}/${id}/clone`;
export const STOCKLIST_PUBLISH = id => `${STOCKLIST_API}/${id}/publish`;
export const STOCKLIST_UNPUBLISH = id => `${STOCKLIST_API}/${id}/unpublish`;

// GL ACCOUNTS
export const GL_ACCOUNTS_OPTION = '/openboxes/api/glAccountOptions';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

having an occassion - could you please specify at the top of the file

const API = '/openboxes/api'

and use it in this endpoint?
You don't have to change it the lines above, but just to have less refactor in the future and use this constant since now

5 changes: 3 additions & 2 deletions src/js/utils/option-utils.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import _ from 'lodash';
import queryString from 'query-string';

import glAccountApi from 'api/services/GlAccountApi';
import apiClient from 'utils/apiClient';


Expand Down Expand Up @@ -220,6 +221,6 @@ export const fetchProductsTags = async () => {
};

export const fetchProductsGlAccounts = async () => {
const response = await apiClient.get('/openboxes/api/glAccountOptions');
return response.data.data;
const { data } = await glAccountApi.getGlAccountOptions();
return data.data;
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we could follow, since you've refactored some of our api calls to use api/services, to use this approach here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm adding one additional comment, which should be rather answered by @awalkowiak - I'm wondering if we should wrap it inside try/catch and have somewhat user-friendly error message if any happens, or let the handler handle that, but we could have some "ugly" error message in terms of user perspective?

Copy link
Member

@jmiranda jmiranda Feb 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussion for standardizing error messages #3849 to be included in coding conventions. May require more technical discussions around this. #3867