Hi,
I created a new Many2one field called grade on the stock.lot model. The grade model contains several fields, one of which is a color field:
color = fields.Integer(string="Color")
My goal is to display serial numbers with different colors in the picking view.
I tried to modify the many2many_tags widget in stock.view_picking_form using XPath to add a color_field option:
<xpath expr="//field[@name='lot_ids']" position="attributes"> <attribute name="options"> {'create': [('parent.use_create_lots', '=', True)], 'color_field': 'product_grade_id.color'} </attribute> </xpath>
However, it seems many2many_tags cannot access a child field (product_grade_id.color) directly.
As a workaround I added a related field on stock.lot that copies the grade color:
grade_color = fields.Integer( related="product_grade_id.color", string="Grade color", readonly=True, )
This works, but feels like a workaround. Is there a way to make many2many_tags use the child field directly, or a better pattern to achieve colored serial numbers in the picking view?
Thanks in advance for any suggestions.
Hello,
The many2many_tags widget can only use fields that exist directly on the same model. It seems adding a related field is the correct solution.