Skip to Content
Menu
This question has been flagged
1 Reply
3577 Views

Hi, 

I need any step by step materials on how to create a form like kiosk_mode (.py, .xml, .js) files and relation between them.

Thanks in advance

Avatar
Discard
Best Answer


The logic is as follows. It all starts with the controller to which your user switches. for example, if this is a POS module, then there’s something like that 'pos / web' that if you follow the link directly, you can also attach a controller to action. This is done in js code. The action itself is bound to the menu in the xml file. Further after the user has gone over the link, the controller processes some data from the database or something else, then calls the template and passes the data to it. The template in the case of kiosk_mode is the name of the html page, see the code below, and the rest of the logic is mapped to the data + js code. Js code as it can be directly in the template and raschbit files and import links.

Some like this:

# -*- coding: utf-8 -*-
from odoo.http import request
from odoo import http
from odoo import SUPERUSER_ID
class MRPEmployeeIndicatorController(http.Controller):
    @http.route('/mrp_employee_indicator/indicator/', type='http', auth='public')
    def index(self, **kw):
        department_id = kw.get('id_department', 0)
        env = http.request.env(user=SUPERUSER_ID)
        # some your data
        values ={
                'table_list': ['За прошлый месяц', 'Сегодня', 'По вчерашний день'],
                'result': env["employee.indicator"].get_employees(department_id)
        }
        return request.render("mrp_employee_indicator.ContainerMainPanel", values)

Also you need do js logic and xml template:
some like this JS:
odoo.define('mrp_employee_indicator', function (require) {
"use strict"; var core = require('web.core');
var Widget = require('web.Widget');
var Model = require('web.DataModel');
var data = require('web.data');
var QWeb = core.qweb; // $(document).ready(function() {
// alert(1);
// }); var mainPanel = Widget.extend({
events: {
'change #department_select': 'display_payslip',
},
start: function(){
this._super;
this.$el.css("height", "100%");
this.$el.css("width", "100%");
this.$el.css("background-color", "rgb(6, 46, 77)");
this.$el.css("overflow", "hidden");
this.table_list = ["Прошлый месяц", "Сегодня", "По вчерашний день"];
var url = new URL(this.$el.context.baseURI);
var debug = url.searchParams.get("debug");
this.department = 0;
if (debug){
this.department = debug;
this.display_payslip();
}
else{
//Добавляем селект с подразделениями
this.departmentSelection = new DepartmentSelection();
this.departmentSelection.prependTo(this.$el);
}
},

display_payslip: function(){
var self = this;
//берем название департамента из селекта
if (self.department== 0)
self.department = $("#department_select").children(":selected").text();
new Model("employee.indicator").call("get_employees", [self.department])
.then(function(result){
self.result = result;
console.log(result);
// Делаем разделители для сотрудников и дохода (17777 -> 17 777)
self.result.forEach(function(departure){
departure.forEach(function(time){
time.forEach(function(emp){
emp[1] = (emp[1]).toLocaleString('ru');
// emp[2] = (emp[2]).toLocaleString('ru');
});
});
});
// перересовываем (обновляем) данные
self.$el.html(QWeb.render("ContainerMainPanel", {widget: self}));
});
 
            // запускаем перересовку данных в цикле каждые 15 минут
            var intervalOdoo = setInterval(function(){
                new Model("employee.indicator").call("get_employees", [self.department])
                    .then(function(result){
                        console.log("Данные обновлены (прошло 15 минут)");
                        self.result = result;
                        self.$el.html(QWeb.render("ContainerMainPanel", {widget: self}));
                    });
            }, 15*60*1000);
        },
            
    });
        var DepartmentSelection = Widget.extend({
        template: "DepartmentSelection",
        start: function(){
            self = this;
            new Model("hr.department").call("search_read", [[],['name','id']])
                .then(function(result){
                    self.select = $("#department_select");
                    result.forEach(function(departure){
                    //console.log(departure);
                        self.select.append('<option>' + departure['name'] + '</option>');
                    });
                })
        },
                        
    });
    core.action_registry.add('mrp_employee_indicator.main_panel', mainPanel);
XML some like this:
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<template id="ContainerMainPanel">
    &lt;!DOCTYPE html&gt;
    <html>

    <head>
        <link rel="stylesheet" href="/mrp_employee_indicator/static/src/css/main_panel.css"/>
        <meta http-equiv="refresh" content="300"/>
    </head>

    <body class="employee_mrp_body" style="background-color: #1F2739;">
        <table class="table_employee_indicator">
            <tr>
                <t t-foreach="table_list" t-as="table_name">
                    <td>
                        <t t-if="table_name == 'Сегодня'">
                            <h1><span class="blue"><t t-esc='table_name'/></span></h1>
                        </t>
                    </td>
                </t>
            </tr>
            <t t-foreach="table_list" t-as="table_name">
                <td>
                    <table class="container_employee_indicator">
                        <thead>
                            <tr>
                                <t t-if="table_name == 'Сегодня'">
                                    <th><h1 class="employee_indicator_h1">Место</h1></th>
                                    <th><h1 class="employee_indicator_h1">Сотрудник</h1></th>
                                    <th><h1 class="employee_indicator_h1">Доход</h1></th>
                                    <th><h1 class="employee_indicator_h1">Ободок</h1></th>
                                    <th><h1 class="employee_indicator_h1">Винтовая</h1></th>
                                    <th><h1 class="employee_indicator_h1">Леска</h1></th>
                                    <th><h1 class="employee_indicator_h1">Всего</h1></th>
                                </t>
                            </tr>
                        </thead>
                        <tbody>
                                <t t-set="index" t-value="0"/>
                                <t t-if="table_name == 'Сегодня'">
                                    <t t-foreach="result[0][0]" t-as="user" t-as_index="index">
                                        <t t-set="index" t-value="index+1"/>
                                        <tr>
                                            <td ><t t-esc='index'/></td>
                                            <td ><t t-esc='user[1]'/></td>
                                            <td ><t t-esc='user[2][0]'/></td>
                                            <t t-foreach="user[2][1]" t-as="qty">
                                                <td ><t t-esc='qty'/></td>
                                            </t>
                                            <td ><t t-esc='user[2][2]'/></td>
                                        </tr>
                                    </t>
                                </t>
                        </tbody>
                    </table>
                </td>
            </t>
            </table>
        </body>
    </html>
</template>
</odoo>

<!-- binding action to the menu-->
    <menuitem name="Вычисленные зарплаты"
              id="mrp_employee_indicator.my_panel_action"
              parent="hr_attendance.menu_hr_attendance_root"
              action="mrp_employee_indicator.my_panel"/>

Avatar
Discard

FIX xml file with html data:)