Reputation: 497
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)
Upvotes: 1
Views: 498
Reputation: 11141
You are working with Odoo 9. So It's advisable to do practice with new 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'
Upvotes: 1