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

Hello odooers,

I hope you a are doing well.

I have one question. I want to use many2one field as dynamic e.g. dynamic model name on onchange of some field.


Actually i have taken one many2one field model_id (ir.model) on onchange of model_id i want to set that model as many2one field relation with field.


I have tried with many ways, didn't find any solution. onchange return attribute also not works like dynamic domain.


Thanks in advance. 


Regards

Haresh Kansara

아바타
취소
베스트 답변

There a field called Reference
Example of how to use it:

fields.Reference(selection='_ select_target_model', string="Source Document")


아바타
취소
베스트 답변

Reference field is perfectly fit with your requirement. also, it doesn't require to take many2one field in ir.model
https://github.com/odoo/odoo/blob/12.0/odoo/addons/test_new_api/models.py#L274


아바타
취소
작성자

thanks, it's very helpful for me. But now i have question, in reference field i can select only one record as many2one. So is there any way to select multiple records from reference field?

Thanks

No there is no way to select multiple records.

but if you want to achieve by extending reference field many2one part with many2many at client and server side

베스트 답변

Hi,

Actually if you achieved it some how means, How it will work ? It will generate inconsistency of the data.  Suppose if in the first record, you choose the model as res.partner , so right now the co-model of dynamic field you specified will be res.partner, and if you selected a record and saved, suppose the id be 11 of model res.partner.

Later, in the second record, you choose the model as sale.order , so the co-model for the dynamic field will be now sale.order, and if you choose record and saved, let it be with ID 10. Now what happens is that, in the first record, you will have sale.order(11) instead of res.partner(11).

So, I don't think this will work out.

If you really want to implement this and if you have only need to select a few models, make many2one fields of necessary models and try to hide the unwanted many2one field based on the condition.

Thanks

아바타
취소
작성자

Not that problem. actually i want to use in wizard to prepare some data based on selected model and record. So at a time user can select only one model and one record and after second time user open wizard then other model and other records. So not problem of model change. but question is how to achieve it?

관련 게시물 답글 화면 활동
3
7월 24
4652
1
9월 23
6636
1
1월 22
12203
8
11월 16
4139
2
2월 25
6075