Python 带有xpath的继承字段不会出现在最终视图上-Odoo 12

Python 带有xpath的继承字段不会出现在最终视图上-Odoo 12,python,odoo,Python,Odoo,我一直在尝试向account.invoice.line模型添加一个字段,这是一个多个字段,我在自定义模块中这样声明: class AccountInvoiceLine(models.Model): """ Model to add withholding concepts into the base invoice model """ _inherit = "account.invoice.line" concept_id = fields.

我一直在尝试向account.invoice.line模型添加一个字段,这是一个多个字段,我在自定义模块中这样声明:

class AccountInvoiceLine(models.Model):

    """
        Model to add withholding concepts into the base invoice model
    """

    _inherit = "account.invoice.line"

    concept_id = fields.Many2one(
        'account.wh.islr.concept',
        string='Withholding Concept',
        required=False,
        help="Withholding concept asociated to this invoice line")
问题是,我无法通过直接将此字段插入此模型的相应xml视图(account.invoice.line)来将其添加到视图中,因为基本Odoo帐户模块在其基本发票视图中定义了一个树状视图,其中包含将发票连接到其行的字段,即**invoice\u line\u id

                            <field
                                name="invoice_line_ids"
                                nolabel="1"
                                widget="section_and_note_one2many"
                                mode="tree,kanban"
                                context="{'type': type, 'journal_id': journal_id, 'default_invoice_id': id}"
                            >
                                <tree string="Invoice Lines" editable="bottom">
                                    <control>
                                        <create string="Add a line"/>
                                        <create string="Add a section" context="{'default_display_type': 'line_section'}"/>
                                        <create string="Add a note" context="{'default_display_type': 'line_note'}"/>
                                    </control>

                                    <field name="sequence" widget="handle"/>
                                    <field name="product_id" domain="[('sale_ok','=',True)]"/>
                                    <field name="origin" invisible="1"/>
                                    <field name="is_rounding_line" invisible="1"/>
                                    <field name="name" widget="section_and_note_text"/>
                                    <field name="display_type" invisible="1"/>
                                    <field name="company_id" invisible="1"/>
                                    <field
                                        name="account_id"
                                        groups="account.group_account_user"
                                        domain="[('company_id', '=', parent.company_id), ('internal_type', '=', 'other'), ('deprecated', '=', False)]"
                                        attrs="{'required': [('display_type', '=', False)]}"
                                    />
                                    <field name="account_analytic_id" groups="analytic.group_analytic_accounting"
                                        domain="[('company_id', '=', parent.company_id)]"
                                        context="{'default_partner_id': parent.partner_id}"/>
                                    <field name="analytic_tag_ids" groups="analytic.group_analytic_tags" widget="many2many_tags" options="{'color_field': 'color'}"/>
                                    <field name="quantity"/>
                                    <field name="uom_id" groups="uom.group_uom"/>
                                    <field name="price_unit" string="Price"/>
                                    <field name="discount" groups="base.group_no_one" string="Disc (%)"/>
                                    <field name="invoice_line_tax_ids" widget="many2many_tags" options="{'no_create': True}" context="{'type':parent.type, 'tree_view_ref': 'account.account_tax_view_tree', 'search_view_ref': 'account.account_tax_view_search'}"
                                        domain="[('type_tax_use','=','sale'),('company_id', '=', parent.company_id)]"/>
                                    <field name="price_subtotal" string="Subtotal" groups="account.group_show_line_subtotals_tax_excluded"/>
                                    <field name="price_total" string="Total" groups="account.group_show_line_subtotals_tax_included"/>
                                    <field name="currency_id" invisible="1"/>
                                </tree>

因此,我真正需要做的是通过继承在account.invoice.line中设置字段,然后创建一个继承基本发票表单的视图(在本例中为客户),并将该字段插入one2many字段内的树中。像这样:

        <record model="ir.ui.view" id="view_invoice_line_form_islr">
            <field name="name">account_invoice_line_concept_islr</field>
            <field name="model">account.invoice</field>
            <field name="inherit_id" ref="account.invoice_form"/>
            <field name="arch" type="xml">
                <xpath expr="//field[@name='invoice_line_ids']/tree/field[@name='product_id']" position="after">
                    <field name="concept_id" required="1"/>
                </xpath>
            </field>
        </record>

账户、发票、行、概念、islr
帐户、发票
可悲的是,所有这些都不起作用,我完全相信这是实现这一目标的途径,但可悲的是,我没有看到任何结果。Odoo正在将concept_id字段正确加载到数据库中,并且每当我升级模块并加载此代码时,都不会出现任何错误。然而,它根本没有显示出来。init文件正确地加载了所有内容,并且视图按原样加载到清单中。我已经没有想法了,我将我的代码建立在一个以前可以工作的代码上,并且做了同样的事情,但是在Odoo8中,这没有树视图,但是基本上是一样的


有什么想法吗?提前谢谢

我自己设法解决了这个问题。由于某种原因,当我将继承视图的id更改为此时,Odoo会识别它并正确加载它。现在它显示了,我不明白为什么这是一个问题开始,但现在它已经解决了。我正在发布解决方案,因此如果其他人在将来发现类似的问题,他们可能会参考此帖子寻求帮助,尽管我非常确定我的案例非常特殊

我的代码最终如下所示:

        <record model="ir.ui.view" id="view_invoice_line_form_islr_inherited">
            <field name="name">account_invoice_line_concept_islr_inherited</field>
            <field name="model">account.invoice</field>
            <field name="inherit_id" ref="account.invoice_form"/>
            <field name="arch" type="xml">
                <xpath expr="//field[@name='invoice_line_ids']/tree/field[@name='product_id']" position="after">
                    <field name="concept_id" required="1"/>
                </xpath>
            </field>
        </record>

账户\发票\行\概念\ islr\继承
帐户、发票

您是否将该文件放入清单文件中?你升级了你的模块还是安装了它?正如我在文章末尾所说的,是的,是的,是的。