Skip to Content
Menú
This question has been flagged
1 Respondre
6920 Vistes

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

@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 Respostes Vistes Activitat
2
d’ag. 24
6746
1
d’oct. 22
24462
2
de set. 21
13171
1
d’ag. 21
8677
1
de jul. 21
4612