Hello there :)
I have a little custom made app that exports product variant's data to a CSV file and now, I'd like to add their attributes. When I export product variants directly through Odoo and I add the column "product_template_attribute_value_ids", I get the attribute names and values as a text, for example "Size: XXL, Color: red" for a t-shirt.
Unfortunately I do not know how to get this data through my script.
Here is a simplified version of my script, including my latest try to get the attributes:
with tempfile.NamedTemporaryFile(prefix="product data", suffix=".csv") as data_file:
headers = ['ID', 'Internal Reference', 'Name', 'German Name', 'Attributes', 'Attributes German','GTIN / EAN']
writer = pycompat.csv_writer(data_file, quoting=1)
writer.writerow(headers)
product_ids = product_obj.search([])
for product in product_ids:
english_product_name = product.with_context({'lang': 'en_US'}).name
german_product_name = product.with_context({'lang': 'de_DE'}).name
# trying to get the attributes starts here
english_attributes = ''
german_attributes = ''
for attributes in product.attribute_line_ids:
for attribute_values in attributes.product_template_value_ids:
english_attributes += attribute_values.with_context({'lang': 'en_US'}) + ','
german_attributes += attribute_values.with_context({'lang': 'de_DE'}) + ','
# trying to get the attributes ends here
writer.writerow(
[product.id, product.default_code, english_product_name, german_product_name, english_attributes, german_attributes, product.barcode])
This does not work and instead of the actual attributes of the particular variant, this lists all the attribute's values of the product's template, e.g. "S,L,XL,XXL,XXXL,blue,red,green,black,yellow,".
Does anyone know how to get the attribute's names and value for each product's variant?