Dalam pengembangan aplikasi Odoo tentu kita akan membedakan informasi yang diberikan untuk semua pengunjung termasuk tanpa login, semua pengguna yang login dan informasi pribadi sesuai akun yang login. Kita akan menggunakan otorisasi path untuk menerapkan hal ini
Otorisasi path pada pemrograman Odoo adalah seperti berikut ini
- Start SSH file system


- Source code model
from odoo import api, fields, models class Hostel(models.Model): _name = 'asrama.hostel' _description = 'Informasi tentang asrama-hostel' _order = 'id desc, name' _rec_name = 'hostel_code' name = fields.Char(string='Nama Hostel',required=True) hostel_code = fields.Char(string='Kode',required=True) street = fields.Char(string='Jalan') street2 = fields.Char(string='Jalan2') zip = fields.Char('Zip',change_default=True) city = fields.Char('Kota') state_id = fields.Many2one('res.country.state', string='State') country_id = fields.Many2one('res.country', string='Negara') phone = fields.Char('Phone',required=True) mobile = fields.Char('Mobile',required=True) email = fields.Char('Email') hostel_floors = fields.Integer(string='Jml Lantai') image = fields.Binary("Gambar Hostel") active = fields.Boolean("Active",default=True, help="Aktifkan/Nonaktifkan data hostel") type = fields.Selection([('male','Laki-laki'),('female','Perempuan'),('common','Umum')] , 'Tipe', help='Tipe Hostel',required=True, default='common' ) other_info = fields.Text('Informasi lain',help='Masukkan informasi lain') description = fields.Html('Description') hostel_rating = fields.Float('Rata-rata rating hostel',digits='Nilai Rating') category_id = fields.Many2one('asrama.category') rector = fields.Many2one('res.partner','Rektor', help='Pilih rektor') rooms_count = fields.Integer(compute="_compute_rooms_count") def _compute_rooms_count(self): room_obj = self.env['asrama.room'] for hostel in self: hostel.rooms_count = room_obj.search_count([('hostel_id','=',hostel.id)]) @api.depends('hostel_code') def _compute_display_name(self): for record in self: name = record.name if record.hostel_code: name = f'{name} ({record.hostel_code})' record.display_name = name - Source code view
<?xml version="1.0" encoding="utf-8"?> <odoo> <!-- asrama.hostel search view --> <record id="view_hostel_search_view" model="ir.ui.view"> <field name="name">Hostel Search</field> <field name="model">asrama.hostel</field> <field name="arch" type="xml"> <search> <field name="name" /> <field name="hostel_code" /> </search> </field> </record> <!-- asrama.hostel tree view --> <record id="View_hostel_tree_view" model="ir.ui.view"> <field name="name">asrama.hostel.view.tree</field> <field name="model">asrama.hostel</field> <field name="arch" type="xml"> <tree> <field name="name" /> <field name="hostel_code" /> <!-- Add your fields here --> </tree> </field> </record> <!-- asrama.hostel form view --> <record id="view_hostel_form_view" model="ir.ui.view"> <field name="name">asrama.hostel.view.form</field> <field name="model">asrama.hostel</field> <field name="arch" type="xml"> <form string="Hostel"> <sheet> <div class="oe_button_box" name="button_box" > <button class="oe_stat_button" name="%(asramaku.asrama_room_action)d" type="action" icon="fa-building" context="{'search_default_hostel_id':active_id}" > <field string="Rooms" name="rooms_count" widget="statinfo" /> </button> </div> <div class="oe_title"> <h3> <table> <tr> <td style="padding-right:10px;"> <field name="name" required="1" placeholder="Name" /> </td> <td style="padding-right:10px;"> <field name="hostel_code" placeholder="Code" /> </td> </tr> </table> </h3> </div> <field name="image" widget="image" class="oe_avatar"/> <group> <group> <label for="street" string="Address"/> <div class="o_address_format"> <field name="street" placeholder="Street..." class="o_address_street"/> <field name="street2" placeholder="Street 2..." class="o_address_street"/> <field name="city" placeholder="City" class="o_address_city"/> <field name="state_id" class="o_address_state" placeholder="State" options='{"no_open": True}'/> <field name="zip" placeholder="ZIP" class="o_address_zip"/> <field name="country_id" placeholder="Country" class="o_address_country" options='{"no_open": True, "no_create": True}'/> </div> </group> <group> <field name="phone" widget="phone"/> <field name="mobile" widget="phone"/> <field name="email" widget="email" context="{'gravatar_image': True}"/> <field name="rector"/> </group> <group> <field name="hostel_floors"/> <field name="active"/> <field name="type"/> <field name="hostel_rating"/> <field name="other_info"/> </group> </group> <group> <field name="description"/> </group> </sheet> </form> </field> </record> <!-- asrama.hostel action window --> <record id="action_hostel" model="ir.actions.act_window"> <field name="name">Hostel</field> <field name="type">ir.actions.act_window</field> <field name="res_model">asrama.hostel</field> <field name="view_mode">tree,form</field> <field name="help" type="html"> <p class="oe_view_nocontent_create"> Membuat Hostel </p> </field> </record> <menuitem id="hostel_main_menu" name="Hostel" sequence="1"/> <menuitem id="hostel_type_menu" name="Hostel" parent="hostel_main_menu" action="action_hostel" groups="group_hostel_manager" sequence="10"/> <menuitem id="hostel_sub1" name="Menu-01" parent="hostel_main_menu" sequence="1"/> </odoo> - Source code main pada controllers
from odoo import http from odoo.http import request class Main(http.Controller): @http.route('/asramaku/all-students',type='http',auth='none') def all_students(self): students = request.env['asrama.student'].sudo().search([]) html_result = '<html><body><ul>' for student in students: html_result += "<li> %s </li>" % student.name html_result += '</ul></body></html>' return html_result @http.route('/asramaku/all-students/mark-mine',type='http', auth='public') def all_students_mark_mine(self): students = request.env['asrama.student'].sudo().search([]) hostels = request.env['asrama.hostel'].sudo().search([('rector','=', request.env.user.partner_id.id)]) hostel_rooms = request.env['asrama.room'].sudo().search([('hostel_id','in',hostels.ids)]) html_result = '<html><body><ul>' for student in students: if student.id in hostel_rooms.student_ids.ids: html_result += "<li> <b>%s</b> </li>" % student.name else: html_result += "<li> %s </li>" % student.name html_result += '</ul></body></html>' return html_result @http.route('/asramaku/all-students/mine',type='http', auth='user') def all_students_mine(self): hostels = request.env['asrama.hostel'].sudo().search([('rector','=', request.env.user.partner_id.id)]) students = request.env['asrama.room'].sudo().search([('hostel_id','in',hostels.ids)]).student_ids html_result = '<html><body><ul>' for student in students: html_result += "<li> %s </li>" % student.name html_result += '</ul></body></html>' return html_result @http.route('/asramaku/students', type='http', auth='none') def students(self): students = request.env['asrama.student'].sudo().search([]) html_result = '<html><body><ul>' for student in students: html_result += "<li> %s </li>" % student.name html_result += '</ul></body></html>' return html_result @http.route('/asramaku/students/json',type='json',auth='none') def students_json(self): records = request.env['asrama.student'].sudo().search([]) return records.read(['name']) - Start SSH dengan upgrade modul


- Tampilan dengan auth=none


- Tampilan dengan auth=public


- Tampilan dengan auth=user

Kunjungi https://www.proweb.co.id/implementasi-odoo/ untuk menambah wawasan anda mengenai Odoo .
