Notes |
|
(0163316)
|
malsasua
|
2024-04-17 11:09
(edited on: 2024-04-17 11:10) |
|
The error shown is raised in the following code (modules/org.openbravo.pos2/src/org/openbravo/pos2/KeymapLoader.java):
private void checkMandatoryFields(String fields[], JSONObject json, String objectIdentifier)
throws JSONException {
for (String field : fields) {
if (!json.has(field) || "null".equals(json.getString(field))) {
String errorMessage = objectIdentifier + " " + field
+ " is a mandatory field to create a new " + objectIdentifier + " from Web Pos";
log.error(errorMessage);
throw new OBException(errorMessage);
}
}
}
It is launched in the createEntity function that is only launched from the processEntity function when the obpos2_keymap_product doesn't exist.
private void processEntity(Class<? extends BaseOBObject> type, JSONArray jsonEntities,
String[] mandatoryFields, Map<String, String> uniqueProperties) throws JSONException {
JSONArray filteredEntities = filterNotDeletedObjects(jsonEntities);
deleteObjectsIfRequired(type, jsonEntities);
for (int i = 0; i < filteredEntities.length(); i++) {
JSONObject jsonEntityObject = filteredEntities.getJSONObject(i);
BaseOBObject entityInstance = getEntityInstance(type, jsonEntityObject.optString("id", null));
if (entityInstance == null) {
BaseOBObject equivalentInstance = getEquivalentInstance(type, jsonEntityObject,
uniqueProperties);
if (equivalentInstance == null) {
createEntity(type, jsonEntityObject, mandatoryFields);
} else {
updateEntity(type, equivalentInstance, jsonEntityObject);
}
} else {
updateEntity(type, entityInstance, jsonEntityObject);
}
}
}
This is why all the Keymaps are not failing.
In this case, when the entity doesn't exist, it looks for the following mandatory fields:
if (json.has("keymapProducts")) {
processEntity(OBPOS2KeymapProduct.class, json.getJSONArray("keymapProducts"),
KEYMAP_PRODUCT_MANDATORY_FIELDS);
}
public static final String[] KEYMAP_PRODUCT_MANDATORY_FIELDS = { "id", "organization", "name",
"status", "product" };
It is looking for the product property and it doesn't exist.
We checked if any of the records in keymapProducts property didn't exist in the backoffice and we found one:
{
"id": "...",
"image": null,
"organization": "0",
"priority": 0,
"useProductImg": true,
"keymapCategoryId": "...",
"productId": "...",
"name": "...",
"status": "A",
"startingDate": null,
"endingDate": null,
"isButtonMandatory": false,
"active": true
}
Although we added the "product" property to that section, it failed with a NPE in the following piece of code (modules/org.openbravo.pos2/src/org/openbravo/pos2/event/OBPOS2KeymapCategoryIsExtensibleEventHandler.java):
OBPOS2KeymapProduct keymapProduct = (OBPOS2KeymapProduct) event.getTargetInstance();
OBPOS2KeymapCategory keymapCategory = keymapProduct.getOBPOS2KeymapCategory();
Boolean canCreateProduct = keymapCategory.isStoresAllowedToAddNewProducts();
It is because the keymapCategory is null.
|
|
|
|
The issue is unable to reproduce, as per my analysis there are several calls to processEntity method which handles the createEntity methods based on certain cases.
we have mandatory defined for each of the keymap subrecords as follows:
{
"keymapCategoryProductPositions": [
"id",
"organization",
"productID",
"layoutPositionColumn",
"layoutPositionRow",
"layoutColumnSpan",
"layoutRowSpan",
"screenResolutionID"
],
"keymapCategoryProductAppearances": [
"id",
"organization",
"productID"
],
"keymapCategoryPositions": [
"id",
"organization",
"categoryID",
"positionX",
"positionY",
"layoutRowSpan",
"layoutColumnSpan",
"screenResolutionID"
],
"keymapCategoryAppearances": [
"id",
"organization",
"categoryID"
],
"keymapCategoryLayouts": [
"id",
"organization",
"keymapVersionID",
"screenResolutionID",
"cATLayoutCols",
"cATLayoutRows"
],
"keymapProductLayouts": [
"id",
"organization",
"categoryID",
"prodLayoutRows",
"prodLayoutCols",
"screenResolutionID"
],
"keymapCategories": [
"id",
"organization",
"name",
"status",
"searchKey"
],
"keymapProducts": [
"id",
"organization",
"name",
"status",
"product"
],
"keymapCategoryProductCategories": [
"id",
"organization",
"categoryID",
"productCategory"
]
}
So attaching a patch which logs the all the details of the keymap when createEntity method is invoked, also everytime a save is triggered the keymapdata from frontend is logged. |
|
|
|
We haven't been able to reproduce the problem. We have attached a diff with additional log, this can be deployed on the customer environment, and if the problem happens again the issue can be reopened with the additional information. |
|
|
(0165635)
|
Leyre
|
2024-06-06 08:52
|
|
Hello Team.
After adding the attached log in this issue the problem happened again.
Client: CDS
EWI:
· Error:
org.openbravo.base.exception.OBException: org.openbravo.pos2.OBPOS2KeymapProduct product is a mandatory field to create a new org.openbravo.pos2.OBPOS2KeymapProduct from Web Pos
· Data type: Keymap
· Creation date: 04-06-2024 22:29:19
· Attached the Terminal log related to the EWI: newcasewithlog.csv |
|
|
|
Keymap editor is officially not supported, as per decision of Product Management. We have reported a separate issue to hide the functionality from the POS so that customers cannot use it by mistake:
https://issues.openbravo.com/view.php?id=55798 [^]
|
|