预期单身人士:hr.employee(1,2)

时间:2015-09-28 10:24:12

标签: python xml odoo-8 odoo qweb

美好的一天!每个人在加载kanban视图时都出错了。我继承了hr.employee Kanban xml,只是在某个文档过期后添加一个条件,它会在kanban视图中添加一个过期文档通知,这里是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

员工中的kanban视图发生了错误

  

预期单身人士:hr.employee(1,2)。

有人会帮助我,并提前致谢。

1 个答案:

答案 0 :(得分:5)

我不知道hr.employeehr.employee_documents之间的关系。如果这个是One2many(针对唯一员工的许多文档),则One2many模型中的hr.employee字段必须指向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

你应该把两种模型之间的关系写给我们,以便给你一个准确的答案。