Kita telah melakukan pemrograman dasar dengan relasi many2one, many2many dan one2many pada model Odoo ERP. Di sini kita akan memberikan source dari pemrograman dasar pada Odoo ERP ini.

Source code pemrograman dasar Odoo ERP adalah seperti pada penjelasan-penjelasan berikut ini

  1. Source code pada folder root:
    __init__.py:

    from . import models
    

    __manifest__.py:

    {
    	'name': "Estate 01",
    	'version': '1.0',
    	'depends': ['base'],
    	'author': "Proweb Indonesia",
    	'category': 'Estate',
    	'application': True,
    	'data':[
    		'security/ir.model.access.csv',
    		'views/estate_property_views.xml',
    		'views/estate_property_type_views.xml',
    		'views/estate_property_tag_views.xml',
    		'views/estate_property_offer_views.xml',
    		'views/estate_menus.xml',
    	],
    }
    
  2. Source code pada folder models:
    __init__.py:

    from . import estate_property_offer
    from . import estate_property_tag
    from . import estate_property_type
    from . import estate_property
    

    estate_property.py:

    from odoo import fields, models
    
    class EstateProperty(models.Model):
    	_name = "estate.property"
    	_description = "Real Estate Property"
    
    	active = fields.Boolean(default=True)
    	state = fields.Selection(
        	[ 
            	('n', 'New'),
            	('o', 'Offer Received'),
            	('a', 'Offer Accepted'),
            	('s', 'Sold'),('c', 'Cancelled'),
            ],
        	'State', default='n'
        )
    
    	name = fields.Char(required=True,default='Rumah Baru')
    	description = fields.Text()
    
    	property_type_id = fields.Many2one("estate.property.type", string="Property Type")
    	tags_id = fields.Many2many("estate.property.tag", string="Property Tags")
    
    	postcode = fields.Char()
    	date_availability = fields.Date(copy=False)
    	expected_price = fields.Float()
    	selling_price = fields.Float(readonly=True,copy=False)
    	bedrooms = fields.Integer(default=2)
    	living_area = fields.Integer()
    	facades = fields.Integer()
    	garage = fields.Boolean()
    	garden = fields.Boolean()
    	garden_area = fields.Integer()
    	garden_orientation = fields.Selection(
        	[ 
            	('n', 'North'),
            	('s', 'South'),
            	('e', 'East'),
            	('w', 'West'),
            ],
        	'Garden Orientation', default='e'
    	)
    
    	user_id = fields.Many2one("res.users", string="Salesman",default=lambda self: self.env.user)
    	buyer_id = fields.Many2one("res.partner", string="Buyer",copy=False)
    
    	offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offer")
    

    estate_property_offer.py:

    from odoo import fields, models
    
    class EstatePropertyOffer(models.Model):
    	_name = "estate.property.offer"
    	_description = "Property Offer"
    
    	price = fields.Float()
    
    	status = fields.Selection(
        	[ 
            	('a', 'Accepted'),
            	('r', 'Refused'),
            ],
        	'Status', copy=False
    	)
    
    	partner_id = fields.Many2one("res.partner")
    	property_id = fields.Many2one("estate.property")
    

    estate_property_tag.py:

    from odoo import fields, models
      
    class EstatePropertyTag(models.Model):
    	_name = "estate.property.tag"
    	_description = "Property Tag"
      
    	name = fields.Char(required=True)
    

    estate_property_type.py:

    from odoo import fields, models
     
    class EstatePropertyType(models.Model):
        _name = "estate.property.type"
        _description = "Property Type"
     
     
        name = fields.Char(required=True)
    
  3. Source code pada folder security:

    ir.model.access.csv:

    id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
    acl_estate,estate.estate_property,model_estate_property,base.group_user,1,1,1,1
    acl_estate_type,estate.estate_property_type,model_estate_property_type,base.group_user,1,1,1,1
    acl_estate_tag,estate.estate_property_tag,model_estate_property_tag,base.group_user,1,1,1,1
    acl_estate_offer,estate.estate_property_offer,model_estate_property_offer,base.group_user,1,1,1,1
    
  4. Source code pada folder views:
    estate_menus.xml:

    <?xml version="1.0"?>
    <odoo>
    	<menuitem id="estate_menu_root" name="Estate">
        	<menuitem id="estate_first_level_menu_listing" name="Listing">
            	<menuitem id="estate_property_menu_action" action="estate_property_action"/>
        	</menuitem>
        	<menuitem id="estate_first_level_menu_settings" name="Settings">
            	<menuitem id="estate_property_type_menu_action" action="estate_property_type_action"/>
            	<menuitem id="estate_property_tag_menu_action" action="estate_property_tag_action"/>
        	</menuitem>
    	</menuitem>
    </odoo>
    

    estate_property_offer_views.xml:

    <?xml version="1.0"?>
    <odoo>
    
    	<record id="estate_property_offer_view_tree" model="ir.ui.view">
            <field name="name">estate.property.offer.tree</field>
            <field name="model">estate.property.offer</field>
            <field name="arch" type="xml">
                <tree string="Offernya" >
                    <field name="price"/>
                    <field name="partner_id"/>
                    <field name="status"/>
                </tree>
            </field>
        </record>
    
    	<record id="estate_property_offer_view_form" model="ir.ui.view">
            <field name="name">estate.property.offer.form</field>
            <field name="model">estate.property.offer</field>
            <field name="arch" type="xml">
            	<form string="Offernya">
       				 <sheet>
            			<group>
               				<group>
                    			<field name="price"/>
                    			<field name="partner_id"/>
                    			<field name="status"/>
                			</group>
            			</group>
        			</sheet>
    			</form>
            </field>
        </record>
    </odoo>
    

    estate_property_tag_views.xml:

    <?xml version="1.0"?>
    <odoo>
        <record id="estate_property_tag_action" model="ir.actions.act_window">
            <field name="name">Property Tag</field>
            <field name="res_model">estate.property.tag</field>
            <field name="view_mode">tree,form</field>
        </record>
    
    	<record id="estate_property_tag_view_tree" model="ir.ui.view">
            <field name="name">estate.property.tag.tree</field>
            <field name="model">estate.property.tag</field>
            <field name="arch" type="xml">
                <tree string="Tagnya" >
                    <field name="name"/>
                </tree>
            </field>
        </record>
    
    	<record id="estate_property_tag_view_form" model="ir.ui.view">
            <field name="name">estate.property.tag.form</field>
            <field name="model">estate.property.tag</field>
            <field name="arch" type="xml">
            	<form string="Tagnya">
       				 <sheet>
            			<group>
               				<group>
                    			<field name="name"/>
                			</group>
            			</group>
        			</sheet>
    			</form>
            </field>
        </record>
    </odoo>
    

    estate_property_type_views.xml:

    <?xml version="1.0"?>
    <odoo>
        <record id="estate_property_type_action" model="ir.actions.act_window">
            <field name="name">Property Type</field>
            <field name="res_model">estate.property.type</field>
            <field name="view_mode">tree,form</field>
        </record>
    
    	<record id="estate_property_type_view_tree" model="ir.ui.view">
            <field name="name">estate.property.type.tree</field>
            <field name="model">estate.property.type</field>
            <field name="arch" type="xml">
                <tree string="Tipe" >
                    <field name="name"/>
                </tree>
            </field>
        </record>
    
    	<record id="estate_property_type_view_form" model="ir.ui.view">
            <field name="name">estate.property.type.form</field>
            <field name="model">estate.property.type</field>
            <field name="arch" type="xml">
            	<form string="Tipe">
       				 <sheet>
            			<group>
               				<group>
                    			<field name="name"/>
                			</group>
            			</group>
        			</sheet>
    			</form>
            </field>
        </record>
    
    </odoo>
    

    estate_property_views.xml:

    <?xml version="1.0"?>
    <odoo>
        <record id="estate_property_action" model="ir.actions.act_window">
            <field name="name">Property</field>
            <field name="res_model">estate.property</field>
            <field name="view_mode">tree,form</field>
        </record>
    
    	<record id="estate_property_view_tree" model="ir.ui.view">
            <field name="name">estate.property.tree</field>
            <field name="model">estate.property</field>
            <field name="arch" type="xml">
                <tree string="Rumahan" >
                    <field name="name"/>
                    <field name="property_type_id"/>
                	<field name="postcode"/>
                    <field name="bedrooms"/>
                    <field name="living_area"/>
                    <field name="expected_price"/>
                    <field name="selling_price"/>
                    <field name="date_availability"/>
                    <field name="user_id"/>
                    <field name="buyer_id"/>
                </tree>
            </field>
        </record>
    
    	<record id="estate_property_view_form" model="ir.ui.view">
            <field name="name">estate.property.form</field>
            <field name="model">estate.property</field>
            <field name="arch" type="xml">
            	<form string="Rumahan">
       				 <sheet>
            			<group>
               				<group>
                    			<field name="name"/>
                    			<field name="property_type_id"/>
                    			<field name="tags_id"/>
                            	<field name="postcode"/>
                    			<field name="date_availability"/>
                			</group>
                			<group>
                    			<field name="expected_price"/>
                    			<field name="selling_price"/>
                			</group>
            			</group>
                		<notebook>
                    		<page string="Description">
               				<group>
                        		<field name="description"/>
                        		<field name="bedrooms"/>
                        		<field name="living_area"/>
                        		<field name="facades"/>
                        		<field name="garage"/>
                        		<field name="garden"/>
                        		<field name="garden_area"/>
                        		<field name="garden_orientation"/>
                			</group>
                    		</page>
                     		<page string="Offers">
                            	<group>
                    				<field name="offer_ids"/>
                                </group>
                        	</page>
                        	<page string="Other Info">
                            	<group>
                    				<field name="user_id"/>
                   			 		<field name="buyer_id"/>
                                </group>
                            </page>
                		</notebook>
        			</sheet>
    			</form>
            </field>
        </record>
    
    	<record id="estate_property_view_search" model="ir.ui.view">
            <field name="name">estate.property.tree</field>
            <field name="model">estate.property</field>
            <field name="arch" type="xml">
                <search string="Rumahan" >
                    <field name="name"/>
                    <field name="postcode"/>
                    <field name="expected_price"/>
                    <field name="bedrooms"/>
                    <field name="living_area"/>
                    <field name="facades"/>
    				<filter string="Archived" name="inactive" domain="[('active', '=', False)]"/>		
            	</search>
            </field>
        </record>
    
    </odoo>
    

Informasi lebih lanjut silahkan mengunjungi
1. https://www.odoo.com/documentation/16.0/developer/howtos/rdtraining/08_relations.html .
2. https://github.com/odoo/technical-training-solutions/tree/16.0-core/estate .

Kunjungi www.proweb.co.id untuk menambah wawasan anda.

Jika anda tertarik mengenai aplikasi Odoo ERP silahkan mengisi form di bawah ini

 

Source Code Pemrograman Dasar Odoo ERP