我有2个型号
在单独的类中
在example.orderline中有一个many2one字段“ stock” stock = fields.Many2one(“ product.product”,“ Product”)
我想为字段“ stock”覆盖模型“ product.product”的name_get
方法
我成功做到了:
def name_get(self):
result = []
for record in self:
default_code = record.default_code
result.append((record.id, default_code))
return result
但是以上内容也适用于销售订单和采购订单。 如何命名get方法仅适用于example.orderline模型?
答案 0 :(得分:1)
您可以在 private boolean isMainFragment=true; //make it false when move to other fragment
@Override
public void onBackPressed() {
if(!isMainFragment){
isMainFragment=true;
//replace your MainFragment
}
else{
//your logic show dialog or super.onBackPressed()
}
}
模型视图侧使用context
属性来处理上述情况。
例如:
example.orderline
现在使用<field name="stock" context="{'display_my_name': True}"/>
方法检查上下文值。如果找到上下文密钥,请执行自定义逻辑,否则返回super。
例如:
name_get()
通过这种方式,不会干扰其他表单视图字段的值显示。