继承res.users时出现混合苹果和橙子的错误

时间:2019-09-19 06:18:30

标签: odoo odoo-12

我正在尝试在odoo 12中继承res.users。但是我遇到了混合苹果和橙子的错误。我想创建一个具有res.users模型字段的新表。

model.py

class SaleIndividual(models.Model):
    _name = 'sale.individual'
    _inherit = 'res.users'
    individual_description = fields.Char()

view.xml

<odoo>
  <record id="view_form_sale_custom_individual" model="ir.ui.view">
    <field name="name">Individual Form</field>
    <field name="model">sale.individual</field>
      <field name="inherit_id" ref="auth_signup.res_users_view_form"/>
    <field name="arch" type="xml">
        <field name="login" position="after">
          <field name="individual_description" />
            </field>
    </field>
  </record>
</odoo>

错误:

raise TypeError("Mixing apples and oranges: %s in %s" % (item, self))
TypeError: Mixing apples and oranges: sale.individual(<odoo.models.NewId object at 0x123018048>,) in res.users()

1 个答案:

答案 0 :(得分:0)

第一种方法:

如果您不想继承资源用户,请按照以下步骤操作:

class ResUsers(models.Model):
 _inherit = 'res.users'
individual_description = fields.Char()

view.xml

<odoo>
<record id="view_form_sale_custom_individual" model="ir.ui.view">
<field name="name">Individual Form</field>
<field name="model">res.users</field>
<field name="inherit_id" ref="auth_signup.res_users_view_form"/>
<field name="arch" type="xml">
    <field name="login" position="after">
      <field name="individual_description" />
        </field>
</field>

第二种方法:

如果要创建新模型,请执行以下步骤:

class SaleIndividual(models.Model):
 _name = 'sale.individual'
 _inherit = 'res.users'
individual_description = fields.Char()

在这种情况下,需要创建一个不继承res用户视图文件的新视图文件。

<odoo>
<record id="view_form_sale_custom_individual" model="ir.ui.view">
<field name="name">Individual Form</field>
<field name="model">sale.individual</field>
<field name="arch" type="xml">
    <form>
       <field name="individual_description" />
    </form>
</field>