Writing attributes

Write the values back to Odoo

Care should be taken writing values back to Odoo as it can result in data loss. A rich feature update is scheduled for development which will enable multi configuration export / import per assembly or part.

During the development of this feature, writing of multiple attribute values will become supported. Until such time, only a single value is supported. You may have multiple attribute lines, but only a single value per line.

TLDR; Only a single value per attribute line is supported for now!

The reason for this is that multiple variants are created when setting attribute line ids, and multiple default_code (Internal reference in Odoo) cannot be set using the single component's name or part number.

There is no way to generate internal references for other configurations. The CAD system has to send this data, which we cannot do at the time of writing this. It is coming in a future update.

When writing values to Odoo you require the following pieces to put the puzzle together:

  • The attribute line id

  • The attribute value operation to perform (add / update / delete)

  • The value to set (e.g. Color = Red or Legs = Steel)

This setup requires the following mappings:

  • At least 1 Property Mapping for the secondary accessor product.template.attribute_line_ids

  • At least 1 Property Mapping for the new or existing value to use (single value)

  • At least a mapping that sets product.template.default_code (or your primary search identifier in the datasource if its not default_code

You may repeat this single value setup for other attributes, as long as you follow the 'single-line-single-attribute-value' setup we will support your configuration

Create a new Property Mapping for a single attribute line id. Follow the guide to Display Single Attribute Values.

Your display in SharpSync and Odoo should now look something like this:

SharpSync
Odoo

Example: Legs

The data we want to send to Odoo is in the form

[ {attributeId} , [ {arrayOfValues} ] ]

Each value for each attribute must be combined into a final attribute value, so multiples would look like this

[ [ {attributeId1} , [ {arrayOfValues1} ] ], [ {attributeId2} , [ {arrayOfValues2} ] ] ]

Or more concisely represented

[ attribute1Values, attribute2Values ]

Data
Description

1

The attribute (this is the ID for Legs)

2

The attribute value id (this is the ID for Aluminium)

[[ 1, [2] ]]

The combined attribute id and value id

[ [ 1, [2] ],

[ 2, [11,12] ]

]

The combined attribute ids and value ids. Attribute 1 (Legs), Value ID 2 (Aluminium) Attribute 2 (Color), Value ID 5 and 8 (Red, Satin Black)

To do this, we create a mapping for the Legs (See Display Single Attribute Values )

Once this is setup, we have the ID of the attribute 'Legs', which is the value 1

Then we take the value 1 and combine it with the possible values from the attribute value ids

We do this with the following export manipulation rule

const attributeAccessorName = "attributeLegsName";
const attributeIdInOdoo = attributeAccessorName in rowData.modifications  ? rowData.modifications[attributeAccessorName] : rowData.cells[attributeAccessorName];
const isNewRow = !rowData.isFoundInSecondaryDatasource && rowData.isMissingInSecondaryDatasource;

if (isNewRow)
  return [[attributeIdInOdoo, [s]]];

return [[attributeIdInOdoo[0], [s]]];

Explanation


// The name of the property mapping accessor that contains the attribute id
const attributeAccessorName = "attributeLegsName";
// this checks if the attributeId has been modified (rowData.modifications). 
// If it has, use it, otherwise fall back to the value in the rowData.cells (value of the primary)
const attributeIdInOdoo = attributeAccessorName in rowData.modifications  ? rowData.modifications[attributeAccessorName] : rowData.cells[attributeAccessorName];
// a value checking if the row is new. If it is, there will not be an existing value
const isNewRow = !rowData.isFoundInSecondaryDatasource && rowData.isMissingInSecondaryDatasource;

if (isNewRow)
  return [[attributeIdInOdoo, [s]]];

return [[attributeIdInOdoo[0], [s]]];

Last updated