在odoo 9.0中连接日期和时间

concatenate date and time in odoo 9.0

我有两个字段,如下所示。

>  appo_date = fields.Date(string="Appointment Date")
>  appo_time = fields.Float(string="Appointment Time")

我需要连接这两个字段。为此,我编写了一个如下所示的函数。

def _combine(self, cr, uid, ids, field_name, args, context=None):
        values = {}
        for id in ids:
            rec = self.browse(cr, uid, [id], context=context)[0]
            values[id] = {}
            values[id] = '%f - %f' % (rec.appo_date, rec.appo_time)
        return values

并在单独的字段中调用该函数,如下所示。

appo_date_and_time = fields.Char(compute='_combine', string='Appointment Date/Time', arg=('appo_date','appo_time'), method=True)

这些字段在 xml 个文件中被调用

<field name="appo_date"/>
<field name="appo_time"/>
<field name="appo_date_and_time"/>

我收到一个错误,因为

TypeError: _combine() takes at least 6 arguments (5 given)

您正在使用 Odoo 9。因此建议使用新的 api 进行练习。

尝试使用此代码:

@api.multi
def _combine(self):
    if self.appo_date and self.appo_time:
        self.appo_date_and_time = '%f - %f' % (self.appo_date, self.appo_time)
    elif self.appo_date:
        self.appo_date_and_time = str(self.appo_date)
    elif self.appo_time:
        self.appo_date_and_time = str(self.appo_time)
    else
        self.appo_date_and_time = 'No Date and Time set'