Openerp/histest

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

สร้างโมเดล Department และเชื่อมโยงกับ Appointment เพื่อค้นหาและสร้างรายงาน

histest.py

class HISAppointment(osv.Model):
    _name = 'histest.appointment'
    _columns = {
        'date': fields.date(string=u'วันที่',
                            required=True),
        'patient_id': fields.many2one('histest.patient',
                                      'Patient'),
        'department_id': fields.many2one('histest.department',
                                         'Department'),
    }

class HISDepartment(osv.Model):
    _name = 'histest.department'
    _columns = {
        'name': fields.char(size=200,
                            string=u'แผนก',
                            required=True),
        'appointment_ids': fields.one2many('histest.appointment',
                                           'department_id',
                                           'Appointments'),
    }

class HISDepartmentSearch(osv.TransientModel):
    _name = 'histest.departmentsearch'

    def appointment_search(self, cr, uid, ids, field_name=None,
                           arg=None, context=None):

        appointment_obj = self.pool.get('histest.appointment')

        dsearches = self.browse(cr, uid, ids)
        result = {}
        for dsearch in dsearches:
            result[dsearch.id] = (
                appointment_obj.search(cr, uid,
                                       [('department_id','=',dsearch.department_id.id),
                                        ('date','=',dsearch.search_date)],
                                       context=context))
        return result

    _columns = {
        'department_id': fields.many2one('histest.department',
                                         'Department'),
        'search_date': fields.date(string=u'วันที่ต้องการหา'),

        'appointment_ids': fields.function(appointment_search,
                                           type='one2many',
                                           relation='histest.appointment',
                                           string='Appointment by date'),
    }

histest_view.xml

ส่วน department form:

    <record model="ir.ui.view" id="view_histest_department_form">
      <field name="name">histest.department.form</field>
      <field name="model">histest.department</field>
      <field name="arch" type="xml">
        <form string="Patient" version="7.0">
          <group>
            <field name="name"/>
            <field name="appointment_ids"/>
          </group>
        </form>
      </field>
    </record>

    <record model="ir.actions.act_window" id="action_histest_department">
      <field name="name">Department</field>
      <field name="res_model">histest.department</field>
      <field name="view_type">form</field>
      <field name="view_mode">form,tree</field>
    </record>

    <menuitem name="แผนก" id="menu_histest_department"
              parent="menu_histest_main" sequence="4"
              action="histest.action_histest_department"/>

ส่วน department search form:

    <record model="ir.ui.view" id="view_histest_departmentsearch_form">
      <field name="name">histest.departmentsearch.form</field>
      <field name="model">histest.departmentsearch</field>
      <field name="arch" type="xml">
        <form string="Patient" version="7.0">
          <group>
            <field name="department_id"/>
            <field name="search_date"/>
            <field name="appointment_ids"/>
          </group>
        </form>
      </field>
    </record>

    <record model="ir.actions.act_window" id="action_histest_departmentsearch">
      <field name="name">Department Appointment Search</field>
      <field name="res_model">histest.departmentsearch</field>
      <field name="view_type">form</field>
      <field name="view_mode">form,tree</field>
    </record>

    <menuitem name="แผนก search" id="menu_histest_departmentsearch"
              parent="menu_histest_main" sequence="5"
              action="histest.action_histest_departmentsearch"/>

appointment tree view:

    <record model="ir.ui.view" id="view_histest_appointment_tree">
      <field name="name">histest.appointment.tree</field>
      <field name="model">histest.appointment</field>
      <field name="arch" type="xml">
        <tree string="Message">
          <field name="patient_id"/>
          <field name="date"/>
        </tree>
      </field>
    </record>

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