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

Dear all,

I am working on Odoo v12 and have a problem with a many2many field.
My many2many field is related to "res.users" and since it is a many2many, for some records I have more than one value that are passed to the actual object.
I have a variable and need to check if the variable value is on the many2many field,  and remove all other records from the object.

    my_variable = 42
    my_relatedfield_ids.ids = res.users(9, 42)

From the above result for the "my_relatedfield_ids.ids", how can I remove the value "9" and keep the value "42" which is the desired value to work with?

For obtaining the "my_relatedfield_ids" I have used:

     filtered_result = object.mapped("my_relatedfield_ids")     #Where "object" contains the results from a search with a specific domain using self.env...

After this, if I print "filtered_result" I get:

     print(filtered_result)      : res.users(9, 42)
    print(filtered_result.ids) : res.users(9, 42)

My related field is declared as:

my_relatedfield_ids = fields.Many2many('res.users', relation='relatedmodel_rel_users', column1='id',column2='name')

What I need to do is to remove the excess values from this object and leave only the value "42" which is the value I need to work with and it is on "my_variable".

I need to keep it like: res.users(42)

Can you help me please?

Best regards

Paulo


아바타
취소
베스트 답변

Hi,

For removing value from many2many field please refer the answer given for this question: Removing elements from many2many field


Thanks

아바타
취소
작성자

Thank you @Niyas,

I have solved my problem and reading the url you sent I have found additional solutions for my problem.

Thank you once again

Best regards

Paulo

베스트 답변

You can write as following to get only my_variable from my_relatedfield_ids.


only_my_variable_record = my_relatedfield_ids.filtered(lambda l : l.id == my_variable)​

아바타
취소
관련 게시물 답글 화면 활동
1
6월 19
7188
1
8월 24
7937
1
2월 25
21111
3
9월 25
309
1
9월 25
1440