Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odgovori
6919 Prikazi

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

@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 Odgovori Prikazi Aktivnost
2
avg. 24
6746
1
okt. 22
24460
2
sep. 21
13169
1
avg. 21
8676
1
jul. 21
4612