0
votes

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:

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.

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

Any ideas? Thanks in advance!

1
did you put the file in the manifest file? did you upgrade your module or install it ?Charif DZ
As I said at the end of my post, yes, yes and yes.José Vicente Matos Ramonez

1 Answers

0
votes

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