Skip to Content
Menu
This question has been flagged
1 Reply
4493 Views

hi all,

have added a field zone_id (Many2one) res.partner model and also in view (code for both below), now I wants to add One2Many field which should appear in contacts view as editable tree. i can't figure it out how I can add this editable tree? please help. can I add in below files or have to create another for this purpose?

wants to add in below portion where other details are in tabs (pages) Contacts & Addresses, Sales & Purchase etc. are presented.

Note: below xml file code copied while searching from this help forum, answered by @subbarao

Link to topic: https://www.odoo.com/forum/help-1/adding-fields-to-res-partner-form-142759


class PartnerZone(models.Model):

    _inherit = 'res.partner'


    zone_id = fields.Many2one('tests.zones', string="Zone")


<?xml version="1.0" encoding="UTF-8"?>


<odoo>

    <record id="view_res_partner_form_inherit" model="ir.ui.view">

        <field name="name">Tests Custom Fields</field>

        <field name="model">res.partner</field>

        <field name="type">form</field>

        <field name="inherit_id" ref="base.view_partner_form"/>

        <field name="arch" type="xml">

            <xpath expr="//field[@name='category_id']" position="after">

                <field name="zone_id" string="Select Zone"/>

            </xpath>

        </field>

    </record>

</odoo>


regards

Avatar
Discard
Author

why i failed to get answer? how i can ask this question to get help?

Author Best Answer

now achieved it...  but it is showing below error when clicking on Add a line... any idea

ValueError: Invalid field 'same_vat_partner_id' on model 'tests.users'

class Users(models.Model):
    _name = 'tests.users'
    _rec_name = 'name'
    _description = "Tests Users"
    name = fields.Char(string="User Name", required=True)
    email = fields.Char(string="Email")
    email_verified_at = fields.Datetime(string="Email Verified At")
    address = fields.Text(string="User Address")
    password = fields.Char(string="Password", required=True)
    profile_picture = fields.Binary()
    phone = fields.Char(string="Phone No.", required=True)
    type = fields.Selection([
        ('staff', 'Staff'),
        ('customer', 'Customer'),
        ('rider', 'Rider')
    ], required=True, string="User Type", default='staff')
    remember_token = fields.Char(string="Remember Token")
    zone_id = fields.Many2one("tests.zones", string="Zone")
    description = fields.Text(string="Other Information")
    deleted_at = fields.Datetime()
    user_ids = fields.One2many('tests.userzones', 'user_id', string="User Zone")

-------- below code is to achieve as asked for --------

class PartnerZone(models.Model):
    _inherit = 'res.partner'
    zone_id = fields.Many2one('tests.zones', string="Zone")
    user_mids = fields.One2many('tests.usermetas', 'user_id', string="User Metas")
    user_wids = fields.One2many('tests.userwallets', 'user_id', string="User Wallets")


<?xml version="1.0" encoding="UTF-8"?>
<odoo>
    <record id="view_res_partner_form_inherit" model="ir.ui.view">
        <field name="name">Contacts Custom Fields</field>
        <field name="model">res.partner</field>
        <field name="type">form</field>
        <field name="inherit_id" ref="base.view_partner_form"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='category_id']" position="after">
                <field name="zone_id" string="Zone"/>
            </xpath>
            <!-- added below code for editable tree in contacts form -->
            <xpath expr="//page[@name='sales_purchases']" position="after" >
                <page string="Wallets">
                    <field name="user_wids">
                        <tree editable="bottom" string="User Wallets">
                            <field name="amount"/>
                            <field name="credits"/>
                            <field name="description"/>
                        </tree>
                    </field>
                </page>
            </xpath>
        </field>
    </record>
</odoo>


here is screenshot


Avatar
Discard
Author

any hope to resolve the problem?

Related Posts Replies Views Activity
1
Sep 21
3985
0
Jan 21
3657
4
Dec 23
16129
1
Sep 16
6476
0
Mar 15
2865