简体   繁体   English

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

[英]Inherited field with xpath does not appear on the final view - Odoo 12

I have been trying to add a field to the account.invoice.line model, a Many2one field which I stated like this in my custom module: 我一直在尝试将一个字段添加到account.invoice.line模型中,这是我在自定义模块中这样声明的Many2one字段:

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")

Thing is, I cannot add this field into the view by directly inserting it into the corresponding xml view for this model (account.invoice.line) since base Odoo Account module defines a tree view in their base invoice view with the field that connects an invoice to their lines, which would is **invoice_line_ids. 事实是,由于基本Odoo帐户模块在其基本发票视图中定义了一个树状视图,并且该字段将一个发票到他们的行,即** invoice_line_ids。

                            <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>

So, what I really have to do is to set the field in account.invoice.line through inheritance, then make a view that inherits the base invoice form, in this case for customers, and insert the field into that tree inside of that one2many field. 因此,我真正要做的是通过继承在account.invoice.line中设置字段,然后创建一个继承基本发票表单(在这种情况下是针对客户)的视图,然后将该字段插入到那棵树中。领域。 Like this: 像这样:

        <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>

Sadly, none of this works, I'm entirely sure this is the way to go to make this work but I sadly see no results. 可悲的是,这些都不起作用,我完全确定这是完成这项工作的方法,但可悲的是我没有看到任何结果。 Odoo is loading the concept_id field correctly into the database and gives me no error whatsoever whenever I upgrade my module and load this code up. Odoo正在将concept_id字段正确地加载到数据库中,并且每当我升级模块并加载此代码时,都不会出现任何错误。 However, it doesn't show at all. 但是,它根本不显示。 The init files are loading everything correctly and the view is loaded into the manifest as it should be. 初始化文件正在正确加载所有内容,并且视图已按原样加载到清单中。 I've ran out of ideas, I'm basing my code in one that used to work and did the same but in Odoo 8, this didn't have the tree view that time but did basically the same. 我用尽了所有的想法,我将自己的代码建立在可以正常工作的代码的基础上,但是在Odoo 8中,当时没有树形视图,但基本相同。

Any ideas? 有任何想法吗? Thanks in advance! 提前致谢!

I have managed to fix the issue myself. 我已经设法解决了这个问题。 For some reason, when I changed the id of the inherited view to this Odoo recognizes it and loads it up correctly. 出于某种原因,当我将继承视图的ID更改为此Odoo时,它会识别并正确加载它。 Now it shows, it beats me as to why this was a problem to begin with but now it's been solved. 现在它显示了,这使我感到困惑,为什么这首先是一个问题,但现在已经解决了。 I'm posting the solution so if anyone else finds something similar in the future they may refer to this post for help, even though I am pretty sure my case is very particular. 我正在发布解决方案,因此,即使我确定我的案子非常特殊,如果将来有人发现类似的内容,他们也可以向该帖子寻求帮助。

My code ended up looking like this: 我的代码最终看起来像这样:

        <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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM