Penambahan Monetary Field dalam Kustomisasi Odoo 17

Sep 2, 2024 | Odoo 17 Development

Dalam mengembangkan aplikasi berbasis Odoo 17 kita mungkin akan membuat form-form mengenai harga barang atau harga layanan yang lain. Di sini kita dapat menggunakan monetary field.

Penambahan monetary field dalam kustomisasi Odoo 17 adalah seperti langkah-langkah berikut ini

  1. Menambahkan model baru

    from odoo import fields, models
    
    
    class AsramaRoom(models.Model):
        _name = "asrama.room"
        _description = "Informasi Kamar Asrama"
        _rec_name = "room_no"
    
        name = fields.Char(string="Nama Kamar", required=True)
        room_no = fields.Char("No Kamar", required=True)
        floor_no = fields.Integer("No Lantai", default=1, help="No Lantai")
        currency_id = fields.Many2one('res.currency', string='Mata Uang')
        rent_amount = fields.Monetary('Harga Sewa', help='Masukkan harga sewa')
    
  2. Update pada security csv

    id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
    access_hostel_manager_id,access.hostel.manager,asramaku.model_asrama_hostel,group_hostel_manager,1,1,1,1
    access_hostel_user_id,access.hostel.user,asramaku.model_asrama_hostel,group_hostel_user,1,0,0,0
    access_hostel_room_manager_id,access.hostel.room.manager,asramaku.model_asrama_room,asramaku.group_hostel_manager,1,1,1,1
    access_hostel_room_user_id,access.hostel.room.user,asramaku.model_asrama_room,asramaku.group_hostel_user,1,0,0,0
    
  3. Tambahkan view

    <?xml version="1.0" encoding="UTF-8"?>
    <odoo>
        <data>
            <record id="view_asrama_room_tree" model="ir.ui.view">
                <field name="name">asrama.room.tree</field>
                <field name="model">asrama.room</field>
                <field name="arch" type="xml">
                    <tree string="Room">
                        <field name="name"/>
                        <field name="room_no"/>
                        <field name="floor_no"/>
                    </tree>
                </field>
            </record>
    
            <record id="view_asrama_room_form" model="ir.ui.view">
                <field name="name">asrama.room.form</field>
                <field name="model">asrama.room</field>
                <field name="arch" type="xml">
                    <form string="Room">
                        <sheet>
                            <group col="4" name="main">
                                <field name="name"/>
                                <field name="room_no"/>
                                <field name="floor_no"/>
                            </group>
                            <group col="4">
                                <field name="rent_amount"/>
                                <field name="currency_id"/>
                            </group>
                        </sheet>
                    </form>
                </field>
            </record>
    
            <record model="ir.actions.act_window" id="action_asrama_room">
                <field name="name">Room</field>
                <field name="type">ir.actions.act_window</field>
                <field name="res_model">asrama.room</field>
                <field name="view_mode">tree,form</field>
                <field name="domain">[]</field>
                <field name="context">{}</field>
                 <field name="help" type="html">
                    <p class="oe_view_nocontent_create">
                        Tambah Kamar.
                    </p>
                 </field>
            </record>
    
            <menuitem id="asrama_room_menu" name="Kamar Asrama" parent="asramaku.hostel_main_menu"
                action="asramaku.action_asrama_room" groups="asramaku.group_hostel_manager"
                sequence="2"/>
    
        </data>
    </odoo>
    
  4. Update model – init

    from . import hostel
    from . import asrama_room
    
  5. Mengupdate manifest

    {
        'name': 'Manajemen Asrama',
        "summary": "Cara mudah kelola asrama",
        "data":[
            "security/hostel_security.xml",
            "security/ir.model.access.csv",
            "data/data.xml",
            "views/hostel.xml",
            "views/asrama_room.xml",
        ],
    }
    
  6. Restart Odoo
    # /home/apku/odooku/addons# chmod -R a+rx asramaku
    # docker restart odooku-web-1
    
  7. Mengaktifkan developer mode dengan Odoo Debug

  8. Upgrade modul

  9. Tampilan hostel

  10. Tampilan kamar asrama
    List view:


    Form view:

Kunjungi www.proweb.co.id/implementasi-odoo/ untuk menambah wawasan implementasi Odoo ERP.

Odoo ERP merupakan aplikasi lengkap untuk otomatisasi proses bisnis perusahaan anda.
Jika anda tertarik dengan Odoo ERP silahkan mengisi form di bawah ini