Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
7341 Widoki

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

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
wrz 24
1298
2
kwi 23
6152
3
kwi 17
11475
1
maj 16
9060
0
maj 16
3235