转换为字母的数字

时间:2016-09-08 10:03:39

标签: python odoo-8

我安装了模块 num2words 这是我的代码:

from num2words import num2words

class HrHolidays(models.Model):     _inherit ='hr.holidays'

interim = fields.Many2one(
    'hr.employee',
    string="Interim")
partner_id = fields.Many2one('res.partner', string="Customer")
remaining_leaves = fields.Integer(compute='_get_remaining_days', string='Leaves')  
number_text=fields.Char(string='Nombre de jour')


@api.multi
def _get_remaining_days(self, name, args):
    res = super(HrHolidays, self)._get_remaining_days(name, args)
    return res

def calculatenumber(self, number_of_days_temp,lang='fr'):
    number_text = num2words(number_of_days_temp,lang)
    return {'value': {'number_text': number_text}}

.XML

             <xpath expr="//field[@name='interim']" position="after">
                      <field name="number_of_days_temp" nolabel="1"  on_change="calculatenumber(number_of_days_temp)"/>

     </xpath>
        <field name="number_of_days_temp" position="after">
            <field name="number_text"/>
        </field>

我得到了这个错误,我不知道如何解决它 enter image description here

1 个答案:

答案 0 :(得分:0)

验证函数的定义

def calculatenumber(self,cr, uid, ids,number_of_days_temp, context=None):
    number_text = num2words(number_of_days_temp,lang='fr')
    return {'value': {'number_text': number_text}}

或者你可以使用新的api

@api.onchange('number_of_days_temp')
def calculatenumber(self):
    self.number_text = num2words(self.number_of_days_temp,lang='fr')

然后您必须从XML视图中删除on_change="calculatenumber(number_of_days_temp)"