Inheritance with different method in odoo

Inheritance with different method in odoo :

When the class is using the same implementation of another class then it is called inheritance. 

We can change the behavior and functionality of class by using inheritance

First create a new class and that inherited from an existing class.adding functionality to it.the original class is called parent class or base class. While the new class is called child class or derived class. Inheritance in child class is inherited by its parent class.

Use :- 

Inheritance is used to inherit the method.first create a new class and inherit the existing class.

Steps :-

1 ) First you create a new module.

2) Create a new file in models.

3) File name same in write class.

​        from odoo import models, fields

    class sale_order(models.Model):

         _inherit = 'gift.zone'

​remarks = fields.Char(string='Remarks')

4) Import sale_order in __init__.py file.

5) Create sale_order_view.xml file in the views folder.

6) Write record id, field name and model name.

7) Browser in select your created module.and click on new after click on database near icon , select Edit view :form and copy External id.

8) Step 7 is to write in ref= (Edit view).

9) <xpath expr="//field[@name='gift_price']" position="after">

<field name="remarks"/>

  </xpath>

-> name = After which the name has to be put in any field. 

-> set the position.

-> field name = write new field name.

10) Manifest file in import views file and depends in write Module name.

Go to browser -> refresh -> upgrade you module -> setting -> technical -> select models -> search your model name -> select field -> in app.


Here, 4 types of methods are available .

  1. Before
  2. After
  3. Inside
  4. Replace


1) Before :-

<xpath expr="//field[@name='description']" position="before">

    <field name="idea_ids" />

</xpath>

Insert xpath, name= (you can add any existing field) and set the position.after you can write a new field.

You can see the new field before the description field.


2) After :-

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

    <field name="idea_ids" />

</xpath>

Insert xpath, name= (you can add any existing field) and set the position.after you can write a new field.

You can see new field after description field.


3) Inside :-

<xpath expr="//field[@name='description']" position="inside">

    <field name="idea_ids" />

</xpath>

Insert xpath, name= (you can add any existing field) and set the position.after you can write a new field.

You can see a new field inside of the description field. It means remove existing field and add new field for use INSIDE.


4) Replace :-

<xpath expr="//field[@name='description']" position="replace">

    <field name="idea_ids" />

</xpath>

Insert xpath, name= (you can add any existing field) and set the position.after you can write a new field.

You can see the new field replace the description field. It means changing the Name of the field.





Administrator February 1, 2024
Share this post
Archive
Sign in to leave a comment