Display Single Attribute Names
Last updated
Last updated
The goal is to display a single attribute, and select a different value. Once the BOM is submitted the new value will take effect.
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.
To view the values of a Product Template's attributes in SharpSync, use the Property Mapping list product.attribute["{nestedListName"}]
(see also )
Start by adding a for
product.template.attributes
Primary Accessor
(Unmapped)
Secondary Accessor
product.template.attributes
List Name
product.attribute
List Value Selector
{id}:{name}
Prefer Odoo Value
checked
Update Odoo on submit
Do NOT enable. We'll enable the next mapping.
Render Type
Advanced List
Open the Property Mapping > Settings and enter a List Name
of
product.attribute
Click the Save
button. You'll immediately see results in the List preview. Typically you would select a single name from the list returned. For my use-case, I was returned the list below, and I picked the value 'Legs'
1:Legs|2:Color|3:Duration|5:Finish
The new list must be formatted into a list that SharpSync can understand. We'll make use of the Advanced List
option which lets us customize the values
You can use ChatGPT or CoPilot with this prompt to easily convert the data returned from Odoo. Use the following prompt:
Convert the following string into a JSON array with "id" and "name" key value pair objects. The keys must be integers
After converting the values, you'll get a list like this
Copy and paste the values to the List Items
text area (It becomes visible after selecting a render type of Advanced List
).
We'll apply the Prefer Odoo Value
checkbox setting here so that we always get shown the Odoo value. Check the checkbox to display values from our secondary source in favor of values from the Primary CAD / PDM / PLM Source.
Click the Save
button at the bottom
If you pull a BOM from Odoo, you'll now be able to select an attribute from the list.
We want to take this a step further. We don't just want to read whether I have a 'Legs' attribute on the product template. I want to also read the value of the 'Legs' attribute for the product template.
Let's go ahead and add a new property mapping.
product.template.attribute_line_ids
Summary of the settings below:
Primary Accessor
(Unmapped)
Secondary Accessor
product.template.attributes
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 Selector
item.
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:
Rendering Type
Advanced List
List Display Selector
name
List Value Selector
id
List Items
Click the Save
button at the bottom.
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.
The values that arrive from Odoo are complex nested values (the type is nestedObject
in SharpSync) and looks something like this:
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:
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
to
This will return a list of 'ids' as a result, allow selection of the values from the list of values on the screen.
This deals with the values. The next step is to put an optional blocking rule in place.
Add a new rule which will block multiple values from being submitted to Odoo.
Navigate to the Property Mapping.
Add a new Import Rule:
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)
Start by adding a for