20. How To Add Many2one Field In Odoo || Relational Fields in Odoo || Odoo 15 Development Tutorials
Summary
TLDRIn this tutorial, the process of adding a 'many to one' field in Odoo is explained, with a focus on the Hospital Appointment model. The video demonstrates the steps of creating a new model, defining the field, and setting up views. It walks viewers through the process of adding a patient ID field to the appointment form, along with the importance of adhering to naming conventions. The tutorial also covers how to troubleshoot issues, including handling naming conflicts and error resolution, ensuring the feature works smoothly in Odoo 15 Community Edition.
Takeaways
- 😀 Learn how to add a 'many-to-one' field in Odoo, specifically for creating relationships between models like Hospital Appointment and Patient.
- 😀 The tutorial uses Odoo version 15 Community Edition to demonstrate the creation and implementation of a new model called 'Hospital Appointment'.
- 😀 A step-by-step guide is provided for creating a new model, adding views, and ensuring proper security for the model in the system.
- 😀 When defining a 'many-to-one' field, it’s important to follow the naming convention, such as 'patient_id' for a field linking to a patient model.
- 😀 The many-to-one relationship allows users to select a patient for an appointment, which will be reflected in the related models.
- 😀 The tutorial highlights the importance of checking that all the fields in the form view are correctly defined, such as replacing 'patient' references with 'appointment'.
- 😀 Ensure that the newly created fields, views, and actions are correctly added to the manifest file to be recognized by the system after a restart.
- 😀 The 'many-to-one' field can be created using the syntax: 'fields.Many2one', followed by the model name and string (e.g., 'patient_id').
- 😀 Security access is an essential step, and the necessary access rules should be created for the 'Hospital Appointment' model to function properly for users.
- 😀 Finally, the tutorial demonstrates how a 'many-to-one' field helps link appointments to patients and how these links are searchable and manageable in Odoo.
- 😀 The script also clarifies how errors related to model references (e.g., missing or incorrect references to the model in views) can be fixed by properly specifying the model name in the field definition.
Q & A
What is the main topic of this tutorial video?
-The main topic is how to add a 'many-to-one' field in Odoo, specifically in the context of the hospital module, by creating a new model for appointments and linking it to the patient model.
What version of Odoo is being used in this tutorial?
-The tutorial is based on Odoo version 15 Community Edition.
What does the 'many-to-one' field do in Odoo?
-A 'many-to-one' field in Odoo allows a record in one model to be linked to a single record in another model, effectively establishing a relationship where many records from the first model can be associated with one record from the second model.
Which new model is being created in this tutorial?
-A new model called 'hospital.appointment' is being created in the tutorial.
Why does the tutorial add a 'many-to-one' field to the 'hospital.appointment' model?
-The 'many-to-one' field is added to the 'hospital.appointment' model to link each appointment to a patient, allowing for easy association between the two models.
What issue was encountered with the views in the tutorial?
-The issue encountered was that the views for the 'hospital.patient' and 'hospital.appointment' models conflicted. The views were not displaying as expected because the 'hospital.patient' view was being overridden, causing the system to default to a blank view.
What is the naming convention for 'many-to-one' fields in Odoo?
-The naming convention for 'many-to-one' fields in Odoo requires the field name to end with '_id', such as 'patient_id', 'product_id', or 'user_id'.
What is the significance of using 'co_model' in the field definition?
-The 'co_model' parameter is used to explicitly specify which model the 'many-to-one' field should reference. If not specified, Odoo defaults to the first model it encounters.
What problem occurs if 'co_model' is incorrectly used in the 'many-to-one' field definition?
-If 'co_model' is incorrectly used, such as not specifying the correct model or misplacing it in the field definition, an internal server error (500) may occur, as demonstrated in the tutorial.
What happens when a 'many-to-one' field is left empty or a new patient is created in the system?
-When a 'many-to-one' field is left empty, Odoo will not display any name or related information. However, when a new patient is created, the field will show the newly created patient's name, and the field will update accordingly.
Outlines

このセクションは有料ユーザー限定です。 アクセスするには、アップグレードをお願いします。
今すぐアップグレードMindmap

このセクションは有料ユーザー限定です。 アクセスするには、アップグレードをお願いします。
今すぐアップグレードKeywords

このセクションは有料ユーザー限定です。 アクセスするには、アップグレードをお願いします。
今すぐアップグレードHighlights

このセクションは有料ユーザー限定です。 アクセスするには、アップグレードをお願いします。
今すぐアップグレードTranscripts

このセクションは有料ユーザー限定です。 アクセスするには、アップグレードをお願いします。
今すぐアップグレード関連動画をさらに表示

GoHighLevel Automation Tutorial | 6. Move Leads From One Pipeline To Another

Modelagem de dados - modelo conceitual, lógico e físico

Excel Snake Game VBA Macro (Advanced) Part 2/2

Modellierung von Datenbanken - Erstellung eines ERM

Hospital Management System in Python with MySQL Connectivity

Lec-14: Introduction to ER model | ER Model क्या है
5.0 / 5 (0 votes)