Hello,
In Odoo 15, I have a form view with the following code to make the company_id field mandatory:
<xpath expr="/form/sheet//field[@name='company_id']" position="attributes"> <attribute name="required">1</attribute> </xpath>
This works as expected.
Now, I want to automatically populate the company_id field with the current user's company when creating a new record, using XML only. I've tried adding the following:
<xpath expr="/form/sheet//field[@name='company_id']" position="attributes"> <attribute name="required">1</attribute> <attribute name="context">{'default_company_id': company_id}</attribute> </xpath>
However, this does not auto-fill the field as intended.
Is there a way to achieve this purely through XML in Odoo 15? Or is it necessary to implement this functionality using Python code?