SharpSync
  • Welcome
  • Fundamentals
    • Getting Started
      • Registration
      • Landing Page
      • Support
      • Subscription
    • Data Sources
    • Property Mappings
    • Rule Templates
    • BOM Comparison
    • Data Safety
    • Troubleshooting
      • Duplicate component paths
      • OAuth 2.0
  • Data Sources
    • Autodesk Inventor
    • CSV
      • Getting Started
      • Importing a Bill of Materials (BOM)
    • MS Dynamics 365 Business Central
      • Getting Started
      • Item Fields Json & Internal Names
      • Resource Fields Json & Internal Names
      • List Names For nestedObject Mappings
    • NetSuite
      • OAuth Setup
        • Permissions
      • Suite API Setup
      • Create an uploads folder
      • Setting up a thumbnail folder
      • Authentication + Configuration
      • Common setup
        • Configure quantity mapping
        • Configure accounts mappings
        • Configure itemType mapping
        • Configure isPhantom mapping
        • Configure subsidiary mapping
        • Configure price mapping
        • Configure Where Used Link mapping
        • Configure thumbnail mapping
        • Common Mapping Rules
        • Common List names
      • Advanced Bill of Materials
      • Configure Server Side Script
        • Example Server Side Script
      • Configure SharpSync to use Server Side Script
      • Configure Routings
      • Integration tips
      • Troubleshooting
    • Odoo
      • Getting Started
        • Authentication + Configuration
        • Debugging tips
      • Common Setup
        • Map BOM Codes
        • Map BOM Types
        • Map Attribute Values
          • Reading Attributes - Overview
          • Display All Attribute Names
          • Display Single Attribute Values
          • Writing attributes
      • Product Management
      • Hosting Options
      • List Names
      • Permissions
    • Onshape
      • Getting Started
      • Setting up Derivatives
    • Propel PLM
      • Getting Started
    • SolidWorks
    • SolidWorks PDM
      • Downloading and installing the add-in
      • Configure the add-in
      • Setting up the Solidworks PDM Web 2
      • Troubleshooting
      • Submitting a BOM for update
  • Property Mappings
    • Property Mapping Settings
      • Rendering Types
    • Rule Templates
      • Import / Export
        • Append text
        • Calculate number
        • Export manipulation
        • Format as decimal number
        • Prepend text
        • Remove property
        • Replace all instances
        • Replace first instance
        • Round to nearest X
        • Select from JSON
        • Set cell value
        • Set empty cells
        • Text manipulation
      • Display
        • Number between
        • Text contains
        • Text ends with
        • Text evaluation
        • Text is a number
        • Text is exactly
        • Text is in list
        • Text is not a number
        • Text is not empty
        • Text is not in list
        • Text length between
        • Text length is exactly
        • Text maximum length
        • Text minimum length
        • Text not contains
        • Text not ends with
        • Text not starts with
        • Text starts with
  • Advanced
    • Derivatives
    • Advanced Scripting
  • User management
    • User Management
    • Application Permissions
Powered by GitBook
On this page
  • Setting up the list
  • Read individual attribute values
  • Add a New Rule To Parse the Value Ids
  • Add Blocking Rule
  1. Data Sources
  2. Odoo
  3. Common Setup
  4. Map Attribute Values

Display Single Attribute Values

PreviousDisplay All Attribute NamesNextWriting attributes

Last updated 17 days ago

Attributes in Odoo are an advanced topic. You should approach this with a lot of patience and caution.

The goal is to display a single attribute, and select a different value. Once the BOM is submitted the new value will take effect.

Setting up the list

We start by specifying the list name product.attribute. The list product.attribute is special in that you can expand upon the query by adding an attribute name at the end in square brackets. Use the steps in the previous topic to duplicate the mapping.

Read individual attribute values

To view the values of an individual Product Template's attribute in SharpSync, use the Property Mapping list product.attribute["{nestedListName"}] (see also )

Start by adding a for

product.template.attribute_line_ids

Summary of the settings below:

Setting
Value

Primary Accessor

(Unmapped)

Secondary Accessor

product.template.attribute_line_ids

List Name

product.attribute["Legs"]

List Value Selector

{id}:{name}, attribute_id : {attribute_id[0]}

Prefer Odoo Value

checked

Update Odoo on submit

Checked.

Warning! Enable only if mapping a single value !

[You have been warned!] . Always always test attribute mappings.

If you are unsure, leave this unchecked

Render Type

Advanced List

We'll specify our list name and add an attribute name 'Legs' as follows:

product.attribute["Legs"]

Click the Save button at the bottom, then the 'refresh' icon below the List Value Selectoritem.

A new list of items is returned

1:Steel, attribute_id : 1|2:Aluminium, attribute_id : 1|8:Custom, attribute_id : 1

In SharpSync make the following changes to the Property Mapping:

Setting
Value

Rendering Type

Advanced List

List Display Selector

name

List Value Selector

id

List Items

Important! Make sure the idparameter is an integer value (not wrapped in quotes "")

  • Click the Save button at the bottom.

Pro Tip: You could add a `{ "id" : 0, "name" : "" }` item to show blank values when nothing is found and trigger a display rule to warn you.

[
  { "id": 0, "name": ""},
  { "id": 1, "name": "Steel", "attributeId" : 1 },
  { "id": 2, "name": "Aluminium" , "attributeId" : 1 },
  { "id": 8, "name": "Custom" , "attributeId" : 1 }
]

You now have the values in the list, but nothing will yet display in the Bill Of Materials view.

The next step will be to parse the values from Odoo so that it automatically selects the correct value onscreen when the BOM is loaded from Odoo.

Add a New Rule To Parse the Value Ids

The values that arrive from Odoo are complex nested values (the type is nestedObject in SharpSync) and looks something like this:

[
  {
    "id": 27,
    "value_count": 2,
    "sequence": 10,
    "attribute_id": {
      "id": 1,
      "display_name": "Legs"
    },
    "value_ids": [
      {
        "id": 1,
        "display_name": "Steel",
        "color": 9
      },
      {
        "id": 2,
        "display_name": "Aluminium",
        "color": 3
      }
    ]
  },
  {
    "id": 28,
    "value_count": 2,
    "sequence": 11,
    "attribute_id": {
      "id": 2,
      "display_name": "Color"
    },
    "value_ids": [      
      {
        "id": 11,
        "display_name": "Red",
        "color": 3
      },
      {
        "id": 12,
        "display_name": "Satin Black",
        "color": 3
      },
      // ... more
    ]
  }
]

This must be converted to a more readable format for the BOM comparison screen, so we'll make use of an Import Rule.

Navigate to the Property Mapping. Add a new Import Rule to parse the values from Odoo for Legs:

Setting
Value

Rule Type

Import

Rule Name

Text Manipulation

Value

Enabled for

Odoo only

This parses the values from Odoo and filters out everything but the first value. If you want to return all the values from Odoo, change the last line from

return retVal[0];

to

return retVal;

This will return a list of 'ids' as a result, allow selection of the values from the list of values on the screen.

We can now read the values. The next step is to put an optional blocking rule in place.

Add Blocking Rule

Add a new rule which will block multiple values from being submitted to Odoo.

Navigate to the Property Mapping.

Add a new Import Rule:

Setting
Value

Rule Type

Import

Rule Name

Text Evaluation

Value

On Rule Failure Action:

block

At the time of writing, we do not support multiple value updates. You will have to change the rendering type from Advanced MultiSelect List to Advanced List (Single selection)

[
  { "id": 1, "name": "Steel", "attributeId" : 1 },
  { "id": 2, "name": "Aluminium" , "attributeId" : 1 },
  { "id": 8, "name": "Custom" , "attributeId" : 1 }
]
const attributeName = "Legs";
const valueWhenNotFound = []; 

if (!Array.isArray(s)) {
  let isArray = false;
  if (typeof s === "string" && s.trim().startsWith("[") && s.trim().endsWith("]"))
  {
    try {
      s = JSON.parse(s);
      isArray = true;
    } catch (e) {
      console.error("Failed to parse JSON string", e);
      return valueWhenNotFound;
    }
  }
  else
  {
    console.warn("s is not an array or a parsable string", typeof s);
    return valueWhenNotFound;
  }
  
  if (!isArray)
    return valueWhenNotFound;
}

const attributeValueIds = s.find((item) => item.attribute_id?.display_name === attributeName)?.value_ids || [];
var retVal = attributeValueIds.length > 0 ? attributeValueIds.map((vi) => vi.id) : valueWhenNotFound;
console.log("retVal", retVal);

if (retVal.length === 0)
{
  return valueWhenNotFound;
}

return retVal[0];
if (s && s.length > 1)  
  return { status: "failure", message: `Only a single property value is supported`, passOrBlock: `pass` };
List Names
Property Mapping