跳至內容
選單
此問題已被標幟
1 回覆
6917 瀏覽次數

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
24458
2
9月 21
13169
1
8月 21
8676
1
7月 21
4612