【问题标题】:Odoo Inherited view not styledOdoo 继承的视图未设置样式
【发布时间】:2015-03-29 11:41:25
【问题描述】:

我想在 Odoo v8 中从另一个视图继承一个视图。第一个视图的 id 为:form_authority_information,继承的视图的 id 为:form_authority_information_construction_law

这是 form_authority_information

的代码
<record model="ir.ui.view" id="form_authority_information">
        <field name="name">view.name</field>
        <field name="model">company.authority_information</field>
        <field name="arch" type="xml">
            <form>
                <sheet>
                    <group colspan="4" id="content">
                        <group colspan="2" col="2" id="general">
                            <separator string="General" colspan="2"/>
                            <field name="related_field"/>
                            <field name="information_date"/>
                            <field name="information_medium" attrs="{'invisible':[('is_finished', '=', True)]}" />
                            <field name="is_finished"/>
                        </group>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

对于 form_authority_information_construction_law

<record model="ir.ui.view" id="form_authority_information_construction_law">
        <field name="name">Construction Law</field>
        <field name="model">company.authority_information.construction_law</field>
        <field name="inherit_id" ref="form_authority_information"/>
        <field name="arch" type="xml">
            <data>
                <group id="general" position="after">
                    <separator string="Construction Law" colspan="2"/>
                    <field name="construction_law_type"/>
                    <field name="building_area_type"/>
                    <field name="zoning_name" attrs="{'invisible':[('construction_law_type', '=', 'qualified')]}"/>

                </group>
            </data>
        </field>
    </record>

数据继承工作正常。我有我想在继承视图中看到的所有字段。问题是,它没有设置继承视图的样式。对于主视图,所有内容都显示在“工作表”环境中,但对于继承的视图,顺序是另一个,工作表不显示。 “attr”属性也不起作用。

有人知道这种奇怪行为的解决方案吗?

更新:图片 更新2:正常工作需要外部ID吗?

Update3:Python 代码 models.py

class company_authority_information(models.Model):
    _name = 'company.authority_information'
    # other fields...

class company_authority_information_report_committee(models.Model):
    _name = 'company.authority_information.report_committee'
    _inherit = 'company.authority_information'

提前致谢。

【问题讨论】:

  • 从视图中移除数据,它会由odoo引擎自己添加。
  • 不幸的是,这并没有什么不同。
  • 你在那里写错了模型名称,需要在继承视图中写父模型名称。 &lt;field name="model"&gt;company.authority_information&lt;/field&gt;
  • 如果我这样做,我会收到以下错误:Error details: Field zoning_name does not exist 所以看来模型应该是继承模型。否则我无法访问仅存在于继承中的字段。
  • 你能把你的python代码贴在这里吗?

标签: inheritance openerp odoo odoo-8


【解决方案1】:

尝试关注,

class company_authority_information(models.Model):
    _name = 'company.authority_information'
    # other fields...

class gut8_authority_information_report_committee(models.Model):
    _inherit = 'company.authority_information'

如果您提供_name,那么它将为此创建表,因此当您继承任何模型时,您要么保持与_inherit 相同的_name,要么不指定_name,以防_inherit 存在。如果不行,重启服务器和升级模块。

<record model="ir.ui.view" id="form_authority_information_construction_law">
        <field name="name">Construction Law</field>
        <field name="model">company.authority_information</field>
        <field name="priority" eval="50" />
        <field name="inherit_id" ref="form_authority_information"/>
        <field name="arch" type="xml">
                <group id="general" position="after">
                    <separator string="Construction Law" colspan="2"/>
                    <field name="construction_law_type"/>
                    <field name="building_area_type"/>
                    <field name="zoning_name" attrs="{'invisible':[('construction_law_type', '=', 'qualified')]}"/>
                </group>
        </field>
    </record>

【讨论】:

  • 像魅力一样工作。非常感谢你。是_name
  • 永远记住一件事,每当您想在父模型中添加或扩展某些内容时,在视图中&lt;field name="model"&gt; 必须具有父模型名称。它将视图的内容添加到模型中。因此,如果您给那里子模型,那么它不会给您任何指示,因为从语法上讲它没有错,这是合乎逻辑的。
  • 现在我遇到的问题是它继承了所有视图,而不仅仅是我想要继承的视图。我该如何解决?
  • 你能澄清更多吗?实际上发生了什么以及你想做什么。
  • 我现在有 authority_information、authority_information_report_committee 和 authority_information_construction_law。该视图每次都是所有三个视图的组合。似乎不知道何时应用哪个视图。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-03
  • 1970-01-01
  • 1970-01-01
  • 2021-04-28
相关资源
最近更新 更多