Skip to Content
Menu
This question has been flagged
4 Replies
7787 Views

Hiiii,
How to inherit field to existing tables?

I've tried various things, but it's hard to understand,

i want to inherit my field(on my addons) to model asset.

this my code ;

class Aset(models.Model): #addons field
    _inherit='asset.asset' 
    
    asset_number = fields.Char('Item Code/Reg', size=64)
    no_pol=fields.Char('Police Number')
    many_units=fields.Char('Number Of Units', default='1')
    item_type_id=fields.Many2one('item_type', string='Item Type')
    colour=fields.Char('Colour')
    machine_number=fields.Char('Number Machine')
    chassiss=fields.Char('Chassis Number')
    fill_in_the_slider=fields.Char('Slider')
    bpkb_no=fields.Char('BPKB No')
    year=fields.Char('Year')

xml ;

<record model="ir.ui.view" id="asset_asset_form_view">
    <field name="name">asset_asset_form</field>
    <field name="model">asset.asset</field>
    <field name="inherit_id" ref="asset.assets_form_view" />
    <field name="arch" type="xml">
        <page position='inside'>
            <group position="inside">
                <field name='serial'>
            <group>
                <field name='color'/>
            </group>
                </field>
       </group>
</page>

Thanks before...

Avatar
Discard
Best Answer

Based on your code  on <page position='inside'> that  means "Put new tags Inside Element <Page> on referenced view (asset.assets_form_view)"

So the result as attached images. because odoo will render xml structure like this
<page string="Info">
    <group>
        <group>
            ******original fields on group top left
        </group>
    </group>
    <group string="Warranty">
        <group>
            *** Original fields on group bottom left
        </group>
        <group>
            *** Original fields on group bottom right
        </group>
    </group>


    <!-- THE APPENDED TAGS by <page position="inside">**TAGS**</page> -->
    <group>
        <field name='serial'>
    </group>
    <group>
        <field name='color'/>
    </group>
    <!-- END -->
</page>


So for you expected result like image that you attached, maybe you can try like this

<xpath expr="//form/sheet/notebook/page/group[1]" position="inside">
    **Appended tags
</xpath>
** Using group[1] or group (depends on referenced structure)

or

<xpath expr="//form/sheet/notebook/page/group[1]/group" position="after">
    **Appended tags
</xpath>

Note:
The expression depends by referenced views,,so you must modify it base on referenced xml view structure (asset.assets_form_view)

You can see the video that referenced by @Cybrosys before
And please learn about \XPATH\ expression\\ \/\ i\nheriting  View ON Odoo.

Regards

Avatar
Discard
Author

Thanks for response.

I do both examples,

still not as I expected sir.

the example above makes the field in an existing group, it is almost exactly what I want, but rather want to create a new group and be next to the existing group (as in the picture)

So for more please post the original view to inherit (asset.assets_form_view)

And your full xml view code , so me or anyone can help more detail,,

Regards..

Author

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

<field name="name">asset_asset_form</field>

<field name="model">asset.asset</field>

<field name="inherit_id" ref="asset.assets_form_view" />

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

<xpath expr="//form/sheet/notebook/page/group" position="inside">

<group>

</group>

<group>

<field name='colour'/>

<field name='machine_number'/>

<field name='chassiss'/>

<field name='fill_in_the_slider'/>

<field name='bpkb_no'/>

<field name='year'/>

</group>

</xpath>

<field name='asset_number' position='replace'>

<field name='asset_number'/>

</field>

<field name='active' position='after'>

<field name='item_type_id' />

</field>

<field name='serial' position='after'>

<field name='many_units' />

</field>

</field>

</record>

Can you share screen shoot origin form (before inheriting) ?? i wanna see the structure ,, before it inherited

And i see you wanna inherit form view from module wich named "asset" ,, i try to find the module at odoo source code on github (https://github.com/odoo/odoo/tree/10.0/addons) , but cant find "asset" module. It's your own custom module ??

If it right,, can you share the original form view xml structure...??

And What the result looks like , if your xpath like this:

<xpath expr="//form/sheet/notebook/page/group[1]/group[1]" position="after">

<group>

<field name='colour'/>

<field name='machine_number'/>

<field name='chassiss'/>

<field name='fill_in_the_slider'/>

<field name='bpkb_no'/>

<field name='year'/>

</group>

</xpath>

Author

now code like this,

<xpath expr="//form/sheet/notebook/page/group" position="inside">

<group>

</group>

<group>

<field name='colour'/>

<field name='machine_number'/>

<field name='chassiss'/>

<field name='fill_in_the_slider'/>

<field name='bpkb_no'/>

<field name='year'/>

</group>

</xpath>

and result like in image before...

Author

origin like this image https://drive.google.com/file/d/1mTJx570PVSSy8XnLmSwGaX38xmyzx3lS/view

and this for module,

https://apps.odoo.com/apps/modules/10.0/asset/

I just added a new field to the module, because when I tried to add a field directly to the module it couldn't, so I made simple addons for the inheritance

I see on that module repository on -> https://github.com/codup/odoo-eam/blob/10.0/asset/asset_view.xml#L72

There's Empty Group Already defined on origin form view, it post wil be rendered on top right of form

So in this case, can you try to put this code:

<xpath expr="//form/sheet/notebook/page/group[1]/group[2]" position="inside">

<field name='colour'/>

<field name='machine_number'/>

<field name='chassiss'/>

<field name='fill_in_the_slider'/>

<field name='bpkb_no'/>

<field name='year'/>

</xpath>

and see the result

Author

Hi La Jayuhni,

Big Thanks, now it's appropriate

Best Answer

Hi,

If you are looking to inherit and add new custom fields to the model asset.asset , what you have done seems to be fine, if there is an issue in the same, please post the issue or update the question with the error message.

Additional field to existing view

Thanks


Avatar
Discard
Author

Hello, Thanks for response

there was no error, but the addons field that I added was not in the 'Info' table and grouped there. but instead adds the fields below.

and essentially I want to add fields with new groups next to existing groups,

regards.

Related Posts Replies Views Activity
2
Mar 24
10323
5
Sep 20
5181
1
Dec 19
8410
1
Jan 19
5038
2
Jul 18
13144