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

จาก Theory Wiki
ไปยังการนำทาง ไปยังการค้นหา
แถว 35: แถว 35:
 
     'sequence': 9,
 
     'sequence': 9,
 
     'depends': [],
 
     'depends': [],
     'data': [],
+
     'data': [
 +
        'easynote_view.xml',
 +
    ],
 
     'demo': [],
 
     'demo': [],
 
     'test': [],
 
     'test': [],
แถว 44: แถว 46:
 
     'auto_install': False,
 
     'auto_install': False,
 
}
 
}
 +
</syntaxhighlight>
 +
 +
* สร้างไฟล์ <tt>easynote.py</tt>
 +
 +
<syntaxhighlight lang="python">
 +
from osv import osv, fields
 +
 +
class Note(osv.Model):
 +
    _name = 'easynote.note'
 +
    _rec_name = 'title'
 +
    _columns = {
 +
        'title': fields.char('Title', size=100, required=True),
 +
        'body': fields.text('Body', required=True),
 +
    }
 +
</syntaxhighlight>
 +
 +
* สร้างไฟล์ <tt>easynote_view.xml</tt>
 +
 +
<syntaxhighlight lang="xml">
 +
<?xml version="1.0" encoding="utf-8"?>
 +
<openerp>
 +
  <data>
 +
    <!-- New note Form View -->
 +
    <record model="ir.ui.view" id="view_easynote_note_tree">
 +
      <field name="name">easynote.note.tree</field>
 +
      <field name="model">easynote.note</field>
 +
      <field name="arch" type="xml">
 +
        <tree string="Stages">
 +
          <field name="title"/>
 +
          <field name="body"/>
 +
        </tree>
 +
      </field>
 +
    </record>
 +
 +
    <!-- New note Form View -->
 +
    <record model="ir.ui.view" id="view_easynote_note_form">
 +
        <field name="name">easynote.note.form</field>
 +
        <field name="model">easynote.note</field>
 +
        <field name="arch" type="xml">
 +
          <form string="Note" version="7.0" class="oe_form_nomargin">
 +
            <field name="title" />
 +
            <field name="body" widget="html" class="oe_memo" editor_height="450px" />
 +
          </form>
 +
        </field>
 +
    </record>
 +
 +
    <record model="ir.actions.act_window" id="action_easynote_note">
 +
      <field name="name">EasyNotes</field>
 +
      <field name="res_model">easynote.note</field>
 +
      <field name="view_type">form</field>
 +
      <field name="view_mode">tree,form</field>
 +
      <field name="context">{'search_default_open_true':True}</field>
 +
      <field name="help" type="html">
 +
        <p class="oe_view_nocontent_create">
 +
          Click to add a personal note.
 +
          </p><p>
 +
          Use notes to organize personal tasks or notes. All
 +
          notes are private; no one else will be able to see them. However
 +
          you can share some notes with other people by inviting followers
 +
          on the note. (Useful for meeting minutes, especially if
 +
          you activate the pad feature for collaborative writings).
 +
          </p><p>
 +
          You can customize how you process your notes/tasks by adding,
 +
          removing or modifying columns.
 +
        </p>
 +
      </field>
 +
    </record>
 +
 +
    <menuitem name="Notes" id="menu_easynote_notes" parent="" sequence="20" action="easynote.action_easynote_note"/>
 +
 +
  </data>
 +
</openerp>
 +
 
</syntaxhighlight>
 
</syntaxhighlight>

รุ่นแก้ไขเมื่อ 17:12, 12 พฤศจิกายน 2556

ขั้นตอนเริ่มต้น

  • สร้าง database ใหม่
  • เข้าใช้เป็น admin
    • ตั้ง Time zone
    • เปิด Technical Features: Users/Users => Administrator => Edit => Access Rights => Technical Features
    • Log out / log in (จะเห็นเมนูเพิ่มขึ้น)

สร้างโมดูล

เอกสารอ้างอิง Help page, [1], Technical Memento
  • สร้างไดเร็กทอรีใน openerp/addons ชื่อตามโมดูล สมมติเราจะสร้างโมดูล easynote
  • สร้างไฟล์ __init__.py
import easynote
  • สร้างไฟล์ __openerp__.py
{
    'name': 'EasyNotes',
    'version': '0.1',
    'category': 'Tools',
    'description': """
This is a sample module
=======================

Easy notes can be found in the 'Home' menu.
""",
    'author': 'Testing',
    'website': 'http://openerp.com',
    'summary': 'Easy notes, easy everything',
    'sequence': 9,
    'depends': [],
    'data': [
        'easynote_view.xml',
    ],
    'demo': [],
    'test': [],
    'css': [],
    'images': [],
    'installable': True,
    'application': True,
    'auto_install': False,
}
  • สร้างไฟล์ easynote.py
from osv import osv, fields

class Note(osv.Model):
    _name = 'easynote.note'
    _rec_name = 'title'
    _columns = {
        'title': fields.char('Title', size=100, required=True),
        'body': fields.text('Body', required=True),
    }
  • สร้างไฟล์ easynote_view.xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
  <data>
    <!-- New note Form View -->
    <record model="ir.ui.view" id="view_easynote_note_tree">
      <field name="name">easynote.note.tree</field>
      <field name="model">easynote.note</field>
      <field name="arch" type="xml">
        <tree string="Stages">
          <field name="title"/>
          <field name="body"/>
        </tree>
      </field>
    </record>

    <!-- New note Form View -->
    <record model="ir.ui.view" id="view_easynote_note_form">
        <field name="name">easynote.note.form</field>
        <field name="model">easynote.note</field>
        <field name="arch" type="xml">
          <form string="Note" version="7.0" class="oe_form_nomargin">
            <field name="title" />
            <field name="body" widget="html" class="oe_memo" editor_height="450px" />
          </form>
        </field>
    </record>

    <record model="ir.actions.act_window" id="action_easynote_note">
      <field name="name">EasyNotes</field>
      <field name="res_model">easynote.note</field>
      <field name="view_type">form</field>
      <field name="view_mode">tree,form</field>
      <field name="context">{'search_default_open_true':True}</field>
      <field name="help" type="html">
        <p class="oe_view_nocontent_create">
          Click to add a personal note.
          </p><p>
          Use notes to organize personal tasks or notes. All
          notes are private; no one else will be able to see them. However
          you can share some notes with other people by inviting followers
          on the note. (Useful for meeting minutes, especially if
          you activate the pad feature for collaborative writings).
          </p><p>
          You can customize how you process your notes/tasks by adding,
          removing or modifying columns.
        </p>
      </field>
    </record>

    <menuitem name="Notes" id="menu_easynote_notes" parent="" sequence="20" action="easynote.action_easynote_note"/>

  </data>
</openerp>