Read BOM WorkCenters

Create a new Property Mapping with the following settings:

Setting
Value

Property Name / Header

Operation WorkCenters

Accessor

operationWorkCenters

Primary Property

(Unmapped)

Secondary Property

mrp.bom.operation_ids

Update Odoo on Submit

false

[not here, we'll do it for the individual operations]

List Name

mrp.workcenter

List Value Selector

{id}:{resource_id[1]}

Rendering Type

Advanced Multi Select List

List Display Selector

name

List Value Selector

id

List items

Copied from the List Value (and formatted as a JSON array) but should look something like this

[
  { "id": 1, "name": "Galvanizing Station" },
  { "id": 2, "name": "Drill Station 1"  }
]

Enabled

true

Prefer Odoo Value

true

After adding the new Property Mapping, add an import rule

Setting
Value

Type

import

Name

Text Manipulation

Process for {Primary}

false

Process for Odoo

true

JavaScript expression


if (!s)
  return [];

if (Array.isArray(s)) 
  return s.map((item) => item.workcenter_id["id"]);

if (typeof s === "string") {
  try {
    const parsed = JSON.parse(s);
    if (Array.isArray(parsed)) {
      return parsed.map((item) => item.workcenter_id["id"]);
    } else {
      console.log("Parsed operationWorkCenters JSON is not an array, it is " + typeof parsed, parsed);
      return [];
    }
  } catch (e) {
    console.log("Invalid operationWorkCenters JSON string:", s, "Error:", e.message);
    return [];
  }
}

console.log("Input string for operationWorkCenters is not an array or valid JSON string, it is " + typeof s, s);
return [];

Last updated