简体   繁体   English

错误:QWeb2 - 模板 ['HrAttendanceMyMainMenu']:odoo 14 中没有为 foreach 提供枚举器

[英]Error: QWeb2 - template['HrAttendanceMyMainMenu']: No enumerator given to foreach in odoo 14

I wanted to add a additional field (Many2one) on the CHECK-IN-CHECK-OUT screen.我想在 CHECK-IN-CHECK-OUT 屏幕上添加一个附加字段 (Many2one)。

Here's my model:这是我的 model:

class HrAttendance(models.Model):
    _inherit = "hr.attendance"

    work_status = fields.Many2one('work.status', string='Work Status')

Here's my XM view:这是我的 XM 视图:

 <t t-name="HrAttendanceMyMainMenu">
        <div class="o_hr_attendance_kiosk_mode_container o_home_menu_background">
            <span class="o_hr_attendance_kiosk_backdrop"/>
            <div class="o_hr_attendance_clock text-center"/>
            <div class="o_hr_attendance_kiosk_mode">
                <t t-set="checked_in" t-value="widget.employee.attendance_state=='checked_in'"/>
                <t t-if="widget.employee">
                    <div class="o_hr_attendance_user_badge o_home_menu_background">
                        <img class="img rounded-circle" t-attf-src="/web/image?model=hr.employee.public&amp;field=image_128&amp;id=#{widget.employee.id}" t-att-title="widget.employee.name" t-att-alt="widget.employee.name"/>
                    </div>
                    <div class="form-group">
                        <select class="form-control" id="locationSelected">
                          <t t-foreach="work_status" t-as="location">
                              <option t-att-value="location.id"><t t-esc="location.name"/></option>
                          </t>
                        </select>
                    </div>
                    <h1 class="mb8"><t t-esc="widget.employee.name"/></h1>
                    <h3 class="mt8 mb24"><t t-if="!checked_in">Welcome!</t><t t-else="">Want to check out?</t></h3>
                    <h4 class="mt0 mb0 text-muted" t-if="checked_in">Today's work hours: <span t-esc="widget.hours_today"/></h4>
                    <a class="fa fa-7x o_hr_attendance_sign_in_out_icon fa-sign-out btn-warning" t-if="checked_in" aria-label="Sign out" title="Sign out"/>
                    <a class="fa fa-7x o_hr_attendance_sign_in_out_icon fa-sign-in btn-secondary" t-if="!checked_in" aria-label="Sign in" title="Sign in"/>
                    <h3 class="mt0 mb0 text-muted">Click to <b t-if="checked_in">check out</b><b t-if="!checked_in">check in</b></h3>
                </t>
                <t t-else="">
                    Warning : Your user should be linked to an employee to use attendance. Please contact your administrator.
                </t>
            </div>
        </div>
    </t>

shows following traceback:显示以下追溯:

Traceback:
Error: QWeb2 - template['HrAttendanceMyMainMenu']: No enumerator given to foreach
    at Object.exception (http://localhost:8069/web/content/684-8b6b22b/web.assets_common.js:4408:7)
    at Object.foreach (http://localhost:8069/web/content/684-8b6b22b/web.assets_common.js:4422:80)
    at Engine.eval (eval at _render (http://localhost:8069/web/content/684-8b6b22b/web.assets_common.js:4450:73), <anonymous>:26:24)
    at Engine._render (http://localhost:8069/web/content/684-8b6b22b/web.assets_common.js:4449:296)
    at Engine.render (http://localhost:8069/web/content/684-8b6b22b/web.assets_common.js:4449:151)
    at Engine._render (http://localhost:8069/web/content/684-8b6b22b/web.assets_common.js:4453:57)
    at Engine.render (http://localhost:8069/web/content/684-8b6b22b/web.assets_common.js:4449:151)
    at Class.renderElement (http://localhost:8069/web/content/790-9a5b8a1/web.assets_backend.js:488:452)
    at prototype.<computed> [as renderElement] (http://localhost:8069/web/content/684-8b6b22b/web.assets_common.js:4651:488)
    at http://localhost:8069/web/content/684-8b6b22b/web.assets_common.js:4996:6

I have already created values for work_status field but unable to figure out how to rendeer values in dropdown.我已经为work_status字段创建了值,但无法弄清楚如何在下拉列表中呈现值。

Can anyone pls help with that, TIA任何人都可以帮忙吗,TIA

The work_status variable is not defined. work_status变量。 You can check the source code of the qweb2 foreach directive:您可以查看 qweb2 foreach指令的源代码:

if (enu != null) {
    ...
 } else {
    this.exception("No enumerator given to foreach", context);
 } 

Available variable names like employee or hours_today are defined in MyAttendances action, you can override the same function to define the work_status values and use them in the template可用的变量名称,如employeehours_todayMyAttendances操作中定义,您可以覆盖相同的 function 以定义work_status值并在模板中使用它们

Example:例子:

odoo.define('stackoverflow_14.my_attendances', function (require) {
"use strict";

var MyAttendances = require('hr_attendance.my_attendances');

MyAttendances.include({
    willStart: function () {
        var self = this;
        var def = this._rpc({
                model: 'work.status',
                method: 'search_read',
                args: [[], ['name']],
        })
       .then(function (res) {
           self.work_status = res;
       });
       return Promise.all([def, this._super.apply(this, arguments)]);
   },
});
});

The loop in xml you are executing dont contain any values in it so causing this error.您正在执行的xml中的循环不包含任何值,因此导致此错误。 The issue is in line <t t-foreach="work_status" t-as="location">问题在<t t-foreach="work_status" t-as="location">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM