ผลต่างระหว่างรุ่นของ "Openerp/histest3"

จาก Theory Wiki
ไปยังการนำทาง ไปยังการค้นหา
(Openerp/histest ถูกเปลี่ยนชื่อเป็น Openerp/histest3)
 
(ไม่แสดง 10 รุ่นระหว่างกลางโดยผู้ใช้ 1 คน)
แถว 1: แถว 1:
 
หน้านี้รวมข้อมูลสำหรับการทดสอบการพัฒนาระบบด้วย OpenERP
 
หน้านี้รวมข้อมูลสำหรับการทดสอบการพัฒนาระบบด้วย OpenERP
== การแยกโค้ด javascript เป็นส่วน ==
+
== การสร้างรายงาน ==
  
'''ก่อนเริ่ม:''' ดาวน์โหลดโค้ด [http://theory.cpe.ku.ac.th/~jittat/openerp/histest.zip histest.zip] จากครั้งก่อน
+
* สร้างไดเรคตอรี่ชื่อ <code>report</code> และสร้างไฟล์ <code>__init__.py</code> ไว้ภายในนั้น
 +
* ดาวน์โหลด [[File:histest_patient.odt]] เพื่อใช้เตรียมเทมเพลทสำหรับรายงาน เซฟไฟล์นี้ไว้ในไดเรคตอรี <code>report</code>
 +
* ใช้คำสั่ง <code>openerp_sxw2rml.py</code> แปลงไฟล์ของ OpenOffice ให้เป็นไฟล์ RML (Report Markup Language) เพื่อนำไปใช้กับระบบสร้างรายงานของ OpenERP ต่อไป (หมายเหตุ: <code><openerp-path></code> หมายถึงพาธที่ติดตั้ง OpenERP)
  
=== histest.js ===
+
python <openerp-path>/openerp/addons/base_report_designer/openerp_sxw2rml/openerp_sxw2rml.py histest_patient.odt > histest_patient.rml
  
<syntaxhighlight lang="javascript">
+
=== ไฟล์ <code>histest_patient.rml</code> ===
openerp.histest = function(instance) {
+
อย่างไรก็ตาม หากไม่ต้องการใช้ OpenOffice/LibreOffice ในการสร้างเทมเพลท เราสามารถสร้างไฟล์ RML ขึ้นมาได้ด้วยตัวเองดังนี้
 +
<syntaxhighlight lang="xml">
 +
<?xml version="1.0"?>
 +
<document filename="test.pdf">
 +
  <template pageSize="(595.0,842.0)" title="Test" author="Martin Simon" allowSplitting="20">
 +
    <pageTemplate id="first">
 +
      <frame id="first" x1="57.0" y1="57.0" width="481" height="728"/>
 +
    </pageTemplate>
 +
  </template>
 +
  <stylesheet>
 +
    <blockTableStyle id="Standard_Outline">
 +
      <blockAlignment value="LEFT"/>
 +
      <blockValign value="TOP"/>
 +
    </blockTableStyle>
 +
    <initialize>
 +
      <paraStyle name="all" alignment="justify"/>
 +
    </initialize>
 +
    <paraStyle name="P1" fontName="Helvetica"/>
 +
    <paraStyle name="P2" fontName="Helvetica"/>
 +
    <paraStyle name="Standard" fontName="Helvetica"/>
 +
    <paraStyle name="Heading" fontName="Helvetica" fontSize="12.0" leading="15" spaceBefore="12.0" spaceAfter="6.0"/>
 +
    <paraStyle name="Text_20_body" fontName="Helvetica" spaceBefore="0.0" spaceAfter="6.0"/>
 +
    <paraStyle name="List" fontName="Helvetica" spaceBefore="0.0" spaceAfter="6.0"/>
 +
    <paraStyle name="Caption" fontName="Helvetica-Oblique" fontSize="10.0" leading="13" spaceBefore="6.0" spaceAfter="6.0"/>
 +
    <paraStyle name="Index" fontName="Helvetica"/>
 +
    <paraStyle name="Heading_20_1" fontName="Helvetica-Bold" fontSize="115%" leading="NaN" spaceBefore="12.0" spaceAfter="6.0"/>
 +
    <paraStyle name="Table_20_Contents" fontName="Helvetica"/>
 +
    <images/>
 +
  </stylesheet>
 +
  <story>
 +
    <para style="P2">Patient Appointment Information</para>
 +
    <para style="P1">
 +
      <font color="white"> </font>
 +
    </para>
 +
    <section>
 +
      <para style="P1">[[ repeatIn(objects, 'patient') ]]</para>
 +
      <para style="P1">Patient ID: [[ patient.id_number ]]</para>
 +
      <para style="P1">Patient Name: [[ patient.full_name ]]</para>
 +
      <para style="P1">
 +
        <font color="white"> </font>
 +
      </para>
 +
      <para style="P1">Appointment Dates:</para>
 +
      <section>
 +
        <para style="P1">[[ repeatIn(patient.appointment_ids, 'appointment') ]]</para>
 +
        <para style="P1">- [[ appointment.date ]]</para>
 +
      </section>
 +
      <para style="P1">
 +
        <font color="white"> </font>
 +
      </para>
 +
    </section>
 +
    <para style="P1">
 +
      <font color="white"> </font>
 +
    </para>
 +
    <para style="P1">
 +
      <font color="white"> </font>
 +
    </para>
 +
  </story>
 +
</document>
 +
</syntaxhighlight>
  
    openerp.histest.message(instance);
+
=== ไฟล์ <code>histest.py</code> ===
    openerp.histest.patient(instance);
+
เพิ่มโมเดล HISAppointment และแก้ไขโมเดล HISPatient ให้เชื่อมโยงถึงกัน
   
 
    instance.web.client_actions.add('histest.indexAction',
 
                                    'instance.histest.patient.indexAction');
 
  
};
+
<syntaxhighlight lang="python">
</syntaxhighlight>
+
from osv import osv, fields
  
=== histest_message.js ===
+
class HISPatient(osv.Model):
 +
    _name='histest.patient'
  
<syntaxhighlight lang="javascript">
+
    def get_full_name(self, cr, uid, ids, field_name, arg, context):
openerp.histest.message = function(instance) {
+
        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
  
    instance.histest.message = {};
 
    instance.histest.message.popupInterval = null;
 
    instance.histest.message.MsgManagerWidget = instance.web.Widget.extend({
 
  
        start: function() {
+
    _rec_name='full_name'
            var self = this;
 
            console.log("MsgMan started...");
 
            if(instance.histest.message.popupInterval) {
 
                clearInterval(instance.histest.message.popupInterval);
 
            }
 
            instance.histest.message.popupInterval = setInterval(function() {
 
                self.popup();
 
            },5000);
 
            this.shownMsgId = 0;
 
            this.fetchNewMessage(this.shownMsgId, function(msgId) {
 
                self.shownMsgId = msgId;
 
            });
 
        },
 
  
         fetchNewMessage: function(recentId, callback) {
+
    _columns={
            var model = new instance.web.Model('histest.message');
+
         'title': fields.char(size=50,
            model.query().filter([['id','>',recentId]]).all().done(function(results){
+
                            string=u'คำนำหน้าชื่อ',
                if (results.length > 0) {
+
                            required=True),
                    msgId = results[results.length-1].id;
+
        'first_name': fields.char(size=256,
                    callback(msgId);
+
                                  string=u'ชื่อ',
                }
+
                                  required=True),
            });
+
        'last_name': fields.char(size=256,
        },
+
                                string=u'นามสกุล',
          
+
                                required=True),
        popup: function() {
+
        'sex': fields.selection([('M',u'ชาย'),('F',u'หญิง'),],
            var self = this;
+
                                string=u'เพศ',
            this.fetchNewMessage(this.shownMsgId, function(msgId) {
+
                                required=True),
                self.do_action({
+
         'id_number': fields.char(size=20,
                    type: 'ir.actions.act_window',
+
                                string=u'เลขบัตรประชาชน',
                    res_model: "histest.message",
+
                                required=True),
                    res_id: msgId,
+
        'full_name': fields.function(get_full_name,
                    views: [[false, 'form']],
+
                                    type='char'),
                    target: 'new',
+
        'appointment_ids': fields.one2many('histest.appointment',
                    context: {},
+
                                          'patient_id',
                });
+
                                          'Appointments'),
                self.shownMsgId = msgId;
+
     }
            });
 
        }
 
     });
 
};
 
</syntaxhighlight>
 
 
 
=== histest_patient.js ===
 
<syntaxhighlight lang="javascript">
 
openerp.histest.patient = function(instance) {
 
 
      
 
      
    instance.histest.patient = {};
+
:
    instance.histest.patient.indexAction = instance.web.Widget.extend({
 
        template: 'histest.index',
 
        events: {
 
            'click .oe_histest_patient_new_link': 'linkClick',
 
            'click .oe_histest_patient_query_link': 'patientQuery',
 
        },
 
  
        start: function() {
+
class HISAppointment(osv.Model):
            var msgManager = new instance.histest.message.MsgManagerWidget(this);
+
    _name = 'histest.appointment'
            msgManager.appendTo('.oe_application');
+
    _columns = {
        },
+
             'date': fields.date(string=u'วันนัดหมาย', required=True),
 
+
             'patient_id': fields.many2one('histest.patient', 'Patient'),
        patientQuery: function() {
+
             }
            var model = new instance.web.Model('histest.patient');
 
            var self = this;
 
             self.$(".oe_histest_patient_results").html("");
 
            model.query().all().done(function(results) {
 
                for(var i=0; i < results.length; i++) {
 
                    self.$(".oe_histest_patient_results")
 
                        .append('<li>' + results[i].first_name + '</li>');
 
                }
 
            });
 
        },
 
 
 
        linkClick: function() {
 
             this.do_action({
 
                type: 'ir.actions.act_window',
 
                res_model: 'histest.patient',
 
                views: [[false,'form']],
 
                target: 'current',
 
                context: {},
 
             });
 
        }
 
    });
 
};
 
</syntaxhighlight>
 
 
 
== Responsive CSS ==
 
 
 
=== addons/web/static/src/xml/base.xml ===
 
 
 
<syntaxhighlight lang="diff">
 
453c453
 
<            <td colspan="2" class="oe_topbar">
 
---
 
>            <td colspan="1" class="oe_topbar">
 
460c460,461
 
<            <td class="oe_leftbar" valign="top">
 
---
 
>          <td>
 
>            <div class="oe_leftbar" style="float: left;" valign="top">
 
470,472c471,474
 
<            </td>
 
<            <td class="oe_application">
 
<            </td>
 
---
 
>            </div>
 
>            <div class="oe_application" style="float: left">
 
>            </div>
 
>          </td>
 
 
</syntaxhighlight>
 
</syntaxhighlight>
 
=== addons/web/controllers/main.py ===
 
 
 
<syntaxhighlight lang="diff">
 
546a547
 
>        <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0" />
 
</syntaxhighlight>
 
 
=== histest/static/src/css/histest.css ===
 
 
<syntaxhighlight lang="css">
 
.openerp .oe_histest_index {
 
    padding: 10px;
 
    background: black;
 
    color: white;
 
}
 
.openerp .oe_histest_index h1 {
 
    font-size: 40px;
 
}
 
.openerp .oe_application {
 
    width: calc(100% - 221px);
 
}
 
 
@media screen and (max-width: 800px) {
 
    .openerp .oe_leftbar {
 
        width: 100%;
 
    }
 
    .openerp .oe_application {
 
        width: 100%;
 
    }
 
    .openerp a.oe_logo {
 
        display: none;
 
    }
 
}
 
</syntaxhighlight>
 
 
== Asynchronous request ==
 
 
== เพิ่มปุ่ม Search ในฟอร์มให้เรียกค้นกลับไปยังเซิร์ฟเวอร์ของ OpenERP ==
 
  
 
=== ไฟล์ <code>histest_view.xml</code> ===
 
=== ไฟล์ <code>histest_view.xml</code> ===
 +
เพิ่มการแสดงผลฟิลด์ appointment_ids ในฟอร์มของโมเดล HISPatient
  
แก้ไข view <code>histest.patient.form</code> โดยระบุชนิด widget ที่สร้างขึ้นมาให้กับฟิลด์ <code>first_name</code> <code>last_name</code> และ <code>id_number</code>
 
 
<syntaxhighlight lang="xml">
 
<syntaxhighlight lang="xml">
<record model="ir.ui.view" id="view_histest_patient_form">
+
    <record model="ir.ui.view" id="view_histest_patient_form">
  <field name="name">histest.patient.form</field>
+
      <field name="name">histest.patient.form</field>
  <field name="model">histest.patient</field>
+
      <field name="model">histest.patient</field>
  <field name="arch" type="xml">
+
      <field name="arch" type="xml">
    <form string="Patient" version="7.0">
+
        <form string="Patient" version="7.0">
      <group cols="2">
+
          <group cols="2">
        <group colspan="1">
+
            <group colspan="1">
          <field name="title"/>
+
              <field name="title"/>
          <field name="first_name" widget="firstname" />
+
              <field name="first_name" widget="firstname" />
          <field name="last_name" widget="lastname" />
+
              <field name="last_name" widget="lastname" />
        </group>
+
            </group>
        <group colspan="1">
+
            <group colspan="1">
          <field name="sex"/>
+
              <field name="sex"/>
          <field name="id_number" widget="person_id" />
+
              <field name="id_number" widget="person_id" />
        </group>
+
              <field name="appointment_ids" />
      </group>
+
            </group>
    </form>
+
          </group>
  </field>
+
        </form>
</record>
+
      </field>
 +
    </record>
 
</syntaxhighlight>
 
</syntaxhighlight>
  
=== ไฟล์ <code>static/src/xml/histest.xml</code> ===
+
=== ไฟล์ <code>histest_report.xml</code> ===
เพิ่มเทมเพลทเพื่อใข้กับ widget สำหรับฟิลด์ <code>first_name</code> <code>last_name</code> และ <code>id_number</code> ในฟอร์มเพิ่มข้อมูลผู้ป่วย
+
 
 +
ใช้ไฟล์นี้ระบุองค์ประกอบของรายงานการนัดหมายผู้ป่วย
  
 
<syntaxhighlight lang="xml">
 
<syntaxhighlight lang="xml">
  <t t-name="histest.FieldPID" t-extend="FieldChar">
+
<?xml version="1.0" encoding="utf-8"?>
    <t t-jquery="input">
+
<openerp>
      this.parent().append('<button class="oe_histest_pid_search">Search</button>');
+
   <data>
    </t>
 
   </t>
 
  
  <t t-name="histest.FieldFirstName" t-extend="FieldChar">
+
    <report
    <t t-jquery="input">
+
      auto="True"
       this.addClass("oe_histest_firstname");
+
      id="report_histest_patient"
    </t>
+
      model="histest.patient"
  </t>
+
      name="histest.patient"
 +
      rml="histest/report/histest_patient.rml"
 +
      string="Print Appointments"
 +
       header="False"
 +
      menu="True"
 +
      />
  
   <t t-name="histest.FieldLastName" t-extend="FieldChar">
+
   </data>
    <t t-jquery="input">
+
</openerp>
      this.addClass("oe_histest_lastname");
 
    </t>
 
  </t>
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 +
=== ไฟล์ <code>__openerp__.py</code> ===
  
=== ไฟล์ <code>static/src/js/histest_regis.js</code> ===
+
ระบุให้ใช้ไฟล์ <code>histest_report.xml</code> เป็น data
เป็นไฟล์ใหม่ที่สร้างขึ้นมาเพื่อผูก widget ใหม่เข้ากับเทมเพลท รวมถึงบรรจุโค้ดที่ดำเนินการส่งคำร้องการค้นหาตามรหัสผู้ป่วยแบบ asynchronous กลับมายัง OpenERP Server เมื่อผู้ใช้คลิ้กปุ่ม Search ซึ่งเมื่อได้รับคำตอบแล้วจะนำไปอัพเดตในฟิลด์ <code>first_name</code> และ <code>last_name</code> ที่อยู่ในฟอร์มอีกที
 
 
 
<syntaxhighlight lang="javascript">
 
openerp.histest.regis = function(instance) {
 
    instance.histest.regis = {}
 
 
 
    instance.histest.regis.FieldPID = instance.web.form.FieldChar.extend({
 
 
 
        template: 'histest.FieldPID',
 
 
 
        events: {
 
          'click .oe_histest_pid_search': function(e) {
 
            var url = "/histest/ajax?pid="+$(".oe_histest_pid_search").parent().find("input").val();
 
            $.getJSON(url, function(data) {
 
              $(".oe_histest_firstname").val(data.firstname);
 
              $(".oe_histest_lastname").val(data.lastname);
 
            });
 
          },
 
        },
 
 
 
    });
 
 
 
    instance.histest.regis.FieldFirstName = instance.web.form.FieldChar.extend({
 
        template: 'histest.FieldFirstName',
 
    });
 
 
 
    instance.histest.regis.FieldLastName = instance.web.form.FieldChar.extend({
 
        template: 'histest.FieldLastName',
 
    });
 
 
 
    instance.web.form.widgets.add('person_id', 'instance.histest.regis.FieldPID');
 
    instance.web.form.widgets.add('firstname', 'instance.histest.regis.FieldFirstName');
 
    instance.web.form.widgets.add('lastname', 'instance.histest.regis.FieldLastName');
 
};
 
</syntaxhighlight>
 
 
 
=== ไฟล์ <code>__openerp__.py</code> ===
 
ระบุให้โค้ดจาวาสคริปต์ <code>static/src/js/histest_regis.js</code> ถูกโหลดพร้อมกับมอดูล
 
  
 
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
     'js': [
+
{
         'static/src/js/histest.js',
+
    :
        'static/src/js/histest_message.js',
+
     'data': [
        'static/src/js/histest_patient.js',
+
         'histest_view.xml',
         'static/src/js/histest_regis.js',
+
         'histest_report.xml',
 
     ],
 
     ],
 +
    :
 +
}
 
</syntaxhighlight>
 
</syntaxhighlight>
  
== สร้าง web controller เพื่อรับคำร้องการค้นหา ==
+
== การทำให้รายงานรองรับการใช้งานภาษาไทย ==
web controller ที่สร้างขึ้นมีขั้นตอนการทำงานดังนี้
+
แก้ไขไฟล์ <code><openerp-path>/openerp/report/render/rml2pdf/customfonts.py</code> เพื่อระบุให้ใช้ฟอนต์ Garuda แทนฟอนต์ Helvetica รวมถึงระบุพาธสำหรับการค้นหาไฟล์ True-Type Font ที่อ้างถึง
 +
<syntaxhighlight lang="python">
 +
:
 +
CustomTTFonts = [ ('Helvetica',"Garuda", "Garuda.ttf", 'normal'),
 +
        ('Helvetica',"Garuda Bold", "Garuda-Bold.ttf", 'bold'),
 +
        ('Helvetica',"Garuda Oblique", "Garuda-Oblique.ttf", 'italic'),
 +
        ('Helvetica',"Garuda BoldOblique", "Garuda-BoldOblique.ttf", 'bolditalic'),
 +
        :
 +
]
  
# รับคำร้องในรูป AJAX request เมื่อผู้ใช้กดปุ่มค้นหาในฟอร์มวิว
 
# ส่งเลขประจำตัวผู้ป่วยไปยังเซิร์ฟเวอร์ให้บริการข้อมูล (อาทิเช่นเซิร์ฟเวอร์ทะเบียนราษฎร์) เพื่อขอรายละเอียดผู้ป่วย
 
# คืนผลลัพธ์กลับไปที่ฟอร์มในรูปของ JSON
 
  
== การสร้างรายงาน ==
+
TTFSearchPath_Linux = [
 +
            '/usr/share/fonts/truetype', # SuSE
 +
            '/usr/share/fonts/dejavu', '/usr/share/fonts/liberation', # Fedora, RHEL
 +
            '/usr/share/fonts/truetype/*', # Ubuntu,
 +
            '/usr/share/fonts/thai-scalable', # CentOS
 +
            '/usr/share/fonts/TTF/*', # at Mandriva/Mageia
 +
            '/usr/share/fonts/TTF', # Arch Linux
 +
            ]
 +
:
 +
</syntaxhighlight>
  
 
== เอกสารครั้งก่อน ๆ ==
 
== เอกสารครั้งก่อน ๆ ==
 
* [[Openerp/histest1|โค้ดสำหรับการทดสอบครั้งที่ 1 วันที่ 27 มี.ค. 2557]] - เกี่ยวกับ web module และการเรียก message
 
* [[Openerp/histest1|โค้ดสำหรับการทดสอบครั้งที่ 1 วันที่ 27 มี.ค. 2557]] - เกี่ยวกับ web module และการเรียก message
 +
* [[Openerp/histest2|โค้ดสำหรับการทดสอบครั้งที่ 2 วันที่ 3 เม.ย. 2557]] - การทำ responsive css และ asynchronous request

รุ่นแก้ไขปัจจุบันเมื่อ 07:31, 24 เมษายน 2557

หน้านี้รวมข้อมูลสำหรับการทดสอบการพัฒนาระบบด้วย OpenERP

การสร้างรายงาน

  • สร้างไดเรคตอรี่ชื่อ report และสร้างไฟล์ __init__.py ไว้ภายในนั้น
  • ดาวน์โหลด ไฟล์:Histest patient.odt เพื่อใช้เตรียมเทมเพลทสำหรับรายงาน เซฟไฟล์นี้ไว้ในไดเรคตอรี report
  • ใช้คำสั่ง openerp_sxw2rml.py แปลงไฟล์ของ OpenOffice ให้เป็นไฟล์ RML (Report Markup Language) เพื่อนำไปใช้กับระบบสร้างรายงานของ OpenERP ต่อไป (หมายเหตุ: <openerp-path> หมายถึงพาธที่ติดตั้ง OpenERP)
python <openerp-path>/openerp/addons/base_report_designer/openerp_sxw2rml/openerp_sxw2rml.py histest_patient.odt > histest_patient.rml

ไฟล์ histest_patient.rml

อย่างไรก็ตาม หากไม่ต้องการใช้ OpenOffice/LibreOffice ในการสร้างเทมเพลท เราสามารถสร้างไฟล์ RML ขึ้นมาได้ด้วยตัวเองดังนี้

<?xml version="1.0"?>
<document filename="test.pdf">
  <template pageSize="(595.0,842.0)" title="Test" author="Martin Simon" allowSplitting="20">
    <pageTemplate id="first">
      <frame id="first" x1="57.0" y1="57.0" width="481" height="728"/>
    </pageTemplate>
  </template>
  <stylesheet>
    <blockTableStyle id="Standard_Outline">
      <blockAlignment value="LEFT"/>
      <blockValign value="TOP"/>
    </blockTableStyle>
    <initialize>
      <paraStyle name="all" alignment="justify"/>
    </initialize>
    <paraStyle name="P1" fontName="Helvetica"/>
    <paraStyle name="P2" fontName="Helvetica"/>
    <paraStyle name="Standard" fontName="Helvetica"/>
    <paraStyle name="Heading" fontName="Helvetica" fontSize="12.0" leading="15" spaceBefore="12.0" spaceAfter="6.0"/>
    <paraStyle name="Text_20_body" fontName="Helvetica" spaceBefore="0.0" spaceAfter="6.0"/>
    <paraStyle name="List" fontName="Helvetica" spaceBefore="0.0" spaceAfter="6.0"/>
    <paraStyle name="Caption" fontName="Helvetica-Oblique" fontSize="10.0" leading="13" spaceBefore="6.0" spaceAfter="6.0"/>
    <paraStyle name="Index" fontName="Helvetica"/>
    <paraStyle name="Heading_20_1" fontName="Helvetica-Bold" fontSize="115%" leading="NaN" spaceBefore="12.0" spaceAfter="6.0"/>
    <paraStyle name="Table_20_Contents" fontName="Helvetica"/>
    <images/>
  </stylesheet>
  <story>
    <para style="P2">Patient Appointment Information</para>
    <para style="P1">
      <font color="white"> </font>
    </para>
    <section>
      <para style="P1">[[ repeatIn(objects, 'patient') ]]</para>
      <para style="P1">Patient ID: [[ patient.id_number ]]</para>
      <para style="P1">Patient Name: [[ patient.full_name ]]</para>
      <para style="P1">
        <font color="white"> </font>
      </para>
      <para style="P1">Appointment Dates:</para>
      <section>
        <para style="P1">[[ repeatIn(patient.appointment_ids, 'appointment') ]]</para>
        <para style="P1">- [[ appointment.date ]]</para>
      </section>
      <para style="P1">
        <font color="white"> </font>
      </para>
    </section>
    <para style="P1">
      <font color="white"> </font>
    </para>
    <para style="P1">
      <font color="white"> </font>
    </para>
  </story>
</document>

ไฟล์ histest.py

เพิ่มโมเดล HISAppointment และแก้ไขโมเดล HISPatient ให้เชื่อมโยงถึงกัน

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'),
        'appointment_ids': fields.one2many('histest.appointment',
                                           'patient_id',
                                           'Appointments'),
    }
    
:

class HISAppointment(osv.Model):
    _name = 'histest.appointment'
    _columns = {
            'date': fields.date(string=u'วันนัดหมาย', required=True),
            'patient_id': fields.many2one('histest.patient', 'Patient'),
            }

ไฟล์ histest_view.xml

เพิ่มการแสดงผลฟิลด์ appointment_ids ในฟอร์มของโมเดล HISPatient

    <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 cols="2">
            <group colspan="1">
              <field name="title"/>
              <field name="first_name" widget="firstname" />
              <field name="last_name" widget="lastname" />
            </group>
            <group colspan="1">
              <field name="sex"/>
              <field name="id_number" widget="person_id" />
              <field name="appointment_ids" />
            </group>
          </group>
        </form>
      </field>
    </record>

ไฟล์ histest_report.xml

ใช้ไฟล์นี้ระบุองค์ประกอบของรายงานการนัดหมายผู้ป่วย

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

    <report
      auto="True"
      id="report_histest_patient"
      model="histest.patient"
      name="histest.patient"
      rml="histest/report/histest_patient.rml"
      string="Print Appointments"
      header="False"
      menu="True"
      />

  </data>
</openerp>

ไฟล์ __openerp__.py

ระบุให้ใช้ไฟล์ histest_report.xml เป็น data

{
    :
    'data': [
        'histest_view.xml',
        'histest_report.xml',
    ],
    :
}

การทำให้รายงานรองรับการใช้งานภาษาไทย

แก้ไขไฟล์ <openerp-path>/openerp/report/render/rml2pdf/customfonts.py เพื่อระบุให้ใช้ฟอนต์ Garuda แทนฟอนต์ Helvetica รวมถึงระบุพาธสำหรับการค้นหาไฟล์ True-Type Font ที่อ้างถึง

:
CustomTTFonts = [ ('Helvetica',"Garuda", "Garuda.ttf", 'normal'),
        ('Helvetica',"Garuda Bold", "Garuda-Bold.ttf", 'bold'),
        ('Helvetica',"Garuda Oblique", "Garuda-Oblique.ttf", 'italic'),
        ('Helvetica',"Garuda BoldOblique", "Garuda-BoldOblique.ttf", 'bolditalic'),
        :
]


TTFSearchPath_Linux = [
            '/usr/share/fonts/truetype', # SuSE
            '/usr/share/fonts/dejavu', '/usr/share/fonts/liberation', # Fedora, RHEL
            '/usr/share/fonts/truetype/*', # Ubuntu,
            '/usr/share/fonts/thai-scalable', # CentOS
            '/usr/share/fonts/TTF/*', # at Mandriva/Mageia
            '/usr/share/fonts/TTF', # Arch Linux
            ]
:

เอกสารครั้งก่อน ๆ