宜兴通达竭诚为您服务。

通达科技 - 宜兴电脑维护及IT服务外包服务商

Data fields
  • 上传者: Administrator
  • 上传时间:2023年11月13日 05时14分06秒
摘要:
* Data fields ** *** A Model is a class that maps to the data relation (table), and it includes all of the fields and their behaviors for the data yo ......
正文 相关文章 请喝咖啡

    Data fields

    A Model is a class that maps to the data relation (table), and it includes all of the fields and their behaviors for the data you'll be storing. Here we can discuss the type of data stored on a field and how to add them to a model.

    We need to create a python file in the directory models to define the basic model.

    models > school_student.py

    1. Use some simple python code to add the patient details and we need to create a new model for that.

    from datetime import date, timedelta

    from odoo import models, fields, _, api

    class SchoolStudentDetails(models.Model):

       _name = "school.student"

       _rec_name = 'admission_no'

       _description = "Student Details"

       name_id = fields.Many2one('res.partner', string="Name", required=True)

       admission_no = fields.Char(string='Admission No:', required=True,

                                  copy=False,

                                  readonly=True, default=lambda self: _('New'))

       b_date = fields.Date(string='DOB', related='name_id.dob')

       age = fields.Integer(string="Age", compute='_compute_age')

       father_name = fields.Char(string="Father's Name")

       mother_name = fields.Char(string="Mother's Name")

       mobile = fields.Char(string='Mobile', related='name_id.mobile')

       phone = fields.Char(string='Phone', related='name_id.phone')

       gender = fields.Selection([

           ('other', 'Other'),

           ('male', 'Male'),

           ('female', 'Female'),

       ], srting='Gender', default='other')

       blood_grp = fields.Selection([

           ('a+', 'A+'),

           ('b+', 'B+'),

           ('ab+', 'AB+'),

           ('ab-', 'AB-'),

           ('o+', 'O+'),

           ('o-', 'O-'),

       ], string="Blood Group")

       nationality = fields.Many2one('res.country', string='Nationality')

       class_history_ids = fields.One2many('school.class.history', 'student_id', string='Class History')

    class SchoolClassHistory(models.Model):

       _name = "school.class.history"

       _description = "Class History"

       student_id = fields.Many2one('school.student')

       class_id = fields.Integer("Class")

       academic_year_id = fields.Date('Academic Year')

       division = fields.Char('Division')

    The Fields are defined in the model class as the attributes, and also it is used to define where they are stored and what the model can store. The non-relational types of fields are as follows.

    · Char - It is used for string values

    · Text - It is used for multi-line string values

    · Selection - This field is used for a selection list, and allows for dynamically generated lists of options

    · Binary - It is used for storing binary field

    · Html - It is similar to HTML fields

    · Boolean - Store True or False values

    · Date - It store date values and, it has some utilities that are:

    - fields.Date.to_date(string_value): It will convert string to date object

    - fields.Date.to_string(date_value): It will convert date to string value

    - fields.Date.today(): Current date in string format

    - fields.Date.context_today(record, timestamp): It will return the day of the timestamp in a string format

    · Datetime - It is used to store date time values (dd/mm/yyyy HH:MM:SS), and have some utils

    - fields.Datetime.to_datetime(string_value): It will convert String into DateTime

    - fields.Datetime.to_string(datetime_value): It will convert the DateTime object to a string

    - fields.Datetime.now(): It is the current DateTime value

    - fields.Datetime.context_timestamp(record, timestamp): Converts a timestamp-native DateTime object into a zone-aware DateTime object

    · Float - To Store the Float values

    · Monetary - To Store amount in a certain currency

    The relational field types are as follows.

    · Many2one - The Many2one fields relate the many records of the co-model, which is the second model, to the current model’s record.

    · One2many - The One2many field relation is the inverse of the Many2one relation. It relates one record of the co-model to many records of the model.

    · Many2many - The Many2many fields are bidirectional multiple relationships. It means that the number of records in one direction will be directed to the number of records in the other direction.

    2. Here, we added the new fields to the current model, and next, we need to set the form view on the user interface for the added fields. The below code is used to view the field on the user interface.

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

    <odoo>

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

           <field name="name">school.student.form.view</field>

           <field name="model">school.student</field>

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

               <form>

                   <sheet>

                       <div class="oe_title">

                           <h1>

                               <field name="admission_no" readonly="1"/>

                           </h1>

                       </div>

                       <group>

                           <group>

                               <field name="name_id" widget="res_partner_many2one"

                                      context="{'res_partner_search_mode': 'customer', 'show_address': 1 }"

                                      options='{"always_reload": True}'/>

                               <field name="b_date"/>

                               <field name="age"/>

                               <field name="gender"/>

                               <field name="blood_grp"/>

                           </group>

                           <group>

                               <field name="nationality"/>

                               <field name="father_name"/>

                               <field name="mother_name"/>

                               <field name="mobile"/>

                               <field name="phone"/>

                           </group>

                       </group>

                       <notebook>

                           <page string="Class History">

                               <field name="class_history_ids">

                                   <tree editable="bottom">

                                       <field name="class_id" required="1"/>

                                       <field name="division" required="1"/>

                                       <field name="academic_year_id" required="1"/>

                                   </tree>

                               </field>

                           </page>

                       </notebook>

                   </sheet>

               </form>

           </field>

       </record>

    </odoo>

    3. Then Upgrade the module, and we can see the form view in the user interface.

     

     

     

    本文章从网上收集,如有侵权请联系tderp@tderp.com删除
  • 微信扫一扫,一分也是爱:
  • 微信

服务原则及地区范围

宜兴通达网络科技有限公司,地处中国宜兴环科园内,是一家高新技术企业。公司在企业网络维护和企业信息化建设与咨询方面,有10多年经验。

我公司愿与客户一道,力求彻底解决客户问题!
我们不是在给企业提供“头痛医头、脚痛医脚”的暂时解决方案,而是在部署根本性安全与稳定服务!!
我们愿携手客户,建立企业IT规划;杜绝随意安装系统、软件等操作;力求共同维护有序、安全、稳定的网络办公环境!!!
IT服务,服务是根本,客户是上帝;我们提供快速响应、快速上门、快速排查,提供优质高效的服务!!!!

通达科技提供全国范围内的服务,服务形式包括远程协助、电话咨询、电子邮件咨询、传真咨询、问答平台的问题解决等。

宜兴地区提供上门服务:

  • 市区服务:宜城街道、城北街道(屺亭街道)、新街街道、新庄街道、环科园、渚桥开发区
  • 市郊服务:张渚镇、西渚镇、太华镇、徐舍镇、官林镇、杨巷镇、新建镇、和桥镇、高塍镇、万石镇、周铁镇、芳桥镇、丁蜀镇、湖父镇。
  • 联系电话:189-21-343434
  • 在线沟通: