Expected singleton: hr.employee(1, 2)

笑着哭i 提交于 2019-12-23 02:20:00

问题


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>

and the model for documents_status field

and when loading

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

the kanban view in employee an error occurred

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

will someone help me with this and Thanks in Advance.


回答1:


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.



来源:https://stackoverflow.com/questions/32820727/expected-singleton-hr-employee1-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!