Server Framework 101 - Solusi 6

 Solusi untuk tutorial https://www.odoo.com/documentation/18.0/developer/tutorials/server_framework_101/06_basicviews.html

file estate_property.py

from odoo import fields, models
from dateutil.relativedelta import relativedelta

class EstateProperty(models.Model):
    _name = "estate.property"
    _description = "Estate property"

    name = fields.Char('Estate Name', required=True)
    description = fields.Text('Description')
    postcode = fields.Char('Poscode')
    date_availability = fields.Date('Available from', copy=False,
                                    default=lambda self: fields.Date.today() + relativedelta(months=3))
    expected_price = fields.Float('Expected price', required=True)
    selling_price = fields.Float('Selling price', readonly=True, copy=False)
    bedrooms = fields.Integer('Bedrooms', default=2)
    living_area = fields.Integer('Living area (sqm)')
    facades = fields.Integer('Facades')
    garage = fields.Boolean('Garage')
    garden = fields.Boolean('Garden')
    garden_area = fields.Integer('Garden area (sqm)')
    garden_orientation = fields.Selection(
        string='Garden orientation',
        selection=[('north', 'North'),
                   ('south', 'South'),
                   ('east', 'East'),
                   ('west', 'West')])
    active = fields.Boolean('Active', default=True)
    state = fields.Selection(
        string='Status',
        selection=[('new', 'New'),
                   ('offer received', 'Offer Received'),
                   ('offer accepted', 'Offer Accepted'),
                   ('sold', 'Sold'),
                   ('cancelled', 'Cancelled')],
        default='new',
        copy=False)
   
    property_type_id = fields.Many2one('estate.property.type', string="Property Type")
    user_id = fields.Many2one('res.users', string='Salesman', default=lambda self: self.env.user)
    buyer_id = fields.Many2one('res.partner', string="Buyer", copy=False)
    tag_ids = fields.Many2many('estate.property.tag')
    offer_ids = fields.One2many('estate.property.offer', 'property_id', string="Offers")


file estate_property_type.py

from odoo import fields, models

class EstatePropertyType(models.Model):
    _name = "estate.property.type"
    _description = "Estate property type"

    name = fields.Char('Property type', required=True)


file estate_property_tag.py

from odoo import fields, models

class EstatePropertyTag(models.Model):
    _name = "estate.property.tag"
    _description = "Estate property type"

    name = fields.Char('Property tag', required=True)


file estate_property_offer.py

from odoo import fields, models

class EstatePropertyOffer(models.Model):
    _name = 'estate.property.offer'
    _description = 'Estate property offer'
   
    price = fields.Float('Price', required=True)
    status = fields.Selection(string='Status',
        selection=[
            ('accepted', 'Accepted'),
            ('refused', 'Refused'),
        ],
        copy=False,
        default=False)
    partner_id = fields.Many2one('res.partner', string='Partner', required=True)
    property_id = fields.Many2one('estate.property', string="Property", required=True)


file estate_property.xml

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <record id="estate_property_action" model="ir.actions.act_window">
        <field name="name">Estate Property</field>
        <field name="res_model">estate.property</field>
        <field name="view_mode">list,form</field>
    </record>

    <!--search-->
    <record id="estate_property_search" model="ir.ui.view">
        <field name="name">estate.property.search</field>
        <field name="model">estate.property</field>
        <field name="arch" type="xml">
            <search string="Search properties">
                <field name="name" string="Title"/>
                <field name="postcode"/>
                <field name="expected_price"/>
                <field name="bedrooms"/>
                <field name="living_area" string="Living Area (sqm)"/>
                <field name="facades"/>                
                <separator/>
                <filter string="Available" name="avaliable" domain="['|', ('state', '=', 'new'),
                ('state', '=', 'offer received')]"/>
                <group expand="1" string="Group By">
                    <filter string="Postcode" name="postcode" context="{'group_by':'postcode'}"/>
                </group>
            </search>
        </field>
    </record>    

    <!--list view-->
    <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">
            <list string="Properties">
                <field name="name" string="Title"/>
                <field name="postcode"/>
                <field name="bedrooms"/>
                <field name="living_area"/>
                <field name="expected_price"/>
                <field name="selling_price"/>
                <field name="date_availability" string="Available from"/>
            </list>
        </field>
    </record>

    <!--form-->
    <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>
                <sheet>
                    <h1><field name="name" placeholder="Property Title"/></h1>
                    <field name="tag_ids" widget="many2many_tags"/>
                    <group>
                        <group>
                            <field name="property_type_id"/>
                            <field name="postcode"/>
                            <field name="date_availability" string="Available From"/>
                        </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" string="Living Area (sqm)"/>
                                <field name="facades"/>
                                <field name="garage"/>
                                <field name="garden"/>
                                <field name="garden_area" string="Garden Area (sqm)"/>
                                <field name="garden_orientation"/>
                            </group>
                        </page>
                        <page string="Offers">
                            <field name="offer_ids"/>
                        </page>                        
                        <page string="Other Info">
                            <group>
                                <field name="user_id"/>
                                <field name="buyer_id"/>
                            </group>
                        </page>                        
                    </notebook>
                </sheet>
            </form>
        </field>
    </record>
</odoo>


file estate_property_type.xml

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <!-- Action Window -->
    <record id="estate_property_type_action" model="ir.actions.act_window">
        <field name="name">Property Types</field>
        <field name="res_model">estate.property.type</field>
        <field name="view_mode">list,form</field>
    </record>

    <!-- List View -->
    <record id="estate_property_type_view_tree" model="ir.ui.view">
        <field name="name">estate.property.type.list</field>
        <field name="model">estate.property.type</field>
        <field name="arch" type="xml">
            <list string="Property Types">
                <field name="name"/>
            </list>
        </field>
    </record>

    <!-- Form View -->
    <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>
                <sheet>
                    <field name="name"/>
                </sheet>
            </form>
        </field>
    </record>
</odoo>


file estate_property_tag.xml

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <!-- Action Window -->
    <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">list,form</field>
    </record>

    <!-- List View -->
    <record id="estate_property_tag_view_tree" model="ir.ui.view">
        <field name="name">estate.property.tag.list</field>
        <field name="model">estate.property.tag</field>
        <field name="arch" type="xml">
            <list string="Property Tag">
                <field name="name"/>
            </list>
        </field>
    </record>

    <!-- Form View -->
    <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>
                <sheet>
                    <field name="name"/>
                </sheet>
            </form>
        </field>
    </record>
</odoo>


file estate_property_offer.xml

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <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="Property Offer">
                <group>
                    <field name="price"/>
                    <field name="partner_id"/>
                </group>
            </form>
        </field>
    </record>

    <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">
            <list string="Properties Offers">
                <field name="price" string="Price"/>
                <field name="partner_id" string="Partner"/>
                <field name="status" string="Status"/>
            </list>
        </field>
    </record>

    <record id="estate_property_offer_action" model="ir.actions.act_window">
        <field name="name">Property Offers</field>
        <field name="res_model">estate.property.offer</field>
        <field name="domain">[('property_type_id','=', active_id)]</field>
        <field name="view_mode">tree,form</field>
    </record>
</odoo>


file models/__init__.py

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


file security/ir.model.access.csv

id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink

access_estate_property,access_estate_property,model_estate_property,base.group_user,1,1,1,1

access_estate_property_type,access_estate_property_type,model_estate_property_type,base.group_user,1,1,1,1

access_estate_property_tag,access_estate_property_tag,model_estate_property_tag,base.group_user,1,1,1,1

access_estate_property_offer,access_estate_property_offer,model_estate_property_offer,base.group_user,1,1,1,1


file estate/__manifest__.py

{
    'name': 'Estate',
    'depends':[
        'base',
    ],
    'data':[
        'security/ir.model.access.csv',
        'views/estate_property_type.xml',
        'views/estate_property_tag.xml',
        'views/estate_menu.xml',
        'views/estate_property_offer.xml',
        'views/estate_property.xml',
    ],
    'application': True
}






Comments

Popular posts from this blog

Solusi Tutorial Owl Components - Counter

Solusi Tutorial Owl Components - Todo List

Odoo Development Setup menggunakan Windows dan Docker