跳至内容
菜单
此问题已终结
1 回复
6922 查看

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>
形象
丢弃
最佳答案

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

形象
丢弃
编写者

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

相关帖文 回复 查看 活动
2
8月 24
6746
1
10月 22
24462
2
9月 21
13171
1
8月 21
8677
1
7月 21
4612