Server Framework 101 - Solusi 4
Tutorial adalah solusi untuk tutorial https://www.odoo.com/documentation/18.0/developer/tutorials/server_framework_101/05_firstui.html
Tutorial akan membuat menu untuk mengakses model estate yang telah dibuat sebelumnya.
Pertama buat folder estate/views. Kemudian tambahkan file estate_property.xml didalam direktori tersebut.
Berikut kode xml untuk 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>
<menuitem id="estate_property_root" name="Estate Property">
<menuitem id="estate_property_first_level_menu" name="Advertisements">
<menuitem id="estate_property_menu_action" action="estate_property_action" name="Properties"/>
</menuitem>
</menuitem>
</odoo>
Pada official tutorial diminta untuk menambahkan beberapa fields baru dan menambahkan attribute pada field yang telah dibuat pada tutorial sebelumnya.
Berikut code models/estate_property.py setelah diupdate:
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('Postal code')
date_availability = fields.Date('Available from', copy=False,
default=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=False)
state = fields.Selection(
string='Status',
selection=[('new', 'New'),
('offer received', 'Offer Received'),
('offer accepted', 'Offer Accepted'),
('sold', 'Sold'),
('cancelled', 'Cancelled')],
default='new',
copy=False)
Terakhir kita perlu mengupdate file __manifest__.py
{
'name': 'Estate',
'depends':[
'base',
],
'data':[
'security/ir.model.access.csv',
'views/estate_property.xml',
],
'application': True
}
Restart odoo server, lakukan upgrade melalui menu upgrade pada module estate. Bila tidak error akan tampil seperti berikut:


Comments
Post a Comment