【问题标题】:How to related a field to another from other model?如何将一个字段与其他模型的另一个字段相关联?
【发布时间】:2021-03-29 17:30:17
【问题描述】:

我想将字段 client_order_refsale.order 模型带到 mrp.workorder 。我这样做了,但是当我运行时,它没有显示任何价值。有什么问题?

class MRPWorkOrder(models.Model): 
    _inherit = 'mrp.workorder'

    nro_viaje_id = fields.Many2one('sale.order', string="Nro de Viaje")
    nro_viaje = fields.Char(related='nro_viaje_id.client_order_ref', store=True)

视图扩展:

<record id="view_workorder_form_inherit" model="ir.ui.view">
    <field name="name">view.workorder.form.inherit</field>
    <field name="model">mrp.workorder</field>
    <field name="inherit_id" ref="mrp.mrp_production_workorder_tree_editable_view"/>
    <field name="arch" type="html">
        <xpath expr="//field[@name='workcenter_id']" position="after">
              <field name="nro_viaje" string="Viaje" optional="show" readonly="True">
              </field>
        </xpath>
    </field>
</record>

【问题讨论】:

  • 字段声明没问题。可以分享一下包含该字段的 XML 视图吗?
  • 是的,这里是 view.workorder.form.inheritmrp.workorder 记录>
  • 我还是没有解决。我不知道为什么它没有显示任何价值和错误
  • 您是否将您的xml 文件包含在manifest 文件中?
  • 是的,我做到了,但还是没有

标签: odoo odoo-10


【解决方案1】:

这是我运行它时显示的错误@Tiki

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/odoo/odoo/odoo/http.py", line 639, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/odoo/odoo/odoo/http.py", line 315, in _handle_exception
    raise exception.with_traceback(None) from new_cause
odoo.tools.convert.ParseError: while parsing /opt/odoo/odoo/custom_addons/mrp_custom/views/views.xml:37, near
<record id="view_workorder_form_inherit" model="ir.ui.view">
            <field name="name">view.workorder.form.inherit</field>
            <field name="model">mrp.workorder</field>
            <field name="inherit_id" ref="mrp.mrp_production_workcenter_tree_view_inherit"/>
            <field name="arch" type="html">
                <xpath expr="//field[@name='workcenter_id']" position="after">
                    <field name="nro_viaje" string="Viaje" optional="show" readonly="True"/>
                </xpath>
            </field>
        </record>

【讨论】:

  • 你有什么版本的odoo?您确定它是标签所示的版本 10 吗?因为您在问题主体 (mrp_production_workorder_tree_editable_view) 中继承的视图在 odoo-10 中不存在,但在 odoo-14 中存在。
  • 对不起 Tiki,我忘了告诉你我正在使用 odoo 14
  • 还有其他方法可以关联该字段吗?
  • 我测试过,效果很好。 client_order_ref 可能为空的唯一原因是因为 nro_viaje_id 为空或因为订单没有填写该字段。
  • Tiki,你能告诉我如何测试 client_order_ref 是否为空吗?
猜你喜欢
  • 1970-01-01
  • 2022-10-16
  • 1970-01-01
  • 2012-12-24
  • 2021-09-16
  • 1970-01-01
  • 2021-04-30
  • 1970-01-01
  • 2018-01-28
相关资源
最近更新 更多