Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
7328 Tampilan

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

Avatar
Buang
Jawaban Terbai

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).

Avatar
Buang
Jawaban Terbai

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.

Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
2
Sep 24
1297
2
Apr 23
6151
3
Apr 17
11473
1
Mei 16
9057
0
Mei 16
3232