Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
7331 Lượt xem

Hello,
It is a very simple question. I want to use a field from inherited model, here is my balance.py

    from odoo import models, fields, api
   
    class Balance_res_partner(models.Model):
        _name = 'res.partner'
       
       
And balance.xml

    <?xml version="1.0"?>
    <odoo>
    <record id="balance_res_partner_form_view" model="ir.ui.view">
            <field name="inherit_id" ref="base.view_partner_form"/>
            <field name="priority" eval="3"/>
            <field name="model">res.partner</field>
            <field name="arch" type="xml">
                <button name="toggle_active" position="before">
                    <button class="oe_stat_button" type="action" name="%(account.action_account_payments)d"
                                attrs="{'invisible': [('customer', '=', False)]}"
                                icon="fa-usd">
                                <field string="Balance" name="credit" widget="statinfo"/>
                    </button>
                </button>
            </field>
            </record>
        </odoo>

As you see, I don't have any 'credit' field in balance.py, so server doesn't run. The trick I want to do is to use 'credit' field from res.partner, and show its in that button value.

Help needed. Thanks in advance...

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

If you want to show a field that already exists on the res.partner model, you don't have to inherit the model, only the view.

I take it you are trying to use the credit field that is defined on res.partner from the account module?
If so, you have to make sure you set the account module as a dependency in your __manifest__py file. 

To make this work, try removing your model and make sure you depend on the account module.
Also, I don't think you have to use the "priority" field for this to work.

BTW: Your model Class is not inheriting, but trying to redefine res.partner. This is most likely why you get an error.
Use _inherit = 'res.partner' instead of _name = "res_partner
(no need to do this here though, as you should remove your model).

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

from odoo import models, fields, api
    
class Balance_res_partner(models.Model):
        _inherit = 'res.partner'

        credit = fields.Float('Credit')


and don't forgot to add base module dependency on your module.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 9 24
1297
2
thg 4 23
6151
3
thg 4 17
11473
1
thg 5 16
9060
0
thg 5 16
3234