python - 预期单例 : hr. employee(1, 2)

标签 python xml odoo-8 odoo qweb

美好的一天!我在加载 kanban View 时出错。我继承了 hr.employee Kanban xml 并且只添加了一个条件,如果某些文件过期,它会在 kanban View 中添加一个 Expired Documents 通知,这里是 xml 代码:

    <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

员工中的看板 View 发生错误

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

有人会帮我解决这个问题吗?在此先感谢。

最佳答案

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

@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

您应该将两种模型之间的关系写给我们,以便给您准确的答案。

关于python - 预期单例 : hr. employee(1, 2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32820727/

相关文章:

python - 我如何使用 Xml Odoo 创建电子邮件模板

python - 如何解决 psycopg2.ProgrammingError : column reference "account_analytic_id" is ambiguous in odoo

python - 为什么我得到 "ufunc ' multiply' did not contain a loop with signature matching types dtype ('S32' ) dtype ('S32' ) dtype ('S32' )"with values from raw_input

python - 如何删除命令 "plt.plot(x,y)"绘制的点

python - 获取订单中的轮廓

java - 使用 Java 的 XML Splitter - 索引设置距标签的偏移量,省略开始空格

python - 为什么要编译 Python 代码?

php - 使用 php XSLTProcessor 的 XML/XSLT 输出编码问题

java - 如何将 XSD 类型导入根模式?

python - 工资单 odoo 中的休假扣除错误