Skip to Content
Menu
This question has been flagged
1 Reply
6306 Views

I want to add a field in 'line_ids' of bank statement line , but I got error when trying with this code . Any help please ?

Thanks.


class AccountBankStatementLine(models.Model):

    _inherit = "account.bank.statement.line"


    my_field = fields.Many2one('model.model', string="My field")



 <record id="view_bank__inherit" model="ir.ui.view">
            <field name="name">bank.statement.inherit</field>
            <field name="model">account.bank.statement.line</field>
            <field name="inherit_id" ref="account.view_bank_statement_form"/>
            <field name="arch" type="xml">
                <xpath expr="//notebook/page[@name='line_ids']/field/tree/field[@name='partner_id']" position="after" >
                    <field name="my_field" />
                </xpath>
            </field>
        </record>
Avatar
Discard
Best Answer

Hi,

It will be nice if you add the error along with the question. After checking the above code the issue might be with the model name specified inside the inherited view, it should be account.bank.statement instead of account.bank.statement.line


<record id="view_bank_statement_form_inherit" model="ir.ui.view">
<field name="name">bank.statement.inherit</field>
<field name="model">account.bank.statement</field>
<field name="inherit_id" ref="account.view_bank_statement_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='line_ids']//tree/field[@name='partner_id']" position="after">
<field name="my_field"/>
</xpath>
</field>
</record>

For Reference: How To Inherit And Add New Fields To Existing Views

Thanks

Avatar
Discard
Author

@Niyas Raphy, when I tried with model 'account.bank.statement' , I got the following error : raise ValueError(formatted_message).with_traceback(from_traceback) from from_exception

odoo.exceptions.ValidationError: Error while validating view:

Element '<xpath expr="//notebook/page[@name='line_ids']/field/tree/field[@name='partner_id']">' cannot be located in parent view

View name: bank.statement.inherit

Error context:

view: ir.ui.view(1322,)

Please update the xpath,

<xpath expr="//field[@name='line_ids']//tree/field[@name='partner_id']" position="after">

<field name="my_field"/>

</xpath>

Related Posts Replies Views Activity
2
Aug 24
5004
1
Oct 22
22090
2
Sep 21
11227
1
Aug 21
7243
1
Jul 21
3436