I'm using Odoo 18. I have the following models:
- document.foo
class FooDocument(models.Model):
_name = 'document.foo'
_description = 'Foo'
date = fields.Datetime(
string='Date',
)
number = fields.Char(
string='Number',
)
- document.bar
class BarDocument(models.Model):
_name = 'document.bar'
_description = 'Bar'
date = fields.Datetime(
string='Date',
)
number = fields.Char(
string='Number',
)
- document.invoice
class InvoiceDocument(models.Model):
_name = 'document.invoice'
_description = 'Invoice'
date = fields.Datetime(
string='Date',
)
number = fields.Char(
string='Number',
)
doc_base_name = fields.Selection(
string='Base Document Type',
selection=[
('document.foo', 'Foo'),
('document.bar', 'Bar'),
],
default='document.foo',
)
doc_base_id = fields.Many2oneReference(
string='Base Document',
model_field='doc_base_name',
)
Also, I have the following view for document.invoice
<record id="document_invoice_view_form" model="ir.ui.view">
<field name="name">document.invoice.form</field>
<field name="model">document.invoice</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<field name="date" />
<field name="number" />
<field name="doc_base_name" />
<field name="doc_base_id" />
</group>
</sheet>
</form>
</field>
</record>
Then, I am doing the following actions in the Odoo web interface:
1.Creating new records of document.foo
2.Creating a new record of document.invoice
*Choosing Foo value in the doc_base_name (Base Document Type) field
*Trying to choose a value in the doc_base_id (Base Document) field, but there are no values. name_search method doesn't return values
How to solve this problem with doc_base_id
(Many2oneReference) field?
Thank you for your answers! It turned out the reason was the old version of my 18.0 branch from Github. The problem disappeared after pulling current version.