Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2 Antwoorden
4778 Weergaven

When changing the state of a project, I need to write a number to the related product. Project and product have a many2many relationship:

Project_model: product_field -> many2many <- Product_model: number_field

This should be possible by adding "Automated Actions" to project model. I tried with something like that:

for record in records:
    product = record[('x_product)]
    product[('number')] = record.calc_value

When triggering the state change, I get this error:

"Expected singleton: product.template()" while evaluating
Avatar
Annuleer
Beste antwoord

The record['field_name']=value syntax is only used for a single record. Since 0, 1 or more products may exist, use records.write({'field_name':value})

Avatar
Annuleer
Auteur

Thanks for the answer, that looks promising.

But it seems that I have a basic problem with the relation: Do I need to load the product with something like that before I can access it?

products = env['product.template'].search(['id', '=', record.x_product])

Or do I have direct access to the product as it is already related with a many2many relation? Then I could directly apply the action:

record['x_product'].write({'number': record.calc_value})

None of the actually works.

PS: Is there any easy method to print values (like python print) in the Automated Actions?

Gerelateerde posts Antwoorden Weergaven Activiteit
5
dec. 23
23904
0
mrt. 24
1553
3
jan. 24
8199
2
feb. 23
4040
0
nov. 22
2271