Hengky Zhang, thank you for your answer. I finally have time to try this out but I ran into this problem.
Here's my code:
.py file:
class my_stock_production_lot(models.Model):
_name = 'stock.production.lot'
_inherit = 'stock.production.lot'
product_available_qty=fields.Float(string='Quantity Available', related='product_id.qty_available')
@api.multi
def name_get(self):
res = []
for lot in self:
if lot.name:
display_value = lot.name
if lot.product_available_qty > 0:
display_value += ' ['
display_value += '%.0f Units' % lot.product_available_qty
display_value += ']'
res.append((lot.id, display_value))
return res
.xml file:
<record id="view_pack_operation_lot_form_inherit" model="ir.ui.view">
<field name="inherit_id" ref="stock.view_pack_operation_lot_form"/>
<field name="model">stock.pack.operation</field>
<field name="arch" type="xml">
<xpath expr="//field[@name='pack_lot_ids']/tree/field[@name='lot_id']" position="replace">
<field name="lot_id" invisible="context.get('only_create', False)"
domain="[('product_id','=', parent.product_id)]"
context="{'product_id': parent.product_id, 'show_qty': True}"/>
</xpath>
</field>
</record>
My question:
1) Was I right on how to include 'show_qty' in the context of the .xml file?
2) I cannot reference context in the name_get method. name_get cannot accepts a context parameter. When I checked the self._context variable in the debugger, I did not see {'show_qty': False}. I cannot do "if self._context.get('show_qty'):..." either since it is a frozen dict. So how can I determine in name_get whether I should display the default name or my customize name[qty]???
Can you please explain possibly with example? Thanks.