콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다

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?

관련 게시물 답글 화면 활동
5
12월 23
23904
0
3월 24
2390
3
1월 24
8979
2
2월 23
4857
0
11월 22
3059