This question has been flagged
3 Replies
5216 Views

I am working on QWEB as a Demo of my instance. I would like to know how I could insert a new field of UOM to display and select only "product.uom_categ_length"

New Field
Name: x_uom1
Type: Many2One
Relation: product.uom
Model: (The Model shall be)
Stored; Copied;

Insert the field on the VIEW of the model
<field name="x_uom1" class="oe_inline oe_no_button"/>

Current: It shows all the units
Expected: Show only the length and not creatable

Avatar
Discard
Best Answer

Try This

<field name="x_uom1" domain="[('category_id.name', '=', 'Length / Distance')]" options="{'no_create_edit': True, 'no_create':True}"/>

Avatar
Discard
Author

It works! Thanks! One more question. Can I set a default value for this? options="{'default':'m'}" or default="m", or the unit ID? Thanks so much

Author

Big issue! I found it does not work when the user switch to another language. The domain refers the name only as the name of the language. I change the category_id.name as category_id.id, since 'Length / Distance' is one of the main category of units, and the id is 4. Now I have to manually set the Area, since its not in the base. (I created it by myself)

Best Answer
def default_xuom1(self):    
    # your logic goes here and return desired result   
    return your_result   
x_uom1 = fields.Many2one('product.uom','New Field',default=default_xuom1)

Hope this will helps you


Avatar
Discard
Author

umm... could you show me how to write it on QWEB please?