# How to Query model id from a function?

**URL:** https://discuss.tryton.org/t/how-to-query-model-id-from-a-function/8816
**Category:** Developer
**Created:** [September 5, 2025, 3:35pm UTC](https://discuss.tryton.org/t/how-to-query-model-id-from-a-function/8816 "2025-09-05T15:35:34Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![bromoapp](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/b/71c47a/32.png) [@bromoapp](https://discuss.tryton.org/u/bromoapp)
#### Post date: [September 5, 2025, 3:35pm UTC](https://discuss.tryton.org/t/how-to-query-model-id-from-a-function/8816/1 "2025-09-05T15:35:34Z")

</div>

I have below code:

```auto
class RAGQuotationReportForm(ModelView):
    'RAG Quotation Report Start'
    __name__ = 'ltl.crm.rag.quotation.report.form'

    quotation = fields.Many2One('ltl.crm.rag.quotation', 'Quotation', required=True)

    subject = fields.Char('Subject', readonly=True)
    to_company = fields.Char('To Company', readonly=True)
    to_company_address = fields.Many2One('ltl.company.address', 'To Company Address',
        domain=[
            ('company', '=', Eval('company_id'))
        ],
    )

    company_id = fields.Function(fields.Many2One('ltl.company', 'Company ID'),'get_company_id')

    def get_company_id(self, name):
        if self.quotation:
            return self.quotation.proposal.client.company
        else:
            return None

```

My objective is to show a list of Company’s addresses, based on selected Company (which the quotation belongs to).  
My steps:

1. User select a quotation from **Many2One** selection
2. Then select a company address from **Many2One** selection, with domain restriction based on selected quotation’s company.
3. So I point the **Eval** to a function field → **company\_id** that called selected quotation’s company

But when I do console logging at **CompanyAddress** class, what I got is like below:

```auto
INFO:trytond.modules.ltl_company.model.company_address:>>>>>>>>>>>>>> [['company', '=', None]] [company_address.py:46]

```

The **company\_id** field Function seems doesn’t work. Does anybody knows how the right way to do this?

Bromo

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [September 6, 2025, 9:00am UTC](https://discuss.tryton.org/t/how-to-query-model-id-from-a-function/8816/2 "2025-09-06T09:00:29Z")

</div>

The `company_id` field being a [`Function` field](https://docs.tryton.org/latest/server/ref/fields.html#function) with a simple [`getter`](https://docs.tryton.org/latest/server/ref/fields.html#trytond.model.fields.Function.getter), it gets updated only when read (so on load or reload). But if you want to have accurate value while being edited, you need to use a `getter` that is always an [`on_change_with`](https://docs.tryton.org/latest/server/topics/models/fields_on_change.html) method.
