将res.users继承到新模型中时出现错误

时间:2019-09-18 12:22:02

标签: odoo odoo-12

我正在尝试继承odoo12的res.users模型,但出现错误。 我的代码如下:

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

view.xml
<?xml version="1.0"?>
<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 string="Individual">        <group>
        <field name="name" />
          <field name="individual_description" />
          <label for="login" class="oe_edit_only" string="Email Address"/>
                            <h2>
                                <field name="login"
                                        placeholder="email@yourcompany.com"/>
                            </h2>
        </group>
      </form>
    </field>
  </record>

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

重复的键值违反了唯一约束   “ res_groups_users_rel_gid_uid_key”

     

详细信息:密钥(gid,uid)=(1,1)已经存在。

1 个答案:

答案 0 :(得分:1)

如果您想继承res.user,则需要编写如下代码:

用法如下:

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