Openerp/histest1
รุ่นแก้ไขเมื่อ 02:05, 2 เมษายน 2557 โดย Jittat (คุย | มีส่วนร่วม) (Openerp/histest ถูกเปลี่ยนชื่อเป็น 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': [
'static/src/css/histest.css',
],
'js':[
'static/src/js/histest.js'
],
'qweb':[
'static/src/xml/histest.xml'
],
'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')
}
class HISMessage(osv.Model):
_name = 'histest.message'
_columns = {
'message': fields.char(
size=200,
string=u'ข้อความ',
required=True),
}
ไฟล์ histest_view.xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Patient views -->
<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>
<!-- Message views -->
<record model="ir.ui.view" id="view_histest_message_tree">
<field name="name">histest.message.tree</field>
<field name="model">histest.message</field>
<field name="arch" type="xml">
<tree string="Message">
<field name="message"/>
</tree>
</field>
</record>
<record model="ir.ui.view" id="view_histest_message_form">
<field name="name">histest.message.form</field>
<field name="model">histest.message</field>
<field name="arch" type="xml">
<form string="Message" version="7.0">
<group>
<field name="message"/>
</group>
</form>
</field>
</record>
<!-- Actions -->
<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>
<record model="ir.actions.act_window" id="action_histest_message">
<field name="name">Message</field>
<field name="res_model">histest.message</field>
<field name="view_type">form</field>
<field name="view_mode">form,tree</field>
</record>
<!-- Menu items -->
<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"/>
<menuitem name="ข้อความ" id="menu_histest_message"
parent="menu_histest_main" sequence="3"
action="histest.action_histest_message"/>
</data>
</openerp>
ไฟล์ static/src/js/histest.js
เขียน html ด้วยมือ
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();
}
});
};
ใช้ QWeb template
openerp.histest = function(instance) {
instance.web.client_actions.add('histest.indexAction',
'instance.histest.indexAction');
instance.histest.indexAction = instance.web.Widget.extend({
template: 'histest.index'
});
};
เพิ่มระบบ message เข้าไป
openerp.histest = function(instance) {
//instance.web.client_actions.add(
// 'histest.indexAction',
// 'instance.histest.index');
instance.histest.indexAction = instance.web.Widget.extend({
template: 'histest.index',
});
instance.web.client_actions.add(
'histest.indexAction',
'instance.histest.MsgManager');
instance.histest.MsgManager = instance.web.Widget.extend({
start: function() {
var self = this;
console.log("MsgMan started...");
setInterval(function() {self.popup();},5000);
this.shownMsgId = 0;
},
popup: function() {
var model = new instance.web.Model('histest.message');
var self = this;
model.query().filter([['id','>',this.shownMsgId]]).all().done(function(results){
if (results.length > 0) {
msgId = results[results.length-1].id;
self.do_action({
type: 'ir.actions.act_window',
res_model: "histest.message",
res_id: msgId,
views: [[false, 'form']],
target: 'new',
context: {},
});
self.shownMsgId = msgId;
}
});
}
});
};
ไฟล์ static/src/css/histest.css
.openerp .oe_histest_index {
padding: 10px;
background: black;
color: white;
}
.openerp .oe_histest_index h1 {
font-size: 40px;
}
ไฟล์ static/src/xml/histest.xml
<templates>
<t t-name="histest.index">
<div class="oe_histest_index">
<h1>Hello!</h1>
<p>
This is my first homepage.
</p>
</div>
</t>
</templates>