Openerp/histest1
เนื้อหา
สร้างมอดูล 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': 'Someone',
'website': 'http://openerp.com',
'summary': 'HIS Test',
'sequence': 9,
'depends': ['web'],
'data': [
'histest_view.xml',
],
'demo': [],
'test': [],
'css': [],
'js':[
'static/src/js/histest.js'
],
'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'
def get_full_name(self, cr, uid, ids, field_name, arg, context):
patients = self.browse(cr, uid, ids)
result = {}
for p in patients:
result[p.id] = (u'%s %s %s' % (p.title,
p.first_name,
p.last_name))
return result
_rec_name='full_name'
_columns={
'title': fields.char(size=50,
string=u'คำนำหน้าชื่อ',
required=True),
'first_name': fields.char(size=256,
string=u'ชื่อ',
required=True),
'last_name': fields.char(size=256,
string=u'นามสกุล',
required=True),
'sex': fields.selection([('M',u'ชาย'),('F',u'หญิง'),],
string=u'เพศ',
required=True),
'id_number': fields.char(size=20,
string=u'เลขบัตรประชาชน',
required=True),
'full_name': fields.function(get_full_name,
type='char')
}
ไฟล์ 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="Stages">
<field name="title"/>
<field name="first_name"/>
<field name="last_name"/>
<field name="sex"/>
<field name="id_number"/>
</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"/>
<field name="sex"/>
<field name="id_number"/>
</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>
<record model="ir.actions.client" id="action_histest_client_index">
<field name="name">HISTest Client Index</field>
<field name="tag">histest.indexAction</field>
</record>
<menuitem name="HIS" id="menu_histest_top"
parent="" sequence="1"
action="histest.action_histest_patient"/>
<menuitem name="Hospital Inf Sys" id="menu_histest_main"
parent="menu_histest_top" sequence="1"/>
<menuitem name="หน้าหลัก" id="menu_histest_index"
parent="menu_histest_main" sequence="1"
action="histest.action_histest_client_index"/>
<menuitem name="เพิ่มข้อมูลผู้ป่วย" id="menu_histest_patient_new"
parent="menu_histest_main" sequence="2"
action="histest.action_histest_patient"/>
</data>
</openerp>
ไฟล์ static/src/js/histest.js
openerp.histest = function(instance) {
instance.web.client_actions.add('histest.indexAction',
'instance.histest.indexAction');
instance.histest.indexAction = instance.web.Widget.extend({
className: 'oe_histest_index',
start: function() {
this.$el.html("<h1>Hello!</h1>");
return this._super();
}
});
};