Openerp/histest1

จาก Theory Wiki
ไปยังการนำทาง ไปยังการค้นหา

สร้างมอดูล histest

ในไดเรคตอรี openerp/addons/ สร้างไดเรคตอรีชื่อ histest

mkdir histest
cd histest

ไฟล์ __openerp__.py

{
    'name': 'HIS Test',
    'version': '0.1',
    'category': 'Tools',
    'description': """
This is a training module for new HIS
=====================================
 
""",
    'author': 'Chaiporn',
    'website': 'http://openerp.com',
    'summary': 'HIS Test',
    'sequence': 9,
    'depends': [],
    'data': [
        'histest_view.xml',
    ],
    'demo': [],
    'test': [],
    'css': [],
    'images': [],
    'installable': True,
    'application': True,
    'auto_install': False,
}

ไฟล์ __init__.py

import histest

สร้างโมเดลเก็บข้อมูล

สร้างไฟล์ชื่อ histest.py เพื่อประกาศโมเดลสำหรับเก็บข้อมูลดังนี้

# encoding=utf-8

from osv import osv, fields

class HISPatient(osv.Model):
    _name = "histest.patient"

    _columns = {
            'title' : fields.char(
                size=50,
                string=u'คำนำหน้าชื่อ',
                required=True),

            'first_name' : fields.char(
                size=50,
                string=u'ชื่อ',
                required=True
                ),

            'last_name' : fields.char(
                size=50,
                string=u'นามสกุล',
                required=True
                ),
            }

เตรียมหน้าจอแสดงผล (view)

สร้างไฟล์ชื่อ histest_view.xml โดยมีโค้ดดังนี้

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

    <record model="ir.ui.view" id="view_histest_patient_tree">
      <field name="name">histest.patient.tree</field>
      <field name="model">histest.patient</field>
      <field name="arch" type="xml">
        <tree string="Patient">
          <field name="title"/>
          <field name="first_name"/>
          <field name="last_name"/>
        </tree>
      </field>
    </record>

    <record model="ir.ui.view" id="view_histest_patient_form">
      <field name="name">histest.patient.form</field>
      <field name="model">histest.patient</field>
      <field name="arch" type="xml">
        <form string="Patient" version="7.0">
          <group>
            <field name="title"/>
            <field name="first_name"/>
            <field name="last_name"/>
          </group>
        </form>
      </field>
    </record>

    <record model="ir.actions.act_window" id="action_histest_patient">
      <field name="name">Patient</field>
      <field name="res_model">histest.patient</field>
      <field name="view_type">form</field>
      <field name="view_mode">form,tree</field>
    </record>

    <menuitem name="HIS" id="menu_histest_top" 
      parent="" sequence="1" 
      action="histest.action_histest_patient" />

  </data>
</openerp>