【问题标题】:How to use the inherit attribute in OpenERP7?如何在 OpenERP 7 中使用继承属性?
【发布时间】:2015-10-07 13:23:33
【问题描述】:

我正在尝试将“mobil_brigada”字段添加到现有视图view_operaciones_brigadas_form,该视图位于名为operaciones 的模块中。

我的 Python 代码:

class operaciones_mobil(osv.osv):
   _name = 'operaciones.mobil'
   _inherit = 'operaciones.brigada'
   _columns = {
      'mobil_brigada': fields.many2one('add.mobil', 'Numero de Mobil', help="Numero de celular asignado a la brigada")
   }

我的 XML 代码:

<openerp>
<data>
    <!-- begin -->
     <record id="view_operaciones_mobil_form" model="ir.ui.view">
        <field name="name">operaciones.mobil.form</field>
        <field name="model">operaciones.mobil</field>
        <field name="inherit_id" ref="operaciones.view_operaciones_brigadas_form" />
         <field name="priority">100</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
           <field name="supervisor" position="after">
              <field name="mobil_brigada"/>
           </field>
        </field>
    </record>
    <!--/ end -->    
</data>

这是我要修改的原始视图:

<record id="view_operaciones_brigadas_form" model="ir.ui.view">
                <field name="name">operaciones.brigada.form</field>
                <field name="model">operaciones.brigada</field>
                <field name="arch" type="xml">
                    <form string="Employee">
                        <header>
                            <field name="state" widget="statusbar" />
                        </header>
                        <sheet>
                            <div class="oe_title">
                                <label for="ficha" class="oe_edit_only"/>
                                <h1>
                                    <field name="ficha" />
                                </h1>
                                <label for="tipo" class="oe_edit_only"/>
                                <h1>
                                    <field name="tipo"/>
                                </h1>
                                <label for="proyecto" class="oe_edit_only"/>
                                <h1>
                                    <field name="proyecto"/>
                                </h1>
                            </div>
                            <group>
                                <group colspan="8">
                                    <field name="tecnico1"/>
                                    <field name="tecnico2"/>
                                </group>
                                <group colspan="4">
                                    <field name="supervisor"/>
                                    <!-- it supposed to be here -->
                                </group>
                            </group>
                        </sheet>
                    </form>
                </field>
    </record>

但是什么都没有发生,我没有在控制台中收到错误,我是管理员,我已将 XML 文件添加到 __openerp__.py... 我做错了什么?

【问题讨论】:

  • 代码中的缩进问题是复制粘贴的症状,还是它们实际上是按照您粘贴的方式构建的?如果是这样,这是您应该首先解决的一个问题,然后看看您会遇到什么错误。
  • 它不是身份问题.. xD 你让我检查我的代码,但谢谢。

标签: python xml python-2.7 odoo openerp-7


【解决方案1】:

如果您只想修改现有表单,则必须从 Python 模型中删除属性 _name。在你的情况下:

class operaciones_mobil(osv.osv):
   _inherit = 'operaciones.brigada'
   _columns = {
      'mobil_brigada': fields.many2one('add.mobil', 'Numero de Mobil', help='Numero de celular asignado a la brigada')
   }

【讨论】:

  • Forvas,我做到了,我得到了这个错误,Error de contexto: Vista operaciones.mobil.form [view_id: 1116, xml_id: inventario_mobil.view_operaciones_mobil_form, model: opaciones.mobil, parent_id: 1042]" 解析时/home/run/openerp8/openerp/addons/inventario_mobil/ext_operaciones.xml:4,近
  • 好的,现在你刚刚从 Python 代码中删除了 _name 行,你不能再使用 operaciones.mobil 模型了。因此,更改您的 XML 代码,在 ID 为 view_operaciones_mobil_form 的记录中,您必须将模型 operaciones.mobil 替换为 operaciones.brigada
  • 我很高兴你做到了@Jorge。如果您认为它对您有所帮助,请不要忘记将答案设置为正确以关闭问题;)
【解决方案2】:

您正在使用这种继承创建两个表(使用_name_inherit 属性)。如果您只想向现有表添加新功能,则应删除 _name 属性。如果您想保留两个表格(operaciones.mobiloperaciones.brigada),请尝试为模型 operaciones.mobil 创建另一个完整的表格,因为您不能将表格与不同的模型混合使用。

【讨论】:

    【解决方案3】:

    在你的代码中你写_name = 'operaciones.mobil' 这意味着您创建了新模型或表格 所以你不能像你写的那样继承视图

    您需要创建新视图,包括旧视图和新文件,因此您的最终代码可能是

    <record id="view_operaciones_mobil_form" model="ir.ui.view">
            <field name="name">operaciones.mobil.form</field>
            <field name="model">operaciones.mobil</field>
            <field name="inherit_id" ref="operaciones.view_operaciones_brigadas_form" />
             <field name="priority">100</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                  <form string="Employee">
                            <header>
                                <field name="state" widget="statusbar" />
                            </header>
                            <sheet>
                                <div class="oe_title">
                                    <label for="ficha" class="oe_edit_only"/>
                                    <h1>
                                        <field name="ficha" />
                                    </h1>
                                    <label for="tipo" class="oe_edit_only"/>
                                    <h1>
                                        <field name="tipo"/>
                                    </h1>
                                    <label for="proyecto" class="oe_edit_only"/>
                                    <h1>
                                        <field name="proyecto"/>
                                    </h1>
                                </div>
                                <group>
                                    <group colspan="8">
                                        <field name="tecnico1"/>
                                        <field name="tecnico2"/>
                                    </group>
                                    <group colspan="4">
                                        <field name="supervisor"/>
                                        <!-- Your New Field  -->
                                        <field name="mobil_brigada"/>
                                    </group>
                                </group>
                            </sheet>
                        </form>
               </field>
            </field>
        </record>
    

    【讨论】:

      猜你喜欢
      • 2017-12-18
      • 2015-08-23
      • 1970-01-01
      • 2014-10-06
      • 2012-02-09
      • 1970-01-01
      • 2016-07-08
      • 1970-01-01
      • 2014-02-03
      相关资源
      最近更新 更多