Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
5204 มุมมอง

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
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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})

อวตาร
ละทิ้ง
ผู้เขียน

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?

Related Posts ตอบกลับ มุมมอง กิจกรรม
Automated Action to Python Code แก้ไขแล้ว
5
ธ.ค. 23
23904
0
มี.ค. 24
2340
3
ม.ค. 24
8898
2
ก.พ. 23
4814
0
พ.ย. 22
2955