Skip to Content
Menu
This question has been flagged
1 Reply
336 Views

Hi All,

Im trying to write an automation to generate an internal reference based on variant attributes.

I have created an automation to activate on creation, filtered to only act on products with attributes. Here is the code, it doesn't seem to work but I cant think of why, can anyone suggest something to try?


variant_values = [] for line in record.attribute_line_ids: for value in line.value_ids: variant_values.append(value.name) # Create the internal reference base_reference = record.default_code or "PROD" # This code will change, just a place holder for now to test
​ new_internal_ref = base_reference + "-" + "-".join(variant_values) # update the record record.write({'default_code': new_internal_ref})


Avatar
Discard
Best Answer

It looks legit, only the # This code will change, new_internal_ref has an incorrect indentation which may break the code (it is is not a copy and paste error).

For some pythoner, the first few lines maybe written as a single line variant_values = record.attribute_line_ids.mapped('value_ids.name') or list comprehension variant_values = [value.name for line in record.attribute_line_ids for value in line.value_ids]


But I feel you. I've had several years of coding blind with Oracle Rightnow, just put in the code and hope it to work without IDE syntax support or debugging. With Odoo, for these kind of code, i still put it in a def in a self-host instance to make sure they work before pasting them into the automation.


Avatar
Discard