如何知道在odoo中从哪个类中调用了另一个类的方法

时间:2020-03-28 07:11:25

标签: python odoo odoo-10

我有2个型号

  • 1:example.orderline
  • 2:product.product

在单独的类中

在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模型?

1 个答案:

答案 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()

通过这种方式,不会干扰其他表单视图字段的值显示。

相关问题