I have been trying to set the default domain on the product_uom field in sale.order.line. When you edit an existing quotation, it does not show units of measure in the same category as the default unit of sale. So, if you sell in Units, you'd want to see Units and dozens. Instead you see cm, g, in, etc. When you create an order, you don't have this problem because these values are set through onchange.
I thought this was going to be really simple, but I can't for the life of me understand why my attempts are failing. I've tried:
<record id="sale_order_form_view_inherit_product_uomconv" model="ir.ui.view">
<field name="name">sale.order.form.inherit</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='order_line']/tree/field[@name='product_uom']" position="attributes">
<attribute name="domain">[('category_id', '=', product_id.uom_id.category_id.id)]</attribute>
</xpath>
</field>
</record>
I've also tried
<record id="sale_order_form_view_inherit_product_uomconv" model="ir.ui.view">
<field name="name">sale.order.form.inherit</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='order_line']/tree/field[@name='product_uom']" position="replace">
<field name="product_uom" domain="[('category_id', '=', product_id.uom_id.category_id.id)]" attrs="{'readonly': [('state', 'in', ('sale','done', 'cancel'))]}" context="{'company_id': parent.company_id}" groups="product.group_uom" options='{"no_open": True}'/>
</xpath>
</field>
</record>
I get the error "Uncaught Error: AttributeError: object has no attribute 'uom_id' ". I don't really understand how this could be true. The field product_id has been declared in the view, the database maps it to product.product, and the field is definitely not empty when I go to edit the quote.
Any advice would be greatly appreciated.