OpenERP 7: fields.function return [object Object]

我想在名为 的 hr.employee 中添加 1 个字段contract_type。每次用户在Human Resources > Employees. 我使用以下代码在新模块中创建了 xml:


<?xml version="1.0" encoding="utf-8"?>

<openerp>

<data>

    <record id="hr_employee_view_form_inherit" model="ir.ui.view">

        <field name="name">hr.employee.view.form.inherit</field>

        <field name="model">hr.employee</field>

        <field name="inherit_id" ref="hr_contract.hr_hr_employee_view_form2"/>

        <field name="arch" type="xml">

            <xpath expr="//group[@string='Contract']/field[@name='medic_exam']" position="before">

                <field name="contract_type" string="Contract Type"/>

            </xpath>

        </field>

    </record>

</data>

在 py 中,contract_type定义为fields.function.


from openerp import addons

import logging

from openerp.osv import fields, osv

from openerp.tools.translate import _

from openerp import tools


_logger = logging.getLogger(__name__)


class inherit_hr_employee(osv.osv):

_inherit = 'hr.employee'


def _get_contract_type(self, cr, uid, ids, field_name, arg, context=None):

    res = {}

    contract_name = ""

    for i in ids:

        sql_req= """

            SELECT *

            FROM hr_contract

            WHERE employee_id = %d

            """ % (i,)


    cr.execute(sql_req)

    sql_res = cr.dictfetchone()


    flag = False

    _is_empty = sql_res.get("date_end")

    contract_type = sql_res.get("type_id")

    if not _is_empty:

        flag = True

    if flag:

        sql_contract_type = """

            SELECT *

            FROM hr_contract_type

            WHERE id = %d

        """ % (contract_type,)

        cr.execute(sql_contract_type)

        sql_contract = cr.dictfetchone()

        contract_name = sql_contract.get("name")

    for employee in self.browse(cr, uid, ids, context=context):

        res[employee.id] = {

            'contract_type': str(contract_name)

        }

    return res


_columns = {

    'contract_type' : fields.function(_get_contract_type, type='text', string='Contract Type', method=True, readonly=True, size=20)

}


它显示空字段(该函数也没有运行)。我该如何解决这个问题?任何帮助都受到高度赞赏。



汪汪一只猫
浏览 141回答 1
1回答

元芳怎么了

解决了。我res用这个改变定义:res&nbsp;=&nbsp;dict.fromkeys(ids,&nbsp;'')
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python