预期单身人士:hr.employee(1、2) [英] Expected singleton: hr.employee(1, 2)

查看:48
本文介绍了预期单身人士:hr.employee(1、2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天!加载kanban视图时,我每个人都有错误.我继承了hr.employee Kanban xml并仅在某些文档过期时添加条件,它将在kanban视图中添加过期文档"通知,这是xml代码:

Good Day! Everybody I have an error while loading the kanban view. I inherit the hr.employee Kanban xml and just add a condition if a certain documents expired, it will add a Expired Documents notification in kanban view, here is the xml code:

    <record model="ir.ui.view" id="hr_kanban_view_employees_recruitment_kanban">
        <field name="name">HR - Employees Kanban Document Status</field>
        <field name="model">hr.employee</field>
        <field name="inherit_id" ref="hr.hr_kanban_view_employees"/>
        <field name="arch" type="xml">
            <xpath expr="//templates" position="before">
                <field name="employee_id"/>
                <field name="documents_status"/>
            </xpath>
            <xpath expr="//div[@class='oe_employee_details']/ul/li[@id='last_login']" position="inside">
                <span t-if="record.documents_status.raw_value" style="font-size: 100%%"
                        t-att-class="record.documents_status.raw_value==true'oe_kanban_button oe_kanban_color_3'">
                    <field name="employee_id" readonly = "1"/>
                    Has Expired Documents
                </span>
            </xpath>
        </field>
    </record>

documents_status字段的模型

以及加载时

documents_status = fields.Boolean('DocumentStatus', readonly = True,store = False,compute ='getdocumentStatus')

    @api.one
    def getdocumentStatus(self):
        raise Warning(self.employee_id)
        server_date = datetime.datetime.strptime(DATE_NOW.strftime("%Y-%m-%d") ,"%Y-%m-%d")
        result = {}

        for id in self.ids:
            result[id] = {
                'documents_status': True
            }
            totaldoc = self.env['hr.employee_documents'].search_count([('date_expiry', '<', server_date),('employee_doc_id','=', id)])
            if totaldoc > 0:
                result[id]['documents_status'] = True
                self.documents_status = True
            else:
                result[id]['documents_status'] = False
                self.documents_status = False
        return result

员工的kanban视图发生错误

预期的单例:hr.employee(1、2).

Expected singleton: hr.employee(1, 2).

有人可以帮我吗,谢谢.

will someone help me with this and Thanks in Advance.

推荐答案

我不知道hr.employeehr.employee_documents之间的关系.如果此人为One2many(许多文档供唯一雇员使用),则hr.employee模型中必须有一个指向hr.employee_documentsOne2many字段.假设此字段名为documents(这对于通过api.depends触发计算方法很重要).然后编写以下代码:

I don't know the relationship between hr.employee and hr.employee_documents. If this one is a One2many (many documents for a unique employee), there must be a One2many field in hr.employee model pointing to hr.employee_documents. Suppose this field is named documents (this is important to trigger the compute method through the api.depends). Then write this code:

@api.multi
@api.depends('documents.date_expiry')
def getdocumentStatus(self):
    server_date = datetime.datetime.strptime(DATE_NOW.strftime("%Y-%m-%d"), "%Y-%m-%d")
    for record in self:
        totaldoc = self.env['hr.employee_documents'].search_count([('date_expiry', '<', server_date),('employee_doc_id','=', self.id)])
        if totaldoc > 0:
            record.documents_status = True
        else:
            record.documents_status = False

您应该给我们写两个模型之间的关系,以便为您提供准确的答案.

You should write us the relationship between both models to give you an accurate answer.

这篇关于预期单身人士:hr.employee(1、2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆