无法访问Many2Many字段

时间:2019-06-06 09:29:11

标签: python-3.x odoo-12

对于新的自定义模块,我在模型中添加了Many2many字段。看来可行,但是我无法从Many2many中访问视图中的字段

class ouvrage_element(models.Model):
   _name = 'ouvrage.ouvrage_element'
   _description = 'ouvrage_element'

   name = fields.Char(
      string='Nom',
      required=True)

   main_ouvrage = fields.Many2many(
      comodel_name="ouvrage",
      relation="sub_ouvrage",
      column1="main_ouvrage",
      column2="sub_ouvrage_ids")
class Ouvrage(models.Model):
   _name = 'ouvrage'
   _description = 'Ouvrage'

   name = fields.Char(
      string='Nom',
      help='Nom',
      required=True)

   sub_ouvrage_ids = fields.Many2many(
      comodel_name="ouvrage_element", 
      relation="sub_ouvrage", 
      column1="sub_ouvrage_ids", 
      column2="main_ouvrage")

<record id="view_ouvrage_form" model="ir.ui.view">
<field name="name">ouvrage.form</field>
<field name="model">ouvrage</field>
<field name="type">form</field>
<field name="priority" eval="8"/>
<field name="arch" type="xml">
<form string="Ouvrage" version="7.0">
<sheet>
<field name="sub_ouvrage_ids" widget="many2many" string="Sous-ouvrages">
    <tree>
         <field name="name"/>
    </tree>
</field>
</sheet>
</form>
</field>
</record>

“文件” /usr/lib/python3/dist-packages/odoo/models.py”,第1112行,位于_validate_fields中     引发ValidationError(“%s \ n \ n%s”%(_(“验证约束时出错”),tools.ustr(e))) odoo.tools.convert.ParseError:“验证约束时出错

字段name不存在”

1 个答案:

答案 0 :(得分:0)

sub_ouvrage_ids协同模型中的错误:ouvrage_element而不是ouvrage.ouvrage_element 感谢@ Rohit-Pandey的答案