在odoo 9.0中连接日期和时间

时间:2021-05-03 20:23:23

I have two fields as shown below.

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

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

I need to concatenate this two fields. For that i wrote a function as shown below.

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

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

And called that function in a separate field as shown below.

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

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

These fields are called in xml files

这些字段在xml文件中调用

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

I am getting an error as

我收到错误了

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

1 个解决方案

#1


1  

You are working with Odoo 9. So It's advisable to do practice with new api.

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

Try with this code:

试试这段代码:

@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'

#1


1  

You are working with Odoo 9. So It's advisable to do practice with new api.

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

Try with this code:

试试这段代码:

@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'