【问题标题】:Simple odoo many2one multiple context returns no value简单的 odoo many2one 多上下文不返回值
【发布时间】:2019-07-30 07:17:05
【问题描述】:

我在 sale.order.line 中有一个 many2one 字段。 它指向与 product.product 和 res.partner 有关系的自定义模型。

我希望这个新字段根据产品和客户(在 sale.order.line 中)返回自定义模型中的记录名称。

我在 sale.order.line.form.readonly XML 视图中添加了<field name="x_product_customer_reference" string="Product Customer Reference" context="{'default_x_customer_id': order_partner_id, 'default_x_product_id': product_id}"/>

但新字段保持为空。为什么它不起作用? ...

【问题讨论】:

  • 如果可能的话,请您在这里分享您的示例代码。
  • 我在 Saas 上使用了 odoo 开发者模式。这是 sale.order.line 中的 XML 视图 <field name="x_product_customer_reference" string="Product Customer Reference" context="{'default_x_customer_id': order_partner_id, 'default_x_product_id': product_id}"/> 我的自定义模型 x_customer_product_reference 有两个 many2one 字段,x_customer_idx_product_id
  • 域也运行良好,但无法设置默认值

标签: xml odoo


【解决方案1】:

请写下面的代码

<field name="x_product_customer_reference" string="Product Customer Reference" context="{'default_x_customer_id': partner_id, 'default_x_product_id':product_id}"/>

请注意,partner_id 字段应该在销售订单行中,所以请在销售订单行中创建一个不可见的 partner_id 字段,否则请按照以下代码进行操作

<field name="x_product_customer_reference" string="Product Customer Reference" context="{'default_x_customer_id': parent.partner_id, 'default_x_product_id':product_id}"/>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多