From 08bfcab39075ba05a01cb0f4aedf77ecf0526c4f Mon Sep 17 00:00:00 2001 From: Edwin Betancourt Date: Mon, 31 Oct 2022 12:21:50 -0400 Subject: [PATCH] feat: List Product Attribute Instances. (#62) * feat: List Product Attribute Instances. * feat: Add get Product Attribute Set. * update package.json --- package.json | 2 +- .../adempiere/material-management/index.js | 82 ++++++++++++- .../util/convertMaterialManagement.js | 110 ++++++++++++++++++ yarn.lock | 8 +- 4 files changed, 196 insertions(+), 6 deletions(-) create mode 100644 src/modules/adempiere-api/api/extensions/adempiere/util/convertMaterialManagement.js diff --git a/package.json b/package.json index 1ea3f9ce..bb89d701 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/modules/adempiere-api/api/extensions/adempiere/material-management/index.js b/src/modules/adempiere-api/api/extensions/adempiere/material-management/index.js index 2aaaf313..b39b839f 100644 --- a/src/modules/adempiere-api/api/extensions/adempiere/material-management/index.js +++ b/src/modules/adempiere-api/api/extensions/adempiere/material-management/index.js @@ -15,6 +15,10 @@ import { Router } from 'express'; import { convertEntitiesListFromGRPC } from '../util/convertData'; +import { + convertProductAttributeSet, + convertListProductAttributeSetInstances +} from '../util/convertMaterialManagement'; module.exports = ({ config }) => { const api = Router(); @@ -22,7 +26,7 @@ module.exports = ({ config }) => { const service = new ServiceApi(config); /** - * GET List Accounting Combinations + * GET List Product Storage * * req.query.token - user token * req.query.language - login language @@ -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; }; diff --git a/src/modules/adempiere-api/api/extensions/adempiere/util/convertMaterialManagement.js b/src/modules/adempiere-api/api/extensions/adempiere/util/convertMaterialManagement.js new file mode 100644 index 00000000..c339e40f --- /dev/null +++ b/src/modules/adempiere-api/api/extensions/adempiere/util/convertMaterialManagement.js @@ -0,0 +1,110 @@ +/************************************************************************************ + * Copyright (C) 2012-2022 E.R.P. Consultores y Asociados, C.A. * + * Contributor(s): Edwin Betancourt EdwinBetanc0urt@outlook.com * + * 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 . * + ************************************************************************************/ + +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); + }) + } +} diff --git a/yarn.lock b/yarn.lock index 7de4f7eb..a910bfe0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -24,10 +24,10 @@ striptags "^3.0.1" word-wrap "^1.2.1" -"@adempiere/grpc-api@3.5.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/grpc-api@3.5.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"