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

Hi there,


I am trying to use a reference field to allow any model selection. I have the following models


class eaxpl_workflow(models.Model):
_name = 'eaxpl.workflow'

    document_model_id = fields.Many2one('ir.model')

class eaxpl_workflow_instance(models.Model):
_name = 'eaxpl.workflow_instance'

workflow_id = fields.Many2one('eaxpl.workflow', string="Workflow", required=True)
document_model_id = fields.Many2one('ir.model', related='workflow_id.document_model_id')

document_reference = fields.Reference(
selection=??????
)

The question is what to put in selection attribute of the reference field to limit the model selection to the model which is populated in the document_model_id field?


I have found the following snippet, but it has no context of the current model.


    @api.model
def _reference_models(self):
models = self.env['ir.model'].sudo().search(
[('state', '!=', 'manual')])
return [(model.model, model.name)
for model in models
if not model.model.startswith('ir.')]

Is it even possible? How would you approach such a problem?

아바타
취소
베스트 답변

Hello Artur Roszczyk,

You need to add the model list as per your requirement in the selection attribute in the document_reference field.

Please find code in Comment. 

Also, you can refer to below documentation link for better understanding.
https://www.cybrosys.com/blog/reference-fields-in-odoo

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari 

아바타
취소

document_reference = fields.Reference(selection=’_selection_target_model’)

@api.model
def _selection_target_model(self):
return [(model.model, model.name) for model in self.env['ir.model'].sudo().search([('name', '=', self._name)])]

관련 게시물 답글 화면 활동
1
7월 23
3862
1
8월 25
426
1
8월 25
407
4
7월 25
1719
1
7월 25
980