Monday, December 9, 2019

how to edit view in odoo

ODOO

views

 

In this step we will continue with patient object by adding some new fields and design their view , so we have two steps today
  • add the fields 
          'name' which will contain the full name for the patient that will be concatenation of the four name , so 'name' field will be computed field
          'image' which is binary field that will contain the image of patient
          'gender' contain the gender of patient and it is selection field contain two values [male and female]
          'birth_day' the birthdate for the patient
          'met_doctor' which is boolean field that will be true if the patient met the doctor before 
          'last_meeting' the date of last meeting 

So we can add them as 

# -*- coding: utf-8 -*-
from odoo import api, fields, models, _

class ClinicPatient(models.Model):
    ###############################
    #Class for patient which is contain all patient data
    ###############################
    _name = 'clinic.patient'
    _description = "object contain all patient data"

    first_name = fields.Char(string='First Name', required=True)
    second_name = fields.Char(string='Second Name', required=True)
    third_name = fields.Char(string='Third Name', required=True)
    forth_name = fields.Char(string='Fourth Name', required=True)
    name = fields.Char(string="Name", readonly=True, compute='get_patient_name')
    image = fields.Binary(string='Image', copy=False)
    gender = fields.Selection([('male','Male'),('female','Female')], string='Gender',default='male')
    birth_day = fields.Date(string='Birthday', required=True)
    met_doctor = fields.Boolean(string='Met Doctor')
    last_meeting = fields.Date(string='Last Meeting')

    @api.one
    def get_patient_name(self):
        """
        function to calculate the full name for the patient
        """
        self.name = self.first_name+' '+self.second_name+' '+self.third_name+' '+self.forth_name

  • Edit view file as bellow 
<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>

        <!-- """Create Form View""" -->

        <record id="clinic_patient_form_view" model="ir.ui.view">
            <field name="name">clinic.patient.form</field>
            <field name="model">clinic.patient</field>
            <field name="arch" type="xml">
                <form string="Patient">
                    <sheet>
                        <div style="width:100%;">
                            <div style="width:20%;float:left;">
                                <field name="image" widget="image"/>
                            </div>
                            <div style="width:78%;float:right;">
                                <group colspan="2" col="2">
                                    <field name="name" nolabel="1" style="font-size:32px;"/>
                                </group>
                                <table style="width:100%;">
                                    <tr style="width:100%;">
                                        <td style="width:25%;font-size:13px;padding:2px;">
                                            <field name="first_name" placeholder="First Name"/>
                                        </td>
                                        <td style="width:25%;font-size:13px;padding:2px;">
                                            <field name="second_name" placeholder="Second Name"/>
                                        </td>
                                        <td style="width:25%;font-size:13px;padding:2px;">
                                            <field name="third_name" placeholder="Third Name"/>
                                        </td>
                                        <td style="width:25%;font-size:13px;padding:2px;">
                                            <field name="forth_name" placeholder="Fourth Name"/>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                        <br></br><br></br>
                        <group colspan="4" col="4">
                            <field name="gender"/>
                            <field name="birth_day"/>
                            <field name="met_doctor"/>
                            <field name="last_meeting" attrs="{'invisible':[('met_doctor','=',False)],'required':[('met_doctor','=',True)]}"/>
                        </group>
                    </sheet>
                </form>
            </field>
        </record>

        <!-- """Create Tree View""" -->

        <record id="clinic_patient_tree_view" model="ir.ui.view">
            <field name="name">clinic.patient.tree</field>
            <field name="model">clinic.patient</field>
            <field name="arch" type="xml">
                <tree string="Patients">
                    <field name="first_name"/>
                    <field name="second_name"/>
                    <field name="third_name"/>
                    <field name="forth_name"/>
                </tree>
            </field>
        </record>

        <!-- """Create Action View""" -->

        <record id="clinic_patient_action_view" model="ir.actions.act_window">
            <field name="name">Patients</field>
            <field name="res_model">clinic.patient</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="view_id" ref="clinic_patient_tree_view"/>
        </record>


        <!-- """Create the root menu """ -->

        <menuitem id="clinic_root_menu"
            name="Clinic Patient"
            sequence="1"
        />

        <!-- """Create the Configration menu """ -->

        <menuitem id="clinic_patient_main_menu"
            name="Patients" sequence="2"
            parent="clinic_root_menu"
        />

        <!-- """Create the Company's Projects menu""" -->

        <menuitem
            name="Patients"
            parent="clinic_patient_main_menu"
            action="clinic_patient_action_view"
            id="patients_action_menu"
            sequence="5"
        />

    </data>
</odoo>


Watch on YouTube


  PREVIOUS STEP            NEXT STEP

No comments:

Post a Comment

Odoo Invoice Qr code issues

There are two main issues must of us facing with the QR code in Odoo invoice & these issues are 1/ QR code displayed as broken image w...