Add One2many Field in Odoo16

 

Add One2many Field In Odoo16

How To Add One2many Field In Odoo16

Identify the model you want to add the One2many field to. Let’s assume that you want to add a One2many field to the “appointment.pharmacy” model

from odoo import api, fields, models



class HospitalAppointment(models.Model):

    _name = ‘hospital.appointment’

    _description=’hospital.appointment’

    

   

    pharmacy_id = fields.One2many(‘appointment.pharmacy’, ‘appointment_id’, string=’pharmacy_id’ )

    

        

#if we want to create many2one field  first we can create a two model for relational fields in odoo


class AppointmentPharmacy(models.Model):

    _name = ‘appointment.pharmacy’

    _description = ‘appointment pharmacy’



  

    appointment_id = fields.Many2one(comodel_name=’hospital.appointment’, string=’appointment_id’)



# we can also create one xml file like appointment _view.xml


<?xml version=”1.0″ encoding=”utf-8″?>

<odoo>

       

     

        <record id=”view_hospital_appointment_form” model=”ir.ui.view”>

            <field name=”name”>hospital.appointment.form</field>

            <field name=”model”>hospital.appointment</field>

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

                <form>

                               <notebook>

                           

    

                           <page string=’pharmacy’ name=’pharmacy’>

                            <field name=’pharmacy_id’>

                            

                            </field>

                           </page>

                        </notebook>

                        

                           

                      </sheet>

                      

                

                

                </form>

            </field>

        </record>

          

</odoo>

after that we can add xml file in __manifest__.py


{

    ‘name’: ‘Hospital Management’,

    ‘version’: ‘1.2’,

    ‘category’: ‘Hospital Management System’,

    ‘author’: ‘pythonpowers’,

   

    ‘sequence’: -100,

    ‘summary’: ‘HMS’,

    ‘description’: “””

This module contains all the common features of Hospital Managent System.

    “””,

    ‘depends’: [‘mail’,’base’,’product’],

    ‘data’: [

       

        ‘views/appointment_view.xml’,

       

        

    ],

 


    ‘demo’: [],

    ‘application’:True,

        

    ‘installable’: True,

    ‘assets’: {

        

    },

    

    ‘license’: ‘LGPL-3’,


}



    For any inquiries, suggestions, or feedback, you can reach out to us through the provided contact form on our blog. We make an effort to respond to all queries in a timely manner and appreciate your engagement with our content.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *