【问题标题】:Odoo SAAS: Add field from associated model into a tree view of another modelOdoo SAAS:将关联模型中的字段添加到另一个模型的树视图中
【发布时间】:2016-07-20 22:45:27
【问题描述】:

我在 res.partner 中有 2 个字段,我想根据 partner_id 字段在 account.invoice 的树视图中显示它们。我想知道如何通过树视图 Web 界面执行此操作(引用另一个模型和字段),因为 SaaS 版本不允许编程访问。

提前致谢!

【问题讨论】:

    标签: openerp saas odoo-9


    【解决方案1】:

    在您的 account.invoice 模型中为 res.partner 的字段创建相关字段

    x_invoice_preference=fields.Selection(related="partner_id.x_invoice_preference")
    

    最好在其他模型中将相关字段命名为相同名称

    小例子:

    class class1(models.Model):
       _name = 'table1'
       name = fields.Char()
    
    class class2(models.Model):
      _name = 'table2'
      table1_id = fields.Many2one('table1','table 1');
      #this how you create a related field in order to 
      #show it in the form or the tree when you select the value of the many2one field it
      # will have the same value of the vield name of the tabl1 
      name = fields.Char(related="table1_id.name",readonly=True)
    #field_name                  m2onField.field_name 
    

    【讨论】:

    • 如果您不理解我的回答,请告诉我
    • 嗨 Charif,感谢您的回复。该字段是模型“res.partner”中“选择”类型的“x_invoice_preference”。我在 account.invoice 中创建了类型选择的 x_invoice_preference 字段,并在相关字段下(在高级属性选项卡下)我输入了以下内容:x_invoice_preference = fields.SameType(related="partner_id.x_invoice_preference")。保存模型时,我收到: Unknown field name 'x_invoice_preference = fields' in related field 'x_invoice_preference = fields.SameType(related="partner_id.x_invoice_preference")' None ...我做错了什么?
    • 如果该字段是一个选择,那么您需要执行此操作 x_invoice_preference=fields.Selection(related="partner_id.x_invoice_preference")
    • 使用我的新编辑答案,您应该了解相关领域及其工作原理
    • 我很高兴你很高兴你做了很多工作谢谢你
    猜你喜欢
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 2018-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-10
    • 2022-10-25
    相关资源
    最近更新 更多