Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
7327 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit
Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
2
zář 24
1297
2
dub 23
6151
3
dub 17
11473
1
kvě 16
9056
0
kvě 16
3232