我想在名为 的 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)
}
它显示空字段(该函数也没有运行)。我该如何解决这个问题?任何帮助都受到高度赞赏。
元芳怎么了
相关分类