Create Module Custom Addons in Odoo

create custom module odoo

Odoo memberikan pengembang untuk membuat addons / module custom sesuai kebutuhan. Berikut tahapannya :

1. Di terminal, ketik docker ps

2. Lalu ketik docker exec -it [container_id] bash container_id merupakan ID dari image/container Odoo di docker.

3. Buat module baru dengan perintah : odoo scaffold [module_name] [custom_addons_location] Disini kita akan membuat module bernama Registration.

4. odoo scaffold registration /mnt/extra-addons

5. Rename models file dan buat model baru (customer model) di file addons/registration/models/customer.py.

6. Buat menu root & sub menu di file addons/registration/views/views.xml

    <record id="action_customer_tree" model="ir.actions.act_window">
      <field name="name">Customer</field>
      <field name="res_model">customer.customer</field>
      <field name="view_mode">tree,form</field>
      <field name="help" type="html">
          <p class="o_view_nocontent_smiling_face">
              Create Customer Record
          </p>
      </field>
    </record>

    <!--Parent Menu Registration -->
    <menuitem id="customer_menu_root" name="Registration" sequence="7"/>

    <!--Menu Customer -->
    <menuitem id="customer_menu"
      name="Customer"
      parent="registration.customer_menu_root"
      action="action_customer_tree"/>

7. Buat view untuk tree (list) dan form di file baru addons/registration/views/customer_views.xml.

<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
   <data>
        
    <!-- Customer Action-->
    <record id="action_customer" model="ir.actions.act_window">
        <field name="name">Customer</field>
        <field name="res_model">customer.customer</field>
        <field name="view_mode">tree,form</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Create Customer Record
            </p>
        </field>
    </record>

    <!-- Customer Form View-->
    <record id="customer_view_form" model="ir.ui.view">
        <field name="name">customer.view.form</field>
        <field name="model">customer.customer</field>
        <field name="arch" type="xml">
            <form string="Customer">
                <sheet>
                    <group string="Customer">
                        <group>
                            <field name="name"/>
                            <field name="address"/>
                        </group>
                        <group>
                            <field name="priority"/>
                            <field name="register_date"/>
                        </group>
                            <group>
                        </group>
                        <group>
                            <field name="logo"/>
                        </group>
                    </group>
                    <notebook>
                        <page string="Customer Products">
                            <field name="customer_product_id">
                                <tree editable="bottom">
                                    <field name="product_id"/>
                                    <field name="stock"/>
                                    <field name="tonase"/>
                                    <field name="customer_id" invisible="1"/>
                                </tree>
                            </field>
                        </page>
                    </notebook>
                </sheet>
            </form>
        </field>
    </record>
    
    <!--Employee Tree View-->
    <record id="customer_view_tree" model="ir.ui.view">
        <field name="name">customer.tree</field>
        <field name="model">customer.customer</field>
        <field name="arch" type="xml">
            <tree>
                <field name="name" string="Customer Name"/>
                <field name="priority" string="Priority"/>
                <field name="address" string="Address"/>
            </tree>
        </field>
    </record>
    
    </data>
</odoo>

8. Tambahkan path view di views/manifest.py

9. Set akses in csv file untuk model ini di manifest.py

access_customer_customer,customer.customer,model_customer_customer,base.group_user,1,1,1,1

10. Restart Odoo

11. Pergi ke menu Settings di Odoo, click Activate the developer mode di bagian Developer Tools.

12. Pergi ke menu Apps > Update App List > click tombol Update

13. Install registration module yang sudah dibuat.

Untuk lebih jelasnya, lihat video di youtube kami

About the Author

Leave a Reply

Your email address will not be published. Required fields are marked *

You may also like these