This question has been flagged
2 Replies
3961 Views

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

<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)



Avatar
Discard
Best Answer

Hi,

First of all in V9 you have to write code in new API. Your code might be as like below.

@api.multi
def _combine(self):
    for obj in self:
        obj.appo_date_and_time = '%f - %f' % (obj.appo_date, obj.appo_time)

Thats it.

This function will assign value in "appo_date_and_time" field from "appo_date" and "appo_time" fields from that same record.

I hope it is very helpful for you.


Avatar
Discard
Author

Thank you it is working

Best Answer

use odoo9 syntax 

 

    @api.one
def _combine(self):
pass
Avatar
Discard