Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2 Antwoorden
7344 Weergaven

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
Annuleer
Beste antwoord

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
Annuleer
Beste antwoord

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
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
2
sep. 24
1301
2
apr. 23
6153
3
apr. 17
11476
1
mei 16
9060
0
mei 16
3237