This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contoh, kebutuhan untuk menambahkan nama proyek yang berhubungan dengan expense karyawan
Maka yang perlu kita cari tahu pertama kali adalah, ada di modul apakah form tersebut.
Tentunya ada di modul hr_expense dengan tabel di database hr_expense_expense
di modul hr_expense, yang perlu diperhatikan adalah file python hr_expense.py tempat definisi tabel dan proses-proses yang terjadi.
dan file xml untuk mendefinisikan tampilan form tersebut.
terus.... kita ubahkah kedua file tersebut? BIG NO!!
Biarkan modul tersebut apa adanya, jangan menambah, mengubah, menghapus, apapun di situ...
hmm biasanya siii saya cuma menambahkan _logger.. untuk debug kalo ada bugs...
Lalu apa yang kita lakukan?
Kita buat satu modul baru ..
contoh: smcus_hr_expense
apa itu smcus? yaa ini hanya initial nama saya saja sm(siti mawaddah) cus (custom)
jadi untuk mempermudah mencari modul2 hasil custom kita...
SO, kita buat folder baru di dalam folder addons
terus diisi apa aja nih..
karena saya bilang ini dasar-dasar... maka cukup 4 file saja:
__init__.py
__openerp__.py
hr_expense.py
hr_expense_view.xml
__init__.py
isinya apa nih?
cukup 1 baris:
import hr_expense
hr_expense menunjukkan nama file python yang akan digunakan yaitu hr_expense.py
kalau ada 2 file misal hr_expense_expense.py, dan keduanya digunakan ya tambahin lagi aja
import hr_expense
import hr_expense_expense
__openerp__.py
Kodenya seperti berikut ini:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-
'name': menunjukkan nama modulnya
'depends': menunjukkan modul yang terkait dengan custom modul ini. yaitu hr_expense
'data': file yang akan diikutsertakan dalam proses, bisa file xml untuk view atau file csv sebagai contoh data.
Dalam hal ini hanya file hr_expense_view.xml
'category': free text untuk memudahkan kita mencari modul yang kita sudah buat di list modul OpenERP
hr_expense.py
Di awal kita menentukan bahwa kita mau tambahkan field project, maka kita tambahkan di dictionary _columns seperti ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'hr.expense.expense' menunjukkan nama object yang diinherit...
Kalau kita cek di class parent nya... ada di hr_expense/hr_expense.py seperti ini:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'date_confirm': fields.date('Confirmation Date', select=True, help="Date of the confirmation of the sheet expense. It's filled when the button Confirm is pressed."),
'date_valid': fields.date('Validation Date', select=True, help="Date of the acceptation of the sheet expense. It's filled when the button Accept is pressed."),
help='When the expense request is created the status is \'Draft\'.\n It is confirmed by the user and request is sent to admin, the status is \'Waiting Confirmation\'.\
\nIf the admin accepts it, the status is \'Accepted\'.\n If a receipt is made for the expense request, the status is \'Done\'.'),
atau bisa langsung cek aja di folder instalasi openerp
biasanya ada di /opt/openerp/openerp/doc
cukup lengkap kok
untuk dict _defaults digunakan untuk menentukan nilai default dari setiap field...
kalau tidak perlu ya dikosongkan saja
hr_expense_view.xml
Untuk bagian ini, kita tentukan dulu di awal field Project itu mau dimunculkan di mana saja?
di form saja, atau juga di tree dan search view
untuk saat ini kita tambahkan di form dan tree saja yaa
hmm semuanya aja deh ...
yang perlu kita cari pertama kalo adalah model view di file asli hr_expense/hr_expense_view.xml
cari nama object yang sesuai yaitu hr.expense.expense
sudah ketemu?
ya kita perhatikan
record id="view_expenses_tree" untuk tree view
record id="view_expenses_form" untuk form view
untuk yang pertama tree... sekali lagi kita perlu membuat inheritance model seperti ini:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
atribut model: diisi dengan nama object (nama tabel)yang bersesuaian
atribut inherit_id: diisi dengan "nama_modul_asli.id_view_parent"
karena itu kita isi dengan "hr_expense.view_expenses_tree"
nah kemudian di dalam tag dg atribut arch, kita tentukan posisi field baru yang dibuat
Kalau dilihat model view_expense_tree, kita tentukan posisi field smcus_project_name ada setelah field employee_id (Employee)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
position dapat diisi "before" (posisi sebelum field bersangkutan) dan "replace" (menimpa field)
untuk model form
Kita tentukan posisinya ada di bawah field currency
maka kita buat model view berikut ini:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Kalau sudah, kita gabungkan tree dan form
ke dalam 1 file hr_expense_view.xml berikut ini:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters