Skip to content

Commit

Permalink
feat: List Product Attribute Instances. (adempiere#62)
Browse files Browse the repository at this point in the history
* feat: List Product Attribute Instances.

* feat: Add get Product Attribute Set.

* update package.json
  • Loading branch information
EdwinBetanc0urt authored Oct 31, 2022
1 parent 7675a6f commit 08bfcab
Show file tree
Hide file tree
Showing 4 changed files with 196 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"license": "MIT",
"dependencies": {
"@2fd/graphdoc": "^2.4.0",
"@adempiere/grpc-api": "3.5.3",
"@adempiere/grpc-api": "3.5.4",
"@adempiere/grpc-web-store-api": "1.5.7",
"@elastic/elasticsearch": "7.14.0",
"@google-cloud/storage": "^3.0.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@

import { Router } from 'express';
import { convertEntitiesListFromGRPC } from '../util/convertData';
import {
convertProductAttributeSet,
convertListProductAttributeSetInstances
} from '../util/convertMaterialManagement';

module.exports = ({ config }) => {
const api = Router();
const ServiceApi = require('@adempiere/grpc-api/src/services/materialManagement')
const service = new ServiceApi(config);

/**
* GET List Accounting Combinations
* GET List Product Storage
*
* req.query.token - user token
* req.query.language - login language
Expand Down Expand Up @@ -58,5 +62,81 @@ module.exports = ({ config }) => {
}
});

/**
* POST List Product Attribute Set Instances
*
* req.query.token - user token
* req.query.language - login language
* req.query.search_value - search value optional
* req.query.context_attributes - attributes
* req.query.filters - filters to reduce list values
*/
api.post('/get-product-attribute-set', (req, res) => {
if (req.body) {
service.getProductAttributeSet({
token: req.query.token,
language: req.query.language,
// DSL Query
id: req.body.id,
uuid: req.body.uuid,
productId: req.body.product_id,
productUuid: req.body.product_uuid,
productAttributeSetInstanceId: req.body.product_attribute_set_instance_id,
productAttributeSetInstanceUuid: req.body.product_attribute_set_instance_uuid
}, (err, response) => {
if (response) {
res.json({
code: 200,
result: convertProductAttributeSet(response)
})
} else if (err) {
res.json({
code: 500,
result: err.details
})
}
})
}
});

/**
* POST List Product Attribute Set Instances
*
* req.query.token - user token
* req.query.language - login language
* req.query.search_value - search value optional
* req.query.context_attributes - attributes
* req.query.filters - filters to reduce list values
*/
api.post('/list-product-attribute-set-instances', (req, res) => {
if (req.body) {
service.listProductAttributeSetInstances({
token: req.query.token,
language: req.query.language,
// DSL Query
filters: req.body.filters,
productId: req.body.product_id,
productUuid: req.body.product_uuid,
productAttributeSetId: req.body.product_attribute_set_id,
productAttributeSetUuid: req.body.product_attribute_set_uuid,
// Page Data
pageSize: req.query.page_size,
pageToken: req.query.page_token
}, (err, response) => {
if (response) {
res.json({
code: 200,
result: convertListProductAttributeSetInstances(response)
})
} else if (err) {
res.json({
code: 500,
result: err.details
})
}
})
}
});

return api;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/************************************************************************************
* Copyright (C) 2012-2022 E.R.P. Consultores y Asociados, C.A. *
* Contributor(s): Edwin Betancourt [email protected] *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or *
* (at your option) any later version. *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
************************************************************************************/

export function convertProductAttributeValue (productAttributeValue) {
if (!productAttributeValue) {
return undefined
}

return {
id: productAttributeValue.getId(),
uuid: productAttributeValue.getUuid(),
value: productAttributeValue.getValue(),
name: productAttributeValue.getName(),
description: productAttributeValue.getDescription()
}
}

export function convertProductAttribute (productAttribute) {
if (!productAttribute) {
return undefined
}

return {
id: productAttribute.getId(),
uuid: productAttribute.getUuid(),
name: productAttribute.getName(),
description: productAttribute.getDescription(),
value_type: productAttribute.getValueType(),
is_mandatory: productAttribute.getIsMandatory(),
is_instance_attribute: productAttribute.getIsInstanceAttribute(),
sequence: productAttribute.getSequence(),
product_attribute_values: productAttribute.getProductAttributeValuesList().map(productAttributeValue => {
return convertProductAttributeValue(productAttributeValue)
})
}
}

export function convertProductAttributeSet (productAttributeSet) {
if (!productAttributeSet) {
return undefined;
}

return {
id: productAttributeSet.getId(),
uuid: productAttributeSet.getUuid(),
name: productAttributeSet.getName(),
description: productAttributeSet.getDescription(),
is_instance_attribute: productAttributeSet.getIsInstanceAttribute(),
is_lot: productAttributeSet.getIsLot(),
is_lot_mandatory: productAttributeSet.getIsLotMandatory(),
lot_control_id: productAttributeSet.getLotControlId(),
lot_char_start_overwrite: productAttributeSet.getLotCharStartOverwrite(),
lot_char_end_overwrite: productAttributeSet.getLotCharEndOverwrite(),
// Serial Attributes
is_serial: productAttributeSet.getIsSerial(),
is_serial_mandatory: productAttributeSet.getIsSerialMandatory(),
serial_control_id: productAttributeSet.getSerialControlId(),
serial_char_start_overwrite: productAttributeSet.getSerialCharStartOverwrite(),
serial_char_end_overwrite: productAttributeSet.getSerialCharEndOverwrite(),
// Guarantee Date Attributes
is_guarantee_date: productAttributeSet.getIsGuaranteeDate(),
is_guarantee_date_mandatory: productAttributeSet.getIsGuaranteeDateMandatory(),
guarantee_days: productAttributeSet.getGuaranteeDays(),
madatory_type: productAttributeSet.getMandatoryType(),
product_attributes: productAttributeSet.getProductAttributesList().map(productAttribute => {
return convertProductAttribute(productAttribute)
})
}
}

export function convertProductAttributeSetInstance (productAttributeSetInstance) {
if (!productAttributeSetInstance) {
return undefined
}

return {
id: productAttributeSetInstance.getId(),
uuid: productAttributeSetInstance.getUuid(),
description: productAttributeSetInstance.getDescription(),
guarantee_date: productAttributeSetInstance.getGuaranteeDate(),
lot: productAttributeSetInstance.getLot(),
lot_id: productAttributeSetInstance.getLotId(),
serial: productAttributeSetInstance.getSerial(),
product_attribute_set: convertProductAttributeSet(
productAttributeSetInstance.getProductAttributeSet()
)
}
}

export function convertListProductAttributeSetInstances (productAttributeSetInstancesList) {
return {
record_count: productAttributeSetInstancesList.getRecordCount(),
next_page_token: productAttributeSetInstancesList.getNextPageToken(),
records: productAttributeSetInstancesList.getRecordsList().map(productAttributeSetInstance => {
return convertProductAttributeSetInstance(productAttributeSetInstance);
})
}
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
striptags "^3.0.1"
word-wrap "^1.2.1"

"@adempiere/[email protected].3":
version "3.5.3"
resolved "https://registry.yarnpkg.com/@adempiere/grpc-api/-/grpc-api-3.5.3.tgz#372de5ff714511364dbf2d6d12dd27b6b237acb2"
integrity sha512-3/os3howhix3O8RBBajXiCxXKcxFwCEHZywrClNQKlouhqFNgviOL19JShKxjr3OjwYtcaKZhiuIWFefQdxnDw==
"@adempiere/[email protected].4":
version "3.5.4"
resolved "https://registry.yarnpkg.com/@adempiere/grpc-api/-/grpc-api-3.5.4.tgz#9a09a9e5f3d9bf5b5da0414dc76ae417571889d4"
integrity sha512-kWpq9vHDrP6OBDUOwK6hoXnKOTxmlUnSDK2Pc93tkNe8eG7cz84yAd8qIP4a6yKq6UsPWYGQ8brAtTkWRjspDQ==
dependencies:
"@grpc/grpc-js" "1.7.0"
google-protobuf "3.21.0"
Expand Down

0 comments on commit 08bfcab

Please sign in to comment.